Skip to content

Commit d3f8e88

Browse files
authored
Handle owlready2:python_names in genated triples in excelparser (#795)
# Description EMMOntoPy tests fail with owlready0.45 and higher. I want to fix one owlready release at a time, since there seem to be different things that are incompatible going up to v0.48. In v 0.45 owlready2 introduced the python names defined with the predicate "http://www.lesfleursdunormal.fr/static/_downloads/owlready_ontology.owl#python_name" in the ontology. These should not be part of the generated ontology and have therefore been removed in the ontology generated with the excelparser.
1 parent 0f6c235 commit d3f8e88

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

ontopy/excelparser.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,15 @@ def create_ontology_from_pandas( # pylint:disable=too-many-locals,too-many-bran
313313
if input_ontology:
314314
onto = input_ontology
315315
catalog = {}
316+
# Since we will remove newly created python_name added
317+
# by owlready2 in the triples, we keep track of those
318+
# that come from the input ontology
319+
pyname_triples_to_keep = list(
320+
onto.get_unabbreviated_triples(
321+
predicate="http://www.lesfleursdunormal.fr/static/_downloads/"
322+
"owlready_ontology.owl#python_name"
323+
)
324+
)
316325
else: # Create new ontology
317326
onto, catalog = get_metadata_from_dataframe(
318327
metadata, base_iri, imports=imports
@@ -456,6 +465,21 @@ def create_ontology_from_pandas( # pylint:disable=too-many-locals,too-many-bran
456465
entities_with_errors = {
457466
key: set(value) for key, value in entities_with_errors.items()
458467
}
468+
469+
# Remove triples with predicate 'python_name' added by owlready2
470+
onto._del_data_triple_spod( # pylint: disable=protected-access
471+
p=onto._abbreviate( # pylint: disable=protected-access
472+
"http://www.lesfleursdunormal.fr/static/_downloads/"
473+
"owlready_ontology.owl#python_name"
474+
)
475+
)
476+
# Add back the triples python name triples that were in the input_ontology.
477+
if input_ontology:
478+
for triple in pyname_triples_to_keep:
479+
onto._add_data_triple_spod( # pylint: disable=protected-access
480+
s=triple[0], p=triple[1], o=triple[2]
481+
)
482+
459483
return onto, catalog, entities_with_errors
460484

461485

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defusedxml>=0.7.1,<1
44
graphviz>=0.16,<0.21
55
numpy>=1.19.5,<3
66
openpyxl>=3.0.9,<3.2
7-
Owlready2>=0.28,!=0.32,!=0.34,<0.45
7+
Owlready2>=0.28,!=0.32,!=0.34,<0.46
88
packaging>=21.0,<25
99
pandas>=1.2,<2.3
1010
Pygments>=2.7.4,<3

tests/test_excelparser/test_excelparser.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,39 @@ def test_excelparser(repo_dir: "Path") -> None:
9595
assert updated_onto.FinitePattern.iri == onto.FinitePattern.iri
9696
assert len(list(onto.classes())) + 1 == len(list(updated_onto.classes()))
9797

98+
# check that the owlready2 generated python names are not in the triples
99+
assert (
100+
list(
101+
ontology.get_unabbreviated_triples(
102+
predicate="http://www.lesfleursdunormal.fr/static/_downloads/"
103+
"owlready_ontology.owl#python_name"
104+
)
105+
)
106+
== []
107+
)
108+
# check that the owlready2 generated python names are not in the triples
109+
assert (
110+
list(
111+
updated_onto.get_unabbreviated_triples(
112+
predicate="http://www.lesfleursdunormal.fr/static/_downloads/"
113+
"owlready_ontology.owl#python_name"
114+
)
115+
)
116+
== []
117+
)
118+
119+
# Just to be sure that the method of getting the correct triples is OK
120+
assert (
121+
len(
122+
list(
123+
ontology.get_unabbreviated_triples(
124+
predicate="http://www.w3.org/2000/01/rdf-schema#subClassOf"
125+
)
126+
)
127+
)
128+
> 1
129+
)
130+
98131

99132
def test_excelparser_only_classes(repo_dir: "Path") -> None:
100133
"""This loads the excelfile used and tests that the resulting ontology prior

0 commit comments

Comments
 (0)