W3C home > Mailing lists > Public > semantic-web@w3.org > July 2014

Re: to navigate the whole network to the end of all branches and nodes by SPARQL

From: Lei Xu <lei.xu@marklogic.com>
Date: Fri, 11 Jul 2014 05:31:25 +0000
To: Miguel <miguel.ceriani@gmail.com>
CC: "semantic-web@w3.org" <semantic-web@w3.org>
Message-ID: <CFE5A131.61DC%lei.xu@marklogic.com>
Hello Miguel,

I changed the query a little bit and worked very well.

PREFIX rev: <http://dbpedia.org/review/>
PREFIX pd: <http://dbpedia.org/product/>
PREFIX pe: <http://dbpedia.org/person/>

SELECT distinct ?person ?product  WHERE
{
  pd:01 ^(rev:5|rev:4)/((rev:5|rev:4)/^(rev:5|rev:4))* ?person.
  ?person (rev:5|rev:4) ?product.
}


Appreciate it a lot.

What if I want to do something further - to get the object based on the
previous result.
Eventually get a table with 3 arrays like below:
person rev(4|5) product


Trying to figure out how to do it.

Thanks,
Lei Xu

On 7/10/14, 7:50 PM, "Miguel" <miguel.ceriani@gmail.com> wrote:

>Hi,
>If you are using SPARQL 1.1 you can use Property Paths
>(http://www.w3.org/TR/sparql11-query/#propertypaths).
>
>I this case the query should be:
>
>PREFIX rev: <http://dbpedia.org/review/>
>PREFIX pd: <http://dbpedia.org/product/>
>SELECT DISTINCT ?person ?product
>WHERE
>{ pd:04 ^rev:5/(rev:5/^rev:5)* ?person .
>  pd:04 (^rev:5/rev:5)* ?product .
>}
>
>Anyway, there could be performance issues, so you have to check if
>this approach is actually feasible in your case.
>
>Best,
>Miguel
>
>On Thu, Jul 10, 2014 at 5:33 AM, Lei Xu <lei.xu@marklogic.com> wrote:
>> Hello all,
>>
>> Trying to create something similar with Amazonšs recommendation list by
>>RDF
>> and SPARQL.
>>
>> I have n-quad rdf like below.
>> subject:person predicate:review_score object:product
>>
>> 
>><http://dbpedia.org/person/A><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/04><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/A><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/16><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/B><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/16><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/B><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/04><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/B><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/07><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/C><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/07><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/C><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/10><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/D><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/10><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/D><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/11><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/E><http://dbpedia.org/review/4><http://dbpedia
>>.org/product/12><http://source-description/review>
>> .
>> 
>><http://dbpedia.org/person/E><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/14><http://source-description/review>
>> .
>>
>> The query starts with a specified product ­ for example product 04.
>> Step 1. Find all the people who have reviewed this specified product as
>> score = 5.
>> Step 2. Find all the reviewed products by the people from Step 1 as
>>score =
>> 5.
>> Step 3. Find all the people who have reviewed the products from Step 2
>>as
>> score = 5.
>> ..
>> ..
>> Step n. Until no more descendants nodes.
>> Eventually I want to have a list with 2 arrays:
>>
>> 1. All the matching products.
>> 2. All the related people.
>>
>> Because Ešs review on product 12 only scores 4 then the branch from E
>>will
>> be excluded. So the expected result should look like this.
>>
>> 
>><http://dbpedia.org/person/A><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/04>
>> 
>><http://dbpedia.org/person/A><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/16>
>> 
>><http://dbpedia.org/person/B><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/16>
>> 
>><http://dbpedia.org/person/B><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/04>
>> 
>><http://dbpedia.org/person/B><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/07>
>> 
>><http://dbpedia.org/person/C><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/07>
>> 
>><http://dbpedia.org/person/C><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/10>
>> 
>><http://dbpedia.org/person/D><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/10>
>> 
>><http://dbpedia.org/person/D><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/11>
>>
>> My SPARQL looks like below:
>>
>> PREFIX rev: <http://dbpedia.org/review/>
>> PREFIX pd: <http://dbpedia.org/product/>
>> SELECT distinct ?s2 ?o2  WHERE
>> { ?s rev:5 pd:04.
>>   ?s rev:5 ?o2 .
>>   ?s2 rev:5 ?o2 .
>> }
>>
>> And the result is like below:
>>
>> 
>><http://dbpedia.org/person/A><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/04>
>> 
>><http://dbpedia.org/person/A><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/16>
>> 
>><http://dbpedia.org/person/B><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/16>
>> 
>><http://dbpedia.org/person/B><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/04>
>> 
>><http://dbpedia.org/person/B><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/07>
>> 
>><http://dbpedia.org/person/C><http://dbpedia.org/review/5><http://dbpedia
>>.org/product/07>
>>
>> It is different from expected. There must be something wrong with the
>>query
>> pattern. I would like to navigate all the way to the end of the network
>>with
>> certain constraints.
>> What I am looking for is a feature similar with Oracle SQLšs
>> SYS_CONNECT_BY_PATH function. But I do not know how to realize it with
>> SPARQL..
>>
>> Any ideas and hints will be appreciated.
>>
>> Thanks,
>> Lei Xu
>>
Received on Friday, 11 July 2014 05:31:50 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 1 March 2016 07:42:52 UTC