python - How to change `rdf:description` namespace using rdflib? -
i'm dabbling in managing rdf python using rdflib, , ran across page (http://www.obitko.com/tutorials/ontologies-semantic-web/rdf-graph-and-syntax.html) outlines rdf syntax. in it, rdf example 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, code rdf object denotes foaf:person
, in other instances i've seen, line rdf:description
. i'm curious whether example correct, , if difference between re-definition , standard rdf:description
syntax. furthermore, how 1 implement namespace in python using rdflib? i've got following code, creates example rdf, results in rdf:description
instead of foaf:person
line:
import rdflib rd 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()
having <foo:bar>
element opposed <rdf:description>
element syntactic compression used when rdf:type
declared subject.
both examples correct version rdf:description
either missing rdf:type
triple or serialised has chosen not use specific syntactic compression. in general property of rdf/xml, there lots of different ways serialise same graph , given same set of triples different tools may produce different equivalent serialisations.
so in order produce equivalent rdf/xml need add additional rdf:type
triple:
from rdflib.namespace import rdf g.add((joe, rdf.type, foaf.person));
Comments
Post a Comment