RDFLib: Namespace prefixes in XML serialization(RDFLib:XML 序列化中的命名空间前缀)
问题描述
在使用 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 序列化中的命名空间前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:RDFLib:XML 序列化中的命名空间前缀


基础教程推荐
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 筛选NumPy数组 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01