开发者

RDFLib: Namespace prefixes in XML serialization

开发者 https://www.devze.com 2023-01-30 11:52 出处:网络
In a Python script using RDFLib 3.0, I get the following XML-Output when serializing my triples: <rdf:RDF

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 automaticall开发者_Python百科y 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消