Last active
May 24, 2017 01:46
-
-
Save jwestgard/8bdfc61899f94127d373ee3540617df2 to your computer and use it in GitHub Desktop.
Brief instructions on parsing RDF with Python rdflib in the interactive prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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