RDFLib:获取命名空间下的所有URI [英] RDFLib: get all URIs under a namespace

查看:209
本文介绍了RDFLib:获取命名空间下的所有URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在RDFlib中获取命名空间下的URI列表?

例如,我们可以做:

from rdflib.namespace import FOAF

但是我们如何找出FOAF中可用的URI?

实际上,有几个名称空间(RDF,RDFS,FOAF等),我发现很难探索每个名称空间中包含哪些URI,以及要使用哪个URI.说,如果我想表达一个归属关系,我应该使用RDFS.member还是其他?有链接数据的标准还是临时的?

我是RDF的新手,很抱歉,这似乎是一个显而易见的问题.

谢谢!

解决方案

IRI只是不透明的标识符.当我们谈到链接数据和语义网时,rdfs:member分配给属性的含义的语义是在语义网的外部中定义的(希望有好的文档,当然应该与属性关联为rdfs:comment等),并按用途进行关联.对于rdfs:member,描述来自RDFS建议:

5.1.6 rdfs:member

rdfs:member是rdf:Property的实例,它是所有容器成员资格属性的超级属性,即每个容器成员资格属性都具有与rdfs:member属性的rdfs:subPropertyOf关系.

rdfs:member的rdfs:domain是rdfs:Resource. rdfs:member的rdfs:range是rdfs:Resource.

在同一文档中描述了容器成员资格属性:

rdfs:ContainerMembershipProperty

rdfs:ContainerMembershipProperty类具有实例rdf:_1,rdf:_2,rdf:_3 ...的属性,这些属性用于声明资源是容器的成员. rdfs:ContainerMembershipProperty是rdf:Property的子类. rdfs:ContainerMembershipProperty的每个实例都是rdfs:member属性的rdfs:subProperty.

给出一个容器C,其形式为以下形式的三倍:

C rdf:_nnn O

其中nnn是大于0且没有前导零的整数的十进制表示,表示O是容器C的成员.

容器成员资格属性可以应用于容器以外的资源.

读完最后一行实际上让我有些惊讶,但是由于成员资格属性和rdfs:member可以应用于容器以外的资源,因此在您自己的数据结构上使用它们似乎是可以接受的./p>

即使如此,定义您自己的更具体的属性并仅断言它是rdfs:member子属性可能更合适.例如,您可以指定将民族国家与某个多民族联盟关联的politics:memberStateOf属性是rdfs:subPropertyOf rdfs:member.

在其他情况下,咨询词汇文档也是一个好主意.例如,RDFlib页面上的示例可以包括对FOAF的一些使用:

from rdflib import RDF
...
# Create a namespace object for the Friend of a friend namespace.
FOAF = Namespace("http://xmlns.com/foaf/0.1/")
...
# Add triples using store's add method.
store.add((donna, RDF.type, FOAF["Person"]))
store.add((donna, FOAF["nick"], Literal("donna", lang="foo")))

在这里使用FOAF的方式(与您的问题有些不同,也许现在有一个库)使用传入的字符串取决于知道应该存在哪些URI,并且该信息可用在 FOAF规范中.尽管RDF命名空间似乎已定义了一些符号常量(例如,RDF.type),但 解决方案

IRIs are simply opaque identifiers. While we speak of Linked Data and the Semantic Web, the semantics of rdfs:member the meaning assigned to a property is defined outside of the Semantic Web (hopefully by good documentation, which ought, of course, to be associated with the property as an rdfs:comment, or the like), and by usage. For rdfs:member, the description comes from the RDFS recommendation:

5.1.6 rdfs:member

rdfs:member is an instance of rdf:Property that is a super-property of all the container membership properties i.e. each container membership property has an rdfs:subPropertyOf relationship to the property rdfs:member.

The rdfs:domain of rdfs:member is rdfs:Resource. The rdfs:range of rdfs:member is rdfs:Resource.

The container membership properties are described in the same document:

rdfs:ContainerMembershipProperty

The rdfs:ContainerMembershipProperty class has as instances the properties rdf:_1, rdf:_2, rdf:_3 ... that are used to state that a resource is a member of a container. rdfs:ContainerMembershipProperty is a subclass of rdf:Property. Each instance of rdfs:ContainerMembershipProperty is an rdfs:subPropertyOf the rdfs:member property.

Given a container C, a triple of the form:

C rdf:_nnn O

where nnn is the decimal representation of an integer greater than 0 with no leading zeros, states that O is a member of the container C.

Container membership properties may be applied to resources other than containers.

I was actually a bit surprised to read that last line, but since the membership properties and rdfs:member can be applied to resources other than containers, it seems like it would be acceptable to use them on your own data structures.

Even so, it might be more appropriate to define your own more specific property and simply assert that it's a subproperty of rdfs:member. For instance, you might specify that a politics:memberStateOf property relating a nation state to some multi-national union is an rdfs:subPropertyOf rdfs:member.

Consulting the documentation of vocabularies is a good idea in other situations too. For instance, the examples on the RDFlib page do include some use of FOAF:

from rdflib import RDF
...
# Create a namespace object for the Friend of a friend namespace.
FOAF = Namespace("http://xmlns.com/foaf/0.1/")
...
# Add triples using store's add method.
store.add((donna, RDF.type, FOAF["Person"]))
store.add((donna, FOAF["nick"], Literal("donna", lang="foo")))

The way that FOAF is being used here (which is a bit different than in your question, perhaps there's a library for it now) with strings being passed in depends on being aware of what URIs should exist, and that information is available in the FOAF specification. Although it appears that the RDF Namespace has some symbolic constants defined (e.g., RDF.type), the documentation says that RDF.type is actually equivalent to RDF['type']:

Fully qualified URIs in the namespace can be constructed either by attribute or by dictionary access on Namespace instances:

  >>> owl.seeAlso
  rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#seeAlso')
  >>> owl['seeAlso']
  rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#seeAlso')

这篇关于RDFLib:获取命名空间下的所有URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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