I am new to RDFLIB in python. I found this example of creating a graph on here. What is the simplest way to visualize graph created by this code?
import rdflib
# Now we create a graph, a representaiton of the ontology
g = rdflib.Graph()
# Now define the key words that we will use (the edge weights of the graph)
has_border_with = rdflib.URIRef('http://www.example.org/has_border_with')
located_in = rdflib.URIRef('http://www.example.org/located_in')
# define the things - base level objects that will be the nodes
# In this case first we have countries
germany = rdflib.URIRef('http://www.example.org/country1')
france = rdflib.URIRef('http://www.example.org/country2')
china = rdflib.URIRef('http://www.example.org/country3')
mongolia = rdflib.URIRef('http://www.example.org/country4')
# then we have continents
europa = rdflib.URIRef('http://www.example.org/part1')
asia = rdflib.URIRef('http://www.example.org/part2')
# Having defined the things and the edge weights, now assemble the graph
g.add((germany,has_border_with,france))
g.add((china,has_border_with,mongolia))
g.add((germany,located_in,europa))
g.add((france,located_in,europa))
g.add((china,located_in,asia))
g.add((mongolia,located_in,asia))
I see that the rdflib package has a tools component that has a function called rdfs2dot. How can I use this function to display a plot with the RDF graph in it?
g.serialize("world.rdf")
, then convert it the dot syntax:rdfs2dot world.rdf > world.dot
, then use whatever tools that allows to plot dot graphs. For instance xdotxdot world.dot
. For some reason, rdfs2dot produces an empty graph. According to the doc of Graph.serialize, rdf is supposed to be the default format, thus either there is a bug here or in rdfs2dot. Maybe look open tickets on github, or post a new issue. – Arsine