[英]Sparql - Applying limiting criteria to predicates
I'm fairly new to RDF / Sparql, so apologies for any incorrect terminology, and also for the fairly terrible example that follows: 我对RDF / Sparql相当新,所以对任何不正确的术语表示道歉,并且对于下面相当可怕的例子也是如此:
Given the following RDF dataset: 给定以下RDF数据集:
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix e: <http://www.example.com/#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
e:Freemason a owl:Class .
e:Civilian a owl:Class .
e:Marty a e:Freemason .
e:Eugene a e:Freemason .
e:Mike a e:Freemason .
e:Alan a e:Freemason .
e:Paul a e:Civilian .
e:Marty foaf:knows e:Eugene .
e:Eugene foaf:knows e:Mike .
e:Eugene foaf:knows e:Paul .
e:Paul foaf:knows e:Alan .
I'm trying to identify friends-of-friends that e:Marty
knows through other e:Freemason
s only. 我正在努力找到朋友的朋友:
e:Marty
通过其他e:Freemason
知道e:Freemason
只有e:Freemason
。
So: 所以:
Here's the SPARQL query I have: 这是我的SPARQL查询:
prefix e: <http://www.example.com/#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
SELECT *
{
<http://www.example.com/#Marty> foaf:knows+ ?target .
?target a e:Freemason .
}
This returns: 返回:
http://www.example.com/#Eugene
http://www.example.com/#Mike
http://www.example.com/#Alan
Here, Alan is included as he matches the is-a-freemason
criteria. 在这里,艾伦被包括在内,因为他符合
is-a-freemason
标准。
How I do modify the query to exclude Alan? 我如何修改查询以排除Alan?
I don't know the solution in pure SPARQL, sorry. 我不知道纯SPARQL中的解决方案,抱歉。 In OpenLink Virtuoso's SPARQL-BI, the solution is this query
在OpenLink Virtuoso的SPARQL-BI中,解决方案就是这个查询
prefix e: <http://www.example.com/#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
select *
where
{
{ select ?orig ?target
where
{ ?orig foaf:knows ?target .
?target a e:Freemason .
}
}
option ( TRANSITIVE,
T_IN(?orig),
T_OUT(?target),
T_DISTINCT,
T_MIN(1)
)
filter ( ?orig = <http://www.example.com/#Marty> )
}
-- with these results -- - 有了这些结果 -
orig target
<http://www.example.com/#Marty> <http://www.example.com/#Eugene>
<http://www.example.com/#Marty> <http://www.example.com/#Mike>
Here's an example using SPARQL that has been deprecated from the spec (for reasons I never understood) but remains supported in Virtuoso (which will be the case for the unforseeable future) 这是一个使用SPARQL的例子,该规范已经从规范中弃用(出于我从未理解的原因)但在Virtuoso中仍然受到支持(对于不可预见的未来将是如此)
PREFIX e: <http://www.example.com/#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT *
FROM <http://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Tutorials/club-member-test.ttl>
{
<http://www.example.com/#Marty> foaf:knows{2} ?target .
?target a e:Freemason .
}
Live Links: 实时链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.