RDFLib:XML 序列化中的命名空间前缀
- 作者: 青狮金角
- 来源: 51数据库
- 2023-01-31
问题描述
在使用 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.
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
