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 序列化中的命名空间前缀


- YouTube API v3 返回截断的观看记录 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01