nquad parsing seems to return empty graph.

58 views
Skip to first unread message

a.sch...@gmail.com

unread,
Dec 27, 2015, 7:33:37 AM12/27/15
to rdflib-dev
Assume the first exampe nquad example from https://dvcs.w3.org/hg/rdf/raw-file/default/nquads/index.html :
<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> <http://example.org/graph3>.
_:subject1 <http://an.example/predicate1> "object1" <http://example.org/graph1> .
_:subject2 <http://an.example/predicate2> "object2" <http://example.org/graph5> .

When using the following code using the file 'quads':

graph = rdf.Graph()
graph = graph.parse(quads, format='nquads')
print("graph has %s statements." % len(graph))
print(list(graph))

The output is:
graph has 0 statements.
[]

What am I missing? I'd be very glad for every assistance!

Jon Crump

unread,
Dec 27, 2015, 2:00:41 PM12/27/15
to rdfli...@googlegroups.com
If quads, you need ConjunctiveGraph(), not Graph()


>>> graph = ConjunctiveGraph()

>>> graph.parse(data=quads, format="nquads")
<Graph identifier=N0a5bf4cb2fa247949e284b5e6ecdfc75 (<class 'rdflib.graph.Graph'>)>

>>> len(graph)
3

>>> print graph.serialize(format="trig")
@prefix ns1: <http://one.example/> .
@prefix ns2: <http://an.example/> .
@prefix ns3: <http://example.org/> .

ns3:graph1 {
    [] ns2:predicate1 "object1" .
}

ns3:graph3 {
    ns1:subject1 ns1:predicate1 ns1:object1 .
}

ns3:graph5 {
    [] ns2:predicate2 "object2" .
}

–– Si vis pacem, bellum adflicta. ––



--
http://github.com/RDFLib
---
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
To post to this group, send email to rdfli...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/fe817dbf-bad3-499b-b0cd-bd62cd03694b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages