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

查看:157
本文介绍了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前缀定义特定的名称空间前缀?

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文件找到了解决方案.对于存储三元组的(合并)图,请调用

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天全站免登陆