Skip to content

Instantly share code, notes, and snippets.

@jwestgard
Last active May 24, 2017 01:46
Show Gist options
  • Select an option

  • Save jwestgard/8bdfc61899f94127d373ee3540617df2 to your computer and use it in GitHub Desktop.

Select an option

Save jwestgard/8bdfc61899f94127d373ee3540617df2 to your computer and use it in GitHub Desktop.
Brief instructions on parsing RDF with Python rdflib in the interactive prompt
# launch the interactive prompt
python3
# import the module
import rdflib
# create an empty graph object
g = rdflib.Graph()
# parse a turtle file
g.parse('/path/to/your/file.ttl', format='turtle')
# now you have an RDF graph to work with, for example:
len(g)
for (s,p,o) in g: print(s,p,o)
# if you create a second graph object, you can compare the two like this:
g1 == g2
not_g2 = g1 - g2
not_g1 = g2 - g1
etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment