Skip to content

Commit

Permalink
Merge pull request #39
Browse files Browse the repository at this point in the history
Fix bug where E438 won't evaluate correctly
  • Loading branch information
Teester committed Jul 11, 2024
2 parents 0d13754 + 4b74794 commit 5c4484f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 13 additions & 3 deletions comparejsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,20 @@ def calculate_necessity(self, prop: str, shape: dict) -> str:
:return: necessity
"""
necessity: str = "absent"
if "expression" in shape and "expressions" in shape["expression"]:
list_of_expressions: list = []

if "expression" not in shape:
return necessity

if "expressions" in shape["expression"]:
for expression in shape["expression"]["expressions"]:
if "predicate" in expression and expression["predicate"].endswith(prop):
necessity = self.required_or_absent(expression)
list_of_expressions.append(expression)
else:
list_of_expressions.append(shape["expression"])

for expression in list_of_expressions:
if "predicate" in expression and expression["predicate"].endswith(prop):
necessity = self.required_or_absent(expression)
return necessity

@staticmethod
Expand Down
11 changes: 11 additions & 0 deletions test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@ def test_entityschema_e351(self):
follow_redirects=True)
self.assertIn(response.json["properties"][0]["P31"]["response"], ["not enough correct statements"])

def test_entityschema_e438(self):
"""
Tests that a schemas with only 1 expression evaluates correctly
This test tests entityschema E438 (wikimedia disambiguation page) against entity Q11645745.
P31 should return as present
"""
response = self.app.get('/api/v2?entityschema=E438&entity=Q11645745&language=en',
follow_redirects=True)
self.assertIn(response.json["properties"][0]["P31"]["response"], ["correct", "present"])


if __name__ == '__main__':
unittest.main()

0 comments on commit 5c4484f

Please sign in to comment.