Skip to content

Commit

Permalink
Add test and fix RDFLib#1808
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondchuc committed Apr 15, 2022
1 parent b9a92fd commit 9a0feed
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
17 changes: 12 additions & 5 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from rdflib.namespace import Namespace, RDF
from rdflib import plugin, exceptions, query, namespace
import rdflib.term
from rdflib.term import BNode, IdentifiedNode, Node, URIRef, Literal, Genid
from rdflib.term import BNode, IdentifiedNode, Node, RDFLibGenid, URIRef, Literal, Genid
from rdflib.paths import Path
from rdflib.store import Store
from rdflib.serializer import Serializer
Expand Down Expand Up @@ -1512,10 +1512,17 @@ def do_de_skolemize(uriref, t):

def do_de_skolemize2(t):
(s, p, o) = t
if isinstance(s, Genid):
s = s.de_skolemize()
if isinstance(o, Genid):
o = o.de_skolemize()

if RDFLibGenid._is_external_skolem(s):
s = Genid(s).de_skolemize()
elif RDFLibGenid._is_rdflib_skolem(s):
s = RDFLibGenid(s).de_skolemize()

if RDFLibGenid._is_external_skolem(o):
o = Genid(o).de_skolemize()
elif RDFLibGenid._is_rdflib_skolem(o):
o = RDFLibGenid(o).de_skolemize()

return s, p, o

retval = Graph() if new_graph is None else new_graph
Expand Down
44 changes: 44 additions & 0 deletions test/test_issues/test_issue1808.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from rdflib import Graph
from rdflib.term import BNode, URIRef, rdflib_skolem_genid


def test():
"""Test skolemised URI query retrieves expected results.
Issue: https://github.com/RDFLib/rdflib/issues/1808
"""

g = Graph()
g.parse(data='[] <urn:prop> "val" .', format="turtle")
for s, p, o in g:
assert isinstance(s, BNode)

gs = g.skolemize()
for s, p, o in gs:
assert isinstance(s, URIRef) and s.__contains__(rdflib_skolem_genid)

query_with_iri = 'select ?p ?o {{ <{}> ?p ?o }}'.format(s)
query_for_all = 'select ?s ?p ?o { ?s ?p ?o }'

count = 0
for row in gs.query(query_with_iri):
count += 1
assert count == 1

count = 0
for row in gs.query(query_for_all):
count += 1
assert count == 1

gp = Graph()
gp.parse(data=gs.serialize(format='turtle'), format='turtle')

count = 0
for row in gp.query(query_with_iri):
count += 1
assert count == 1

count = 0
for row in gp.query(query_for_all):
count += 1
assert count == 1

0 comments on commit 9a0feed

Please sign in to comment.