Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RDFLib: Namespace prefixes in XML serialization

In a Python script using RDFLib 3.0, I get the following XML-Output when serializing my triples:

<rdf:RDF
  xmlns:_3="http://www.my-example.intra/ontologies/ci.owl#"
>

How can I define specific namespace prefixes for those anonymous _x-prefixes automatically assigned by RDFLib (or it's XML-Serializer respectively)?

<rdf:RDF
  xmlns:ex="http://www.my-example.intra/ontologies/ci.owl#"
>

Many thanks in advance for your responses!

like image 498
sam Avatar asked Dec 13 '10 09:12

sam


1 Answers

I eventually found a solution to this by looking at some (quite messily distributed) rdflib doc files. For the (Conjunctive)Graph storing the triples, call

mygraph.bind(prefix, URIRef(url))

i.e.

mygraph.bind('ex', URIRef('http://www.my-example.intra/ontologies/ci.owl#'))

Passing 'False' as 3rd argument overrides existing namespace prefix bindings.

like image 101
sam Avatar answered Sep 27 '22 19:09

sam