Skip to content

RDFLibGenid not matched by Graph.query() #1808

@white-gecko

Description

@white-gecko

When I have a Graph object with a blank node in it and perform a skolemization on it, the graph generates RDFLibGenid instances which are not matched by IRIs in a query. To reproduce this I have created the following MWE.
As can be seen, after serializing and parsing the graph, the node is a URIRef that is matched by the same query.

from rdflib import Graph, __version__

print("rdflib version:", __version__)

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

gs = g.skolemize()
for s, p, o in gs:
    print(type(s), s)

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

print(query_with_iri)
print(query_for_all)

print("Get by IRI")
for row in gs.query(query_with_iri):
    print(row)

print("??? ^^^ Why is this empty? ^^^")

print("Get everything")
for row in gs.query(query_for_all):
    print(row)

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

print("Get from parsed graph by IRI")
for row in gp.query(query_with_iri):
    print(row)

print("Get everything from parsed graph")
for row in gp.query(query_for_all):
    print(row)

The Output of the MWE:

rdflib version: 6.1.1
<class 'rdflib.term.BNode'> nbdebdd66e4a84a64b29c66ecfc019d5fb1
<class 'rdflib.term.RDFLibGenid'> http://rdlib.net/.well-known/genid/rdflib/nbdebdd66e4a84a64b29c66ecfc019d5fb1
select ?p ?o { <http://rdlib.net/.well-known/genid/rdflib/nbdebdd66e4a84a64b29c66ecfc019d5fb1> ?p ?o }
select ?s ?p ?o { ?s ?p ?o }
Get by IRI
??? ^^^ Why is this empty? ^^^
Get everything
(RDFLibGenid('http://rdlib.net/.well-known/genid/rdflib/nbdebdd66e4a84a64b29c66ecfc019d5fb1'), rdflib.term.URIRef('urn:prop'), rdflib.term.Literal('val'))
Get from parsed graph by IRI
(rdflib.term.URIRef('urn:prop'), rdflib.term.Literal('val'))
Get everything from parsed graph
(rdflib.term.URIRef('http://rdlib.net/.well-known/genid/rdflib/nbdebdd66e4a84a64b29c66ecfc019d5fb1'), rdflib.term.URIRef('urn:prop'), rdflib.term.Literal('val'))

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions