W3C home > Mailing lists > Public > semantic-web@w3.org > March 2016

Re: [semantic-web] SPARQL Query question

From: David Booth <david@dbooth.org>
Date: Wed, 2 Mar 2016 09:51:30 -0500
To: 王涛 <wonder232627@gmail.com>, semantic-web@w3.org
Message-ID: <56D6FDF2.1030209@dbooth.org>
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

This archive was generated by hypermail 2.3.1 : Wednesday, 2 March 2016 14:52:00 UTC