Reputation: 179
I am working with RDF and using rdflib in python. Able to read, subject predicate and object but when tried to view in turtle format its giving plugin error.
#pip install rdflib
#pip show rdflib
from rdflib import Graph
# Intializing Graph
g = Graph()
# Parse in a RDF file graph dbpedia
g.parse('http://dbpedia.org/resource/Michael_Jackson')
# Loop through each triplet in graph (subj, pred, obj)
for index, (sub, pred, obj) in enumerate(g):
print(sub, pred, obj)
if index == 10:
break
#print entire graph in RDF turtle format
print(g.serialize(format='tt1').decode('u8'))
For the last command I am getting error as :
---------------------------------------------------------------------------
PluginException: No plugin registered for (tt1, <class 'rdflib.serializer.Serializer'>)
Upvotes: 0
Views: 595
Reputation: 1251
@masoom-raza: if this issue is solved (by you!) can you please mark it closed? This is to ensure that all [rdflib] issues that are listed in StackOverflow are kept up-to-date. Thanks.
Also, you might like to:
Graph
object with triples()
master
in the repo, no the pip
version) so you don't have to use serialize().decode()
or even format=ttl
as that's defaulyfrom rdflib import Graph
# Intializing Graph
g = Graph()
# Parse in a RDF file graph dbpedia
g.parse('http://dbpedia.org/resource/Michael_Jackson')
# Loop through each triplet in graph (subj, pred, obj) but no limit
for sub, pred, obj in g.triples():
print(sub, pred, obj)
# print entire graph in RDF turtle format
print(g.serialize())
Upvotes: 2
Reputation: 179
There is the small mistake, format=('tt1'). Instead we have to use format=('ttl'). Alphabet l instead of numeric 1.
Upvotes: 1