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

Fix BNode.skolemize() returning a URIRef instead of an RDFLibGenid. #1493

Merged
merged 3 commits into from
Dec 10, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def skolemize(self, authority=None, basepath=None):
if basepath is None:
basepath = rdflib_skolem_genid
skolem = "%s%s" % (basepath, str(self))
return URIRef(urljoin(authority, skolem))
return RDFLibGenid(urljoin(authority, skolem))


class Literal(Identifier):
Expand Down
42 changes: 42 additions & 0 deletions test/test_issue1404.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from rdflib import Graph, URIRef, FOAF
from rdflib.term import RDFLibGenid
from rdflib.compare import isomorphic


def test_skolem_de_skolem_roundtrip():
"""Test round-trip of skolemization/de-skolemization of data.

Issue: https://github.com/RDFLib/rdflib/issues/1404
"""

ttl = '''
@prefix wd: <http://www.wikidata.org/entity/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

wd:Q1203 foaf:knows [ a foaf:Person;
foaf:name "Ringo" ].
'''

graph = Graph()
graph.parse(data=ttl, format='turtle')

query = {"subject": URIRef("http://www.wikidata.org/entity/Q1203"), "predicate": FOAF.knows}

# Save the original bnode id.
bnode_id = graph.value(**query)

skolemized_graph = graph.skolemize()

# Check the BNode is now an RDFLibGenid after skolemization.
skolem_bnode = skolemized_graph.value(**query)
assert type(skolem_bnode) == RDFLibGenid

# Check that the original bnode id exists somewhere in the uri.
assert bnode_id in skolem_bnode

# Check that the original data is not isomorphic with the skolemized data.
assert not isomorphic(graph, skolemized_graph)

# Check that the original graph data is the same as the de-skolemized data.
de_skolemized_graph = skolemized_graph.de_skolemize()
assert isomorphic(graph, de_skolemized_graph)