I'm just dabbling in managing RDF with python using rdflib, and ran across this page (http://www.obitko.com/tutorials/ontologies-semantic-web/rdf-graph-and-syntax.html) that outlines some RDF syntax. In it, the RDF example is the following:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns="http://www.example.org/~joe/contact.rdf#">
<foaf:Person rdf:about="http://www.example.org/~joe/contact.rdf#joesmith">
<foaf:mbox rdf:resource="mailto:joe.smith@example.org"/>
<foaf:homepage rdf:resource="http://www.example.org/~joe/"/>
<foaf:family_name>Smith</foaf:family_name>
<foaf:givenname>Joe</foaf:givenname>
</foaf:Person>
</rdf:RDF>
In here, the code for the RDF object denotes foaf:Person
, but in all other instances I've seen, this line is rdf:Description
. I'm curious whether this example is correct, and if so then what the difference is between this re-definition and the standard rdf:Description
syntax. Furthermore, how would one implement this namespace in python using rdflib? I've currently got the following code, which creates the example RDF, but it results in rdf:Description
instead of foaf:Person
for that line:
import rdflib as rd
from rdflib.namespace import FOAF
joe = rd.URIRef("http://www.example.org/~joe/contact.rdf#joesmith")
joeEmail = rd.URIRef('mailto:joe.smith@example.org')
joeHome = rd.URIRef('http://www.example.org/~joe/')
joeFamily = rd.Literal('Smith')
joeName = rd.Literal('Joe')
g = rd.Graph()
g.bind('foaf', FOAF, False)
g.add((joe, FOAF.mbox, joeEmail))
g.add((joe, FOAF.homepage, joeHome))
g.add((joe, FOAF.family_name, joeFamily))
g.add((joe, FOAF.givenname, joeName))
fp = open('outfile.rdf','wb')
fp.write(g.serialize(format='xml'))
fp.close()