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

Add possibility to set authority and basepath to skolemize graph #807

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,21 +1218,21 @@ def _process_skolem_tuples(self, target, func):
for t in self.triples((None, None, None)):
target.add(func(t))

def skolemize(self, new_graph=None, bnode=None):
def skolemize(self, new_graph=None, bnode=None, authority=None, basepath=None):
def do_skolemize(bnode, t):
(s, p, o) = t
if s == bnode:
s = s.skolemize()
s = s.skolemize(authority=authority, basepath=basepath)
if o == bnode:
o = o.skolemize()
o = o.skolemize(authority=authority, basepath=basepath)
return (s, p, o)

def do_skolemize2(t):
(s, p, o) = t
if isinstance(s, BNode):
s = s.skolemize()
s = s.skolemize(authority=authority, basepath=basepath)
if isinstance(o, BNode):
o = o.skolemize()
o = o.skolemize(authority=authority, basepath=basepath)
return (s, p, o)

retval = Graph() if new_graph is None else new_graph
Expand Down
8 changes: 6 additions & 2 deletions rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,17 @@ def __repr__(self):
clsName = self.__class__.__name__
return """%s('%s')""" % (clsName, str(self))

def skolemize(self, authority="http://rdlib.net/"):
def skolemize(self, authority=None, basepath=None):
""" Create a URIRef "skolem" representation of the BNode, in accordance
with http://www.w3.org/TR/rdf11-concepts/#section-skolemization

.. versionadded:: 4.0
"""
skolem = "%s%s" % (rdflib_skolem_genid, text_type(self))
if authority is None:
authority = "http://rdlib.net/"
if basepath is None:
basepath = rdflib_skolem_genid
skolem = "%s%s" % (basepath, text_type(self))
return URIRef(urljoin(authority, skolem))


Expand Down