RDFLib:XML 序列化中的命名空间前缀 [英] RDFLib: Namespace prefixes in XML serialization

查看:30
本文介绍了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 序列化中的命名空间前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆