Sparql - Applying limiting criteria to predicates

后端 未结 2 1965
暖寄归人
暖寄归人 2020-12-21 07:32

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

Given the following RDF dataset:<

相关标签:
2条回答
  • 2020-12-21 08:00

    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>
    
    0 讨论(0)
  • 2020-12-21 08:18

    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
    0 讨论(0)
提交回复
热议问题