diff --git a/ontopy/utils.py b/ontopy/utils.py index 2a9248e8..b9bfdc92 100644 --- a/ontopy/utils.py +++ b/ontopy/utils.py @@ -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): diff --git a/tests/ontopy_tests/test_utils.py b/tests/ontopy_tests/test_utils.py index 38cf2826..0386bc71 100644 --- a/tests/ontopy_tests/test_utils.py +++ b/tests/ontopy_tests/test_utils.py @@ -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 @@ -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():