在使用 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模板网!
python:不同包下同名的两个模块和类python: Two modules and classes with the same name under different packages(python:不同包下同名的两个模块和类)
配置 Python 以使用站点包的其他位置Configuring Python to use additional locations for site-packages(配置 Python 以使用站点包的其他位置)
如何在不重复导入顶级名称的情况下构造python包How to structure python packages without repeating top level name for import(如何在不重复导入顶级名称的情况下构造python包)
在 OpenShift 上安装 python 包Install python packages on OpenShift(在 OpenShift 上安装 python 包)
如何刷新 sys.path?How to refresh sys.path?(如何刷新 sys.path?)
分发带有已编译动态共享库的 Python 包Distribute a Python package with a compiled dynamic shared library(分发带有已编译动态共享库的 Python 包)