Skip to content

Commit

Permalink
Validator does not check annotationProperty bindings #82
Browse files Browse the repository at this point in the history
  • Loading branch information
hkir-dev committed Feb 25, 2022
1 parent fa53f90 commit 2371372
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/dosdp/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,31 @@ def test_multi_clause_multi_list(pattern):
return stat


def test_annotation_properties(pattern):
"""
Structurally tests whether an annotation property is declared before use.
Args:
pattern: schema in yaml format to validate
Returns: True if all used annotation properties are declared, False otherwise.
"""
declared_annotations = set()
if 'annotationProperties' in pattern.keys(): declared_annotations.update(set(pattern['annotationProperties'].keys()))
expr = parse('annotations.[*].annotationProperty')
used_annotations = [match for match in expr.find(pattern)]

print(declared_annotations)
stat = True
if used_annotations:
for annotation_prop in used_annotations:
val = annotation_prop.value
print(val)
if val not in declared_annotations:
warnings.warn("Annotation property '%s' didn't declared before use." % val)
stat = False
return stat


def format_warning(message, category, filename, lineno, line=None):
return '%s:%s: %s:%s\n' % (filename, lineno, category.__name__, message)

Expand Down Expand Up @@ -249,6 +274,7 @@ def validate(pattern):
if not test_clause_nesting(pattern): stat = False
if not test_axiom_separator(pattern): stat = False
if not test_multi_clause_multi_list(pattern): stat = False
if not test_annotation_properties(pattern): stat = False
except YAMLError as exc:
stat = False
logging.error('Failed to load pattern file: ' + pattern_doc)
Expand Down
5 changes: 5 additions & 0 deletions src/schema/test/generic_test/validator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"../negative_test_set/multi_clause_with_multi_list.yaml")
NEGATIVE_PATTERN_MULTI_CLAUSE_MULTI_LIST2 = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"../negative_test_set/multi_clause_with_multi_list2.yaml")
NEGATIVE_PATTERN_UNDECLARED_ANNOT_PROP = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"../negative_test_set/undeclared_annotation_prop.yaml")


class ValidatorTest(unittest.TestCase):
Expand Down Expand Up @@ -60,3 +62,6 @@ def test_axiom_separator(self):
def test_single_list_per_multi_clause(self):
self.assertFalse(validate(NEGATIVE_PATTERN_MULTI_CLAUSE_MULTI_LIST))
self.assertFalse(validate(NEGATIVE_PATTERN_MULTI_CLAUSE_MULTI_LIST2))

def test_undeclared_annotation_prop(self):
self.assertFalse(validate(NEGATIVE_PATTERN_UNDECLARED_ANNOT_PROP))
47 changes: 47 additions & 0 deletions src/schema/test/negative_test_set/undeclared_annotation_prop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
pattern_name: acute

pattern_iri: http://purl.obolibrary.org/obo/mondo/patterns/acute.yaml

description: 'This pattern is applied to diseases that are described as having an acute onset, i.e. the sudden appearance of disease manifestations over a short period of time.
Examples: [acute bronchiolitis](http://purl.obolibrary.org/obo/MONDO_0020680),
[acute liver failure](http://purl.obolibrary.org/obo/MONDO_0019542)'

contributors:
- https://orcid.org/0000-0002-6601-2165
- https://orcid.org/0000-0001-5208-3432

classes:
acute: PATO:0000389
disease: MONDO:0000001

relations:
has modifier: RO:0002573

annotationProperties:
# exact_synonym: oio:hasExactSynonym
related_synonym: oio:hasRelatedSynonym

vars:
disease: '''disease'''

name:
text: acute %s
vars:
- disease

annotations:
- annotationProperty: exact_synonym
text: '%s, acute'
vars:
- disease

def:
text: Acute form of %s.
vars:
- disease

equivalentTo:
text: '%s and ''has modifier'' some ''acute'''
vars:
- disease

0 comments on commit 2371372

Please sign in to comment.