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.

Revisions

  1. jwestgard revised this gist May 24, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions python_rdflib_REPL
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,8 @@ g.parse('/path/to/your/file.ttl', format='turtle')
    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
    # if you create a second graph object, you can compare the two like this:
    g1 == g2
    g3 = g1 - g2
    not_g2 = g1 - g2
    not_g1 = g2 - g1
    etc.
  2. jwestgard created this gist May 23, 2017.
    20 changes: 20 additions & 0 deletions python_rdflib_REPL
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # 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
    g1 == g2
    g3 = g1 - g2
    etc.