Skip to content

Commit

Permalink
Fix broken test and clean up comparejsonld.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Teester committed Jun 28, 2024
1 parent edcdeff commit 76d5859
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
60 changes: 35 additions & 25 deletions comparejsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,37 +192,47 @@ def check_claims_for_props(self, claims: dict, prop: str) -> str:
:return:
"""
cardinality = "correct"
cardinality: str = "correct"
allowed: str = "present"
if "expression" in self._start_shape and "expressions" in self._start_shape["expression"]:
allowed_list = []
for expression in self._start_shape["expression"]["expressions"]:
for statement in claims[prop]:
is_it_allowed = []
if statement["mainsnak"]["property"] == prop:
is_it_allowed = self._process_triple_constraint(statement["mainsnak"],
expression,
"present")
if "extra" in self._start_shape:
for extra in self._start_shape["extra"]:
if extra.endswith(prop) and allowed == "incorrect":
is_it_allowed = "allowed"
allowed_list.append(is_it_allowed)
cardinality = self._process_cardinalities(expression, allowed_list, self._start_shape, prop)
if "correct" in allowed_list:
allowed = "correct"
if "expression" not in self._start_shape:
return "present"
if "expressions" not in self._start_shape["expression"]:
return "present"
for expression in self._start_shape["expression"]["expressions"]:
if "predicate" in expression and expression["predicate"].endswith(prop):
allowed_list = self._get_allowed_list(claims, prop, expression)
cardinality2 = self._process_cardinalities(expression, allowed_list, self._start_shape, prop)
if cardinality2 not in ["", "correct"]:
cardinality = cardinality2
if "correct" in allowed_list:
allowed = "correct"
if cardinality == "correct":
response = allowed
response: str = allowed
else:
response = cardinality
response: str = cardinality
return response

def _process_cardinalities(self, expression, allowed_list, shape, prop):
def _get_allowed_list(self, claims: dict, prop: str, expression: dict) -> list:
allowed_list: list = []
for statement in claims[prop]:
is_it_allowed: str = ""
if statement["mainsnak"]["property"] == prop:
is_it_allowed = self._process_triple_constraint(statement["mainsnak"],
expression,
"")
if "extra" in self._start_shape:
for extra in self._start_shape["extra"]:
if extra.endswith(prop) and is_it_allowed == "incorrect":
is_it_allowed = "allowed"
allowed_list.append(is_it_allowed)
return allowed_list

def _process_cardinalities(self, expression: dict, allowed_list: list, shape: dict, prop: str) -> str:
if "predicate" not in expression:
return "correct"
return ""
if not expression["predicate"].endswith(prop):
return "correct"
occurrences: dict = allowed_list.count("correct")
return ""
occurrences: int = allowed_list.count("correct")
occurrences += allowed_list.count("present")
cardinality: str = "correct"
for expression in shape["expression"]["expressions"]:
Expand All @@ -234,7 +244,7 @@ def _process_cardinalities(self, expression, allowed_list, shape, prop):
return cardinality

@staticmethod
def _get_cardinalities(occurrences, expression) -> str:
def _get_cardinalities(occurrences: int, expression: dict) -> str:
cardinality: str = "correct"
min_cardinality: bool = True
max_cardinality: bool = True
Expand Down
2 changes: 0 additions & 2 deletions test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Tests to test wikidata entityschemas against wikidata items
"""
import unittest
from unittest import skip

import requests

Expand Down Expand Up @@ -329,7 +328,6 @@ def test_entityschema_e349(self):
follow_redirects=True)
self.assertEqual(200, response.status_code)

@skip
def test_entityschema_e351(self):
"""
Tests that blank schemas doesn't fail
Expand Down

0 comments on commit 76d5859

Please sign in to comment.