Skip to content
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

Merged
merged 6 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@
)

elif write_catalog_file:
write_catalog(

Check warning on line 971 in ontopy/ontology.py

View check run for this annotation

Codecov / codecov/patch

ontopy/ontology.py#L971

Added line #L971 was not covered by tests
{self.get_version(as_iri=True): filename},
output=catalog_file,
directory=dir,
Expand Down Expand Up @@ -1941,6 +1941,14 @@
"""
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)

Comment on lines +1944 to +1951
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.


class BlankNode:
"""Represents a blank node.
Expand Down Expand Up @@ -2008,31 +2016,31 @@


def _get_unabbreviated_triples(
self, subject=None, predicate=None, obj=None, blank=None
onto, subject=None, predicate=None, obj=None, blank=None
Copy link
Collaborator

Choose a reason for hiding this comment

The 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,
)
Binary file modified tests/test_excelparser/onto_only_classes.xlsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to compare the files visually, but can't spot the change. Can you explain?

Binary file not shown.
2 changes: 1 addition & 1 deletion tests/test_excelparser/result_ontology/fromexcelonto.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 .

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
<http://ontology.info/ontology> ;
owl:versionInfo "0.01"@en .

Expand Down
16 changes: 14 additions & 2 deletions tests/test_excelparser/test_excelparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

# if True:
# from pathlib import Path
#
# repo_dir = Path(__file__).resolve().parent.parent.parent

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed

ontopath = (
repo_dir
/ "tests"
Expand All @@ -119,6 +125,12 @@ def test_excelparser_only_classes(repo_dir: "Path") -> None:
# Used for printing new ontology when debugging
# ontology.save("test_only_classes.ttl")

print("----- only in onto -----")
print(onto.difference(ontology))

print("----- only in ontology -----")
print(ontology.difference(onto))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be remobed

assert onto == ontology
assert errors["already_defined"] == {"SpecialPattern"}
assert errors["in_imported_ontologies"] == {"Atom"}
Expand All @@ -143,5 +155,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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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()))
Loading