-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Fix issues with changed IRIs effecting test_excelparser #697
Changes from all commits
b611b8f
bf681e4
a6b13b3
8583d0a
57ff25c
c0b50c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1941,6 +1941,14 @@ def new_annotation_property( | |
""" | ||
return self.new_entity(name, parent, "annotation_property") | ||
|
||
def difference(self, other: owlready2.Ontology) -> set: | ||
"""Return a set of triples that are in this, but not in the | ||
`other` ontology.""" | ||
# pylint: disable=invalid-name | ||
s1 = set(self.get_unabbreviated_triples(blank="_:b")) | ||
s2 = set(other.get_unabbreviated_triples(blank="_:b")) | ||
return s1.difference(s2) | ||
|
||
|
||
class BlankNode: | ||
"""Represents a blank node. | ||
|
@@ -2008,31 +2016,31 @@ def _unabbreviate( | |
|
||
|
||
def _get_unabbreviated_triples( | ||
self, subject=None, predicate=None, obj=None, blank=None | ||
onto, subject=None, predicate=None, obj=None, blank=None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well spotted! |
||
): | ||
"""Help function returning all matching triples unabbreviated. | ||
|
||
If `blank` is given, it will be used to represent blank nodes. | ||
""" | ||
# pylint: disable=invalid-name | ||
abb = ( | ||
None if subject is None else self._abbreviate(subject), | ||
None if predicate is None else self._abbreviate(predicate), | ||
None if obj is None else self._abbreviate(obj), | ||
None if subject is None else onto._abbreviate(subject), | ||
None if predicate is None else onto._abbreviate(predicate), | ||
None if obj is None else onto._abbreviate(obj), | ||
) | ||
for s, p, o in self._get_obj_triples_spo_spo(*abb): | ||
for s, p, o in onto._get_obj_triples_spo_spo(*abb): | ||
yield ( | ||
_unabbreviate(self, s, blank=blank), | ||
_unabbreviate(self, p, blank=blank), | ||
_unabbreviate(self, o, blank=blank), | ||
_unabbreviate(onto, s, blank=blank), | ||
_unabbreviate(onto, p, blank=blank), | ||
_unabbreviate(onto, o, blank=blank), | ||
) | ||
for s, p, o, d in self._get_data_triples_spod_spod(*abb, d=None): | ||
for s, p, o, d in onto._get_data_triples_spod_spod(*abb, d=None): | ||
yield ( | ||
_unabbreviate(self, s, blank=blank), | ||
_unabbreviate(self, p, blank=blank), | ||
_unabbreviate(onto, s, blank=blank), | ||
_unabbreviate(onto, p, blank=blank), | ||
f'"{o}"{d}' | ||
if isinstance(d, str) | ||
else f'"{o}"^^{_unabbreviate(self, d)}' | ||
else f'"{o}"^^{_unabbreviate(onto, d)}' | ||
if d | ||
else o, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
"Jesper Friis"@en, | ||
"Sylvain Gouttebroze"@en ; | ||
dcterms:title "A test domain ontology"@en ; | ||
owl:imports <http://emmo.info/emmo-inferred>, | ||
owl:imports <http://emmo.info/emmo>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not understand why. We import beta-4 which should not have changed as development is now happening in beta5. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is due to backward corrections of ontology IRIs on GitHub Pages. Probably a bad decision, but now it is done and should not be reverted again... |
||
<http://ontology.info/ontology> ; | ||
owl:versionInfo "0.01"@en . | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,14 +91,20 @@ def test_excelparser(repo_dir: "Path") -> None: | |
update_xlspath, force=True, input_ontology=ontology | ||
) | ||
assert updated_onto.ATotallyNewPattern | ||
assert updated_onto.Pattern.iri == onto.Pattern.iri | ||
assert updated_onto.FinitePattern.iri == onto.FinitePattern.iri | ||
assert len(list(onto.classes())) + 1 == len(list(updated_onto.classes())) | ||
|
||
|
||
def test_excelparser_only_classes(repo_dir: "Path") -> None: | ||
"""This loads the excelfile used and tests that the resulting ontology prior | ||
to version 0.5.2 in which only classes where considered, but with empty sheets | ||
for properties.""" | ||
|
||
# Useful for debugging with ipython | ||
# if True: | ||
# from pathlib import Path | ||
# repo_dir = Path(__file__).resolve().parent.parent.parent | ||
|
||
ontopath = ( | ||
repo_dir | ||
/ "tests" | ||
|
@@ -119,6 +125,10 @@ def test_excelparser_only_classes(repo_dir: "Path") -> None: | |
# Used for printing new ontology when debugging | ||
# ontology.save("test_only_classes.ttl") | ||
|
||
# Useful for debugging | ||
# print("----- only in onto -----") | ||
# print(onto.difference(ontology)) | ||
|
||
assert onto == ontology | ||
assert errors["already_defined"] == {"SpecialPattern"} | ||
assert errors["in_imported_ontologies"] == {"Atom"} | ||
|
@@ -143,5 +153,5 @@ def test_excelparser_only_classes(repo_dir: "Path") -> None: | |
update_xlspath, force=True, input_ontology=ontology | ||
) | ||
assert updated_onto.ATotallyNewPattern | ||
assert updated_onto.Pattern.iri == onto.Pattern.iri | ||
assert updated_onto.FinitePattern.iri == onto.FinitePattern.iri | ||
Comment on lines
-146
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check both Pattern (in the imported ontology) and FinitePattern (newly created) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pattern doesn't exists in 1.0.0-beta5, which is the one we have here. |
||
assert len(list(onto.classes())) + 1 == len(list(updated_onto.classes())) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Test the Ontology.difference() methode""" | ||
|
||
|
||
if True: | ||
from pathlib import Path | ||
from ontopy import get_ontology | ||
|
||
repo_dir = Path(__file__).resolve().parent.parent | ||
onto_dir = repo_dir / "tests" / "testonto" | ||
print(repo_dir) | ||
|
||
testonto = get_ontology(onto_dir / "testonto.ttl").load() | ||
testontowi = get_ontology(onto_dir / "testonto_w_individual.ttl").load() | ||
|
||
diff = testonto.difference(testontowi) | ||
diffwi = testontowi.difference(testonto) | ||
assert not diff.intersection(diffwi) | ||
|
||
triple1 = ( | ||
"http://emmo.info/testonto#testindividual", | ||
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type", | ||
"http://www.w3.org/2002/07/owl#NamedIndividual", | ||
) | ||
assert triple1 in diffwi | ||
assert triple1 not in diff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.