- From: Lei Xu <lei.xu@marklogic.com>
- Date: Fri, 11 Jul 2014 01:05:14 +0000
- To: Miguel <miguel.ceriani@gmail.com>
- CC: "semantic-web@w3.org" <semantic-web@w3.org>
Hello Miguel, Thanks for the hint. The current semantic engine I am using does not support * or +. I will check it on a SPARQL 1.1 platform. 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 01:05:38 UTC