Using RDF with Python

Nathan R. Yergler

Creative Commons

What This Talk Is

What Is RDF?

RDF Statements

Sample RDF Block


<rdf:RDF xmlns="http://web.resource.org/cc/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Work rdf:about="">
   <license rdf:resource="http://creativecommons.org/licenses/by/2.0/" />
</Work>

<License rdf:about="http://creativecommons.org/licenses/by/2.0/">
   <permits rdf:resource="http://web.resource.org/cc/Reproduction" />
   <permits rdf:resource="http://web.resource.org/cc/Distribution" />
   <requires rdf:resource="http://web.resource.org/cc/Notice" />
   <requires rdf:resource="http://web.resource.org/cc/Attribution" />
   <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
</License>

</rdf:RDF>


Why is RDF Important?

RDF In Use Today

RDF in Python

rdflib



>>> store = TripleStore()

>>> store.parse ( inputsource )

>>> rdf_subjects = store.subjects()

>>> store.predicates(subject="http://web.resource.org/cc/License")
 


pyrple


>>> from pyrple import Triple

>>> from pyrple.namespaces import FOAF, VAR

>>> Triple(VAR.someone, FOAF.knows, VAR.person)
(?someone, , ?person)

pyrple

sparta


    from rdflib.TripleStore import TripleStore
    store = TripleStore()
    store.parse([URI])
    store.prefix_mapping([prefix], [URI])
    Thing = ThingFactory(store)

Real example... ccRdf



>>> rdf_string = """... rdf goes here ..."""
>>> ccr = ccRdf()
>>> ccr.parse(rdf_string)
>>> license = ccr.licenses()[0]
>>> licenses['requires']
['Attribution']

Conclusions

Thanks!