問題描述
在使用 RDFLib 3.0 的 Python 腳本中,我在序列化三元組時得到以下 XML 輸出:
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#"
>
如何為那些由 RDFLib(或者分別是 XML-Serializer)自動分配的匿名 _x-prefixes 定義特定的命名空間前綴?
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#"
>
非常感謝您的回復!
推薦答案
我最終通過查看一些(分布相當混亂的)rdflib doc 文件找到了解決方案.對于存儲三元組的 (Conjunctive)Graph,調用
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))
即
mygraph.bind('ex', URIRef('http://www.my-example.intra/ontologies/ci.owl#'))
將False"作為第三個參數傳遞會覆蓋現有的命名空間前綴綁定.
Passing 'False' as 3rd argument overrides existing namespace prefix bindings.
這篇關于RDFLib:XML 序列化中的命名空間前綴的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!