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

Fixed failures in rename_iris() #820

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 18 additions & 8 deletions ontopy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,15 +780,25 @@ def rename_iris(onto, annotation="prefLabel"):
to the value of the annotation. Also add an `skos:exactMatch`
annotation referring to the old IRI.
"""
exactMatch = onto._abbreviate( # pylint:disable=invalid-name
"http://www.w3.org/2004/02/skos/core#exactMatch"
)
# exactMatch = onto._abbreviate( # pylint:disable=invalid-name
# "http://www.w3.org/2004/02/skos/core#exactMatch"
# )
for entity in onto.get_entities():
if hasattr(entity, annotation) and getattr(entity, annotation):
onto._add_data_triple_spod(
entity.storid, exactMatch, entity.iri, ""
)
entity.name = getattr(entity, annotation).first()
label = getattr(entity, annotation).first()
if (
label
and not onto.world[f"{onto.base_iri}{label}"]
and hasattr(entity, annotation)
and getattr(entity, annotation)
):
# pylint: disable=fixme
# FIXME: Saving the below skos:exactMatch relations makes Owlready2
# crash when saving.
#
# onto._add_data_triple_spod(
# entity.storid, exactMatch, entity.iri, ""
# )
entity.name = label


def normalise_url(url):
Expand Down
28 changes: 20 additions & 8 deletions tests/ontopy_tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import sys
from pathlib import Path

import ontopy.utils as utils

thisdir = Path(__file__).resolve().parent
sys.path.append(str(thisdir.parent / "utilities"))
from utilities import get_triples, has_triple


Expand Down Expand Up @@ -27,16 +33,22 @@ def test_annotate_source(testonto: "Ontology"):
)


# if True:
# from ontopy import get_ontology
# path = Path(__file__).parent.parent.resolve() / "testonto"
# testonto = get_ontology(str(path) + "/testonto.ttl").load()


def test_rename_iris(testonto: "Ontology"):
assert not has_triple(testonto, s="http://emmo.info/models#TestClass")
assert not has_triple(testonto, s="http://emmo.info/testonto#TestClass")
utils.rename_iris(testonto)
assert has_triple(testonto, s="http://emmo.info/models#TestClass")
assert has_triple(
testonto,
"http://emmo.info/models#TestClass",
"http://www.w3.org/2004/02/skos/core#exactMatch",
"http://emmo.info/models#testclass",
)
assert has_triple(testonto, s="http://emmo.info/testonto#TestClass")
# assert has_triple(
# testonto,
# "http://emmo.info/models#TestClass",
# "http://www.w3.org/2004/02/skos/core#exactMatch",
# "http://emmo.info/models#testclass",
# )


def test_preferred_language():
Expand Down
Loading