Re: [semantic-web] SPARQL Query question

On 03/01/2016 10:27 PM, 王涛 wrote:
>> Hello ,]I'm a tiro on studying in Sparql 1.1 which is the standard
>> language of RDF. In my survey ,we can do some join like
>> equal-join,left-outer-join,because the sparql can support the operator
>> equality ,as well as inequality. However,it also support the operator
>> like greater or less.So my question is that can we use the operator of
>> greater or less in the sparql query between two variables,
>> namely,theta-join. I  saw some research claimed that they do the
>> thetajoin on large graph on the cloud,but I did't see some sparql
>> queries contained theta-join, neither in the sparql1.1. So,can you
>> give me some explain what's the problem and can we use thetajoin like
>> the following examples.
>> select ?ename ?grade where {
>> ?emp rdf:type f:emp;
>> foaf:surname ?ename;
>> f:Sal ?sal.
>> ?salgrade rdf:type f:salgrade;
>> f:LoSal ?low;
>> f:HiSal ?high;
>> f:Grade ?grade.
>> FILTER (?sal >= ?low && ?sal <= ?high)
>> }
>> Looking forward to your reply,thank you .

That query worked fine for me when I tested it, after adding namespace 
prefixes:

   PREFIX foaf: <http://xmlns.com/foaf/0.1/>
   PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
   PREFIX f: <http://example/f#>
   PREFIX : <http://example/>

   select ?ename ?grade where {
      ?emp  rdf:type  f:emp;
            foaf:surname ?ename;
            f:Sal ?sal.
       ?salgrade rdf:type f:salgrade;
            f:LoSal ?low;
            f:HiSal ?high;
            f:Grade ?grade.
     FILTER (?sal >= ?low && ?sal <= ?high)
   }

I tried it on the following test data:

   PREFIX foaf: <http://xmlns.com/foaf/0.1/>
   PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
   PREFIX f: <http://example/f#>
   PREFIX : <http://example/>

   :joe  rdf:type  f:emp ;
     foaf:surname "Joe" ;
     f:Sal 500 .

   :sally  rdf:type  f:emp ;
     foaf:surname "Sally" ;
     f:Sal 600 .

   :midGrade rdf:type f:salgrade ;
     f:LoSal 300 ;
     f:HiSal 900 ;
     f:Grade "Mid" .

   :highGrade rdf:type f:salgrade ;
     f:LoSal 500 ;
     f:HiSal 1200 ;
     f:Grade "High" .

And it produced the following result as expected:

?ename ?grade
Joe Mid
Sally Mid
Joe High
Sally High

I hope that helps.

David Booth

Received on Wednesday, 2 March 2016 14:51:58 UTC