Sparql - Applying limiting criteria to predicates

折月煮酒 提交于 2019-11-29 15:36:28
Ivan Mikhailov

I don't know the solution in pure SPARQL, sorry. In OpenLink Virtuoso's SPARQL-BI, the solution is this query

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)

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:

  1. Query Solution
  2. Query Definition
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!