Sparql-将限制条件应用于谓词 [英] Sparql - Applying limiting criteria to predicates

查看:91
本文介绍了Sparql-将限制条件应用于谓词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对RDF/Sparql还是很陌生,因此对任何不正确的术语以及下面的非常糟糕的示例表示歉意:

I'm fairly new to RDF / Sparql, so apologies for any incorrect terminology, and also for the fairly terrible example that follows:

给出以下RDF数据集:

Given the following RDF dataset:

@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 .

我正在尝试识别e:Marty仅通过其他e:Freemason认识的朋友.

I'm trying to identify friends-of-friends that e:Marty knows through other e:Freemasons only.

所以:

  • Marty通过Eugene认识Mike,而且他们都是共济会成员,所以很好
  • 玛莉(Marty)认识尤金(Eugene),后者有一位平民朋友保罗.保罗有一个共济会的朋友艾伦.但是,马蒂(Marty)没有通往艾伦(Alan)"的仅限共济会"之路,因此应将他排除在外.
  • Marty knows Mike through Eugene, and they're all Freemason's so it's fine
  • Marty knows Eugene, who has a Civilian friend Paul. Paul has a Freemason friend Alan. However, Marty doesn't have a "freemason only" path to Alan, so he should be excluded.

这是我的SPARQL查询:

Here's the SPARQL query I have:

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 .
}

这将返回:

 http://www.example.com/#Eugene
 http://www.example.com/#Mike
 http://www.example.com/#Alan

在这里,Alan符合is-a-freemason标准,因此也包括在内.

Here, Alan is included as he matches the is-a-freemason criteria.

我如何修改查询以排除Alan?

How I do modify the query to exclude Alan?

推荐答案

下面是一个使用SPARQL的示例,该示例已从规范中弃用(出于我从未理解的原因),但仍在Virtuoso中受支持(这种情况在无法预见的情况下会发生)未来)

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)

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 .
}

实时链接:

  1. %0D%0A%7B%0D% 0A ++< http%3A%2F%2Fwww.example.com%2F%23Marty> + foaf%3Aknows%7B2%7D +%3Ftarget +.%0D%0A ++%3Ftarget + a + e%3AFreemason +.%0D%0A% 7D& sho-sponge =& format = text%2Fx-html%2Btr& CXML_redir_for_subjs = 121& CXML_redir_for_hrefs =& timeout = 30000000"rel =" nofollow noreferrer>查询定义
  1. Query Solution
  2. Query Definition

这篇关于Sparql-将限制条件应用于谓词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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