Skip to content

Commit

Permalink
Keep 'ci/dependabot-updates' up-to-date with 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
TEAM4-0 committed Oct 29, 2024
2 parents 3404d46 + d3f8e88 commit 12e267d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
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 @@ def create_ontology_from_pandas( # pylint:disable=too-many-locals,too-many-bran
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 @@ def create_ontology_from_pandas( # pylint:disable=too-many-locals,too-many-bran
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
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

0 comments on commit 12e267d

Please sign in to comment.