如何使用SPARQL从三元组中提取rdf:about或rdf:ID属性? [英] How can one extract rdf:about or rdf:ID properties from triples using SPARQL?

查看:186
本文介绍了如何使用SPARQL从三元组中提取rdf:about或rdf:ID属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始时这似乎是一件小事,但到目前为止,我还没有使用SPARQL来获取给定资源的唯一标识符.给出了我的意思,例如rdf:Description rdf:about="http://...",然后是一些标识此资源的属性,我要做的是首先找到该资源,然后在给定URI的情况下检索所有三元组.

It seemed a trivial matter at the beginning but so far I have not managed to get the unique identifier for a given resource using SPARQL. What I mean is given, e.g., rdf:Description rdf:about="http://..." and then some properties identifying this resource, what I want to do is to first find this very resource and then retrieve all the triples given some URI.

我尝试通过在WHERE子句中编写语句来尝试幼稚的方法,例如:

I have tried naïve approaches by writing statements in a WHERE clause such as:

?x rdf:about ?y and ?x rdfs:about ?y

我希望我很精确.

推荐答案

您正在犯一个经典的错误:将RDF(这是SPARQL查询的内容)与其序列化之一(即RDF/XML)混淆了. rdf:about(和rdf:IDrdf:Descriptionrdf:resource)是RDF/XML的一部分,这是RDF的一种记录方式.您可以使用 RDF验证器来查看某个RDF/XML.

You're making a classic mistake: confusing RDF (which is what SPARQL queries) with (one of) its serialisation, namely RDF/XML. rdf:about (and rdf:ID, rdf:Description, rdf:resource) are part of RDF/XML, a way RDF is written down. You can play around with the RDF Validator to see what RDF triples result from a piece of RDF/XML.

在您的情况下,让我们开始:

In your case let's start with:

<?xml version="1.0"?>
<rdf:RDF 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/terms/">
  <rdf:Description rdf:about="http://www.example.org/">
    <dc:title>Example for Donal Fellows</dc:title> 
  </rdf:Description>
</rdf:RDF>

将其插入验证器,您将得到:

Number      Subject                      Predicate                        Object
1           http://www.example.org/      http://purl.org/dc/terms/title   "Example for Donal Fellows"

(您也可以要求提供图片代表)

(you can also ask for a pictorial representation)

请注意,rdf:about不存在:其值提供了三元组的主题.

Notice that rdf:about is not present: its value provides the subject for the triple.

如何查询与http://www.example.org关联的属性?像这样:

How do I do a query to find properties associated with http://www.example.org? Like this:

select * {
    <http://www.example.org/> ?predicate ?object
}

您将获得:

?predicate                        ?object
<http://purl.org/dc/terms/title>  "Example for Donal Fellows"

您会注意到,查询是在我们要查找值的位置与变量(?v)的三重匹配.我们还可以通过询问:

You'll notice that the query is a triple match with variables (?v) in places where we want to find values. We could also ask what predicate links http://www.example.org/ with "Example for..." by asking:

select * {
    <http://www.example.org/> ?predicate "Example for Donal Fellows"
}

这种模式匹配是SPARQL的核心.

This pattern matching is the heart of SPARQL.

RDF/XML是一个棘手的野兽,您可能会发现使用 N-Triples ,它非常冗长但清晰,或者 turtle ,类似于N-Triples,其中包含大量的速记和缩写.乌龟通常是rdf社区的首选.

RDF/XML is a tricky beast, and you might find it easier to work with N-Triples, which is very verbose but clear, or turtle, which is like N-Triples with a large number of shorthands and abbreviations. Turtle is often preferred by the rdf community.

P.S. rdfs:about在任何地方都不存在.

P.S. rdfs:about doesn't exist anywhere.

这篇关于如何使用SPARQL从三元组中提取rdf:about或rdf:ID属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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