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

Conversation

edmondchuc
Copy link
Contributor

@edmondchuc edmondchuc commented Dec 9, 2021

Fixes #1404

Proposed Changes

  • Correctly return RDFLibGenid instead of URIRef as required by Graph.de_skolemize().
  • This fixes skolemize/de-skolemize round-trip which was previously completely broken.
  • Add tests.

Why RDFLibGenid and not Genid? See URIRef.de_skolemize().

rdflib/rdflib/term.py

Lines 308 to 328 in 327de4e

def de_skolemize(self):
"""Create a Blank Node from a skolem URI, in accordance
with http://www.w3.org/TR/rdf11-concepts/#section-skolemization.
This function accepts only rdflib type skolemization, to provide
a round-tripping within the system.
.. versionadded:: 4.0
"""
if isinstance(self, RDFLibGenid):
parsed_uri = urlparse("%s" % self)
return BNode(value=parsed_uri.path[len(rdflib_skolem_genid) :])
elif isinstance(self, Genid):
bnode_id = "%s" % self
if bnode_id in skolems:
return skolems[bnode_id]
else:
retval = BNode()
skolems[bnode_id] = retval
return retval
else:
raise Exception("<%s> is not a skolem URI" % self)

Essentially, RDFLibGenid will correctly grab the original blank node ID before skolemization.

@edmondchuc edmondchuc changed the title Fix BNode.skolemize() returning a URIRef instead of a Genid. Fix BNode.skolemize() returning a URIRef instead of a RDFLibGenid. Dec 9, 2021
@edmondchuc edmondchuc changed the title Fix BNode.skolemize() returning a URIRef instead of a RDFLibGenid. Fix BNode.skolemize() returning a URIRef instead of an RDFLibGenid. Dec 9, 2021
@edmondchuc edmondchuc self-assigned this Dec 9, 2021
@edmondchuc
Copy link
Contributor Author

Let me add some tests for the skolemization/de-skolemization round-trip.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, fwiw.

Copy link
Member

@nicholascar nicholascar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent testing there @edmondchuc!

@nicholascar nicholascar merged commit 0cbc93e into RDFLib:master Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to round-trip skolemize() and de_skolemize()
2 participants