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

Handle owlready2:python_names in genated triples in excelparser #795

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 24 additions & 0 deletions ontopy/excelparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@
if input_ontology:
onto = input_ontology
catalog = {}
# Since we will remove newly created python_name added
# by owlready2 in the triples, we keep track of those
# that come from the input ontology
pyname_triples_to_keep = list(
onto.get_unabbreviated_triples(
predicate="http://www.lesfleursdunormal.fr/static/_downloads/"
"owlready_ontology.owl#python_name"
)
)
else: # Create new ontology
onto, catalog = get_metadata_from_dataframe(
metadata, base_iri, imports=imports
Expand Down Expand Up @@ -456,6 +465,21 @@
entities_with_errors = {
key: set(value) for key, value in entities_with_errors.items()
}

# Remove triples with predicate 'python_name' added by owlready2
onto._del_data_triple_spod( # pylint: disable=protected-access
p=onto._abbreviate( # pylint: disable=protected-access
"http://www.lesfleursdunormal.fr/static/_downloads/"
"owlready_ontology.owl#python_name"
)
)
# Add back the triples python name triples that were in the input_ontology.
if input_ontology:
for triple in pyname_triples_to_keep:
onto._add_data_triple_spod( # pylint: disable=protected-access

Check warning on line 479 in ontopy/excelparser.py

View check run for this annotation

Codecov / codecov/patch

ontopy/excelparser.py#L479

Added line #L479 was not covered by tests
s=triple[0], p=triple[1], o=triple[2]
)

return onto, catalog, entities_with_errors


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defusedxml>=0.7.1,<1
graphviz>=0.16,<0.21
numpy>=1.19.5,<3
openpyxl>=3.0.9,<3.2
Owlready2>=0.28,!=0.32,!=0.34,<0.45
Owlready2>=0.28,!=0.32,!=0.34,<0.46
packaging>=21.0,<25
pandas>=1.2,<2.3
Pygments>=2.7.4,<3
Expand Down
33 changes: 33 additions & 0 deletions tests/test_excelparser/test_excelparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,39 @@ def test_excelparser(repo_dir: "Path") -> None:
assert updated_onto.FinitePattern.iri == onto.FinitePattern.iri
assert len(list(onto.classes())) + 1 == len(list(updated_onto.classes()))

# check that the owlready2 generated python names are not in the triples
assert (
list(
ontology.get_unabbreviated_triples(
predicate="http://www.lesfleursdunormal.fr/static/_downloads/"
"owlready_ontology.owl#python_name"
)
)
== []
)
# check that the owlready2 generated python names are not in the triples
assert (
list(
updated_onto.get_unabbreviated_triples(
predicate="http://www.lesfleursdunormal.fr/static/_downloads/"
"owlready_ontology.owl#python_name"
)
)
== []
)

# Just to be sure that the method of getting the correct triples is OK
assert (
len(
list(
ontology.get_unabbreviated_triples(
predicate="http://www.w3.org/2000/01/rdf-schema#subClassOf"
)
)
)
> 1
)


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