Repository: OnroerendErfgoed/skosprovider_rdf

Issue:
Don't export local id as dcterms.identifier when it's the URI
When reading a SKOS file, we assign the URI to the id attribute because our skosprovider expects an internal identifier. But, when exporting the provider to SKOS again, we export this id to dcterms:identifier. This creates extra information in the SKOS file that isn't completely. Solution: when exporting to SKOS, if id is equal to uri, don't generate dcterms:identifier statements.

Comments:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index b0e2a7b..3c5a727 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,3 +1,9 @@
+1.3.0 (??-12-2022)
+------------------
+
+- Don't export local id as dcterms.identifier when it's equal to the URI (#117)
+- Add support for Python 3.10 and Python 3.11 (#120) 
+
 1.2.0 (11-10-2022)
 ------------------
 
diff --git a/setup.py b/setup.py
index b97c9d9..b917507 100644
--- a/setup.py
+++ b/setup.py
@@ -24,7 +24,7 @@ requires = [
 
 setup(
     name='skosprovider_rdf',
-    version='1.2.0',
+    version='1.3.0',
     description='skosprovider_rdf',
     long_description=README + '\n\n' + HISTORY,
     long_description_content_type='text/x-rst',
diff --git a/skosprovider_rdf/utils.py b/skosprovider_rdf/utils.py
index ea19f7b..1914a80 100644
--- a/skosprovider_rdf/utils.py
+++ b/skosprovider_rdf/utils.py
@@ -142,7 +142,8 @@ def _add_c(graph, provider, id):
     c = provider.get_by_id(id)
     subject = URIRef(c.uri)
     _add_in_dataset(graph, subject, provider)
-    graph.add((subject, DCTERMS.identifier, Literal(c.id)))
+    if c.id != c.uri:
+        graph.add((subject, DCTERMS.identifier, Literal(c.id)))
     conceptscheme = URIRef(provider.concept_scheme.uri)
     graph.add((subject, SKOS.inScheme, conceptscheme))
     _add_labels(graph, c, subject)


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 86b9f11..446b318 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -2,6 +2,7 @@ import pytest
 from rdflib import Graph
 from rdflib import Namespace
 from rdflib.namespace import DCTERMS
+from rdflib.namespace import DC
 from rdflib.namespace import RDF
 from rdflib.namespace import SKOS
 from rdflib.term import Literal
@@ -255,6 +256,26 @@ class TestRDFDumperProducts:
         graph_dump = utils.rdf_dumper(products_provider)
         assert isinstance(graph_dump, Graph)
 
+    def test_dump_rdf_no_uri_as_local_identifier(self, products_provider, caplog):
+        caplog.set_level(logging.DEBUG)
+        graph_dump = utils.rdf_dumper(products_provider)
+
+        prod_uri = 'http://www.prodcuts.com/Product'
+        jewel_uri = 'http://www.products.com/Jewellery'
+        perfume_uri = 'http://www.products.com/Perfume'
+
+        prod = URIRef(prod_uri)
+        jewel = URIRef(jewel_uri)
+        perfume = URIRef(perfume_uri)
+
+        log.debug(graph_dump.serialize(format='turtle'))
+
+        assert (prod, DCTERMS.identifier, Literal(prod_uri)) not in graph_dump
+        assert (prod, DC.identifier, Literal(prod_uri)) not in graph_dump
+        assert (jewel, DCTERMS.identifier, Literal(jewel_uri)) not in graph_dump
+        assert (jewel, DC.identifier, Literal(jewel_uri)) not in graph_dump
+        assert (perfume, DCTERMS.identifier, Literal(perfume_uri)) not in graph_dump
+        assert (perfume, DC.identifier, Literal(perfume_uri)) not in graph_dump
 
 class TestRDFDumperTrees: