1 Reply Latest reply: Jul 15, 2013 1:26 PM by alwu-Oracle RSS

    problem in writing a query in sparql 1.1

    1006212

      Hello dear friends.

      i'm total beginner in sparql, so it would be great if you could help me.

       

      I have a RDF doc like this:

       

      @prefix foaf: <http://xmlns.com/foaf/0.1/> .

      @prefix lb:   <http://example.org/lastfm/> .

      lb:bob     foaf:knows      lb:user2, lb:user3, lb:user4 ;

                 foaf:age        25 ;

                 lb:listenedTo   lb:track1, lb:track2 ;

                 lb:topArtist    lb:artist1, lb:artist2 .        

      lb:user2   foaf:knows      lb:user5, lb:user6 ;

                 foaf:age        40 ;

                 lb:listenedTo   lb:track1, lb:track2, lb:track3 ;  

                 lb:topArtist    lb:artist2, lb:artist4 .        

      lb:user3   foaf:knows      lb:user5, lb:bob, lb:user6 ;

                 foaf:age        19 ;

                 lb:listenedTo   lb:track2, lb:track3, lb:track4 ;

                 lb:topArtist    lb:artist2, lb:artist3 .      

      lb:user4   lb:listenedTo   lb:track2, lb:track3, lb:track4 ;

                 foaf:age        61 ;

                 lb:topArtist    lb:artist3, lb:artist4, lb:artist5 .     

      lb:user5   foaf:knows      lb:user7 ;

                 foaf:age        23 ;

                 lb:topArtist    lb:artist1, lb:artist3 .

       

       

      and i want to Find all pairs of distinct users that have a common friend.

      i wrote a query like this:

       

       

      PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

      prefix foaf: <http://xmlns.com/foaf/0.1/>

      prefix lb:   <http://example.org/lastfm/>

       

      select distinct ?user1 distinct ?user2

      where

      {

      (?user (foaf:knows)+ ?x) as ?user1.

      (?user (foaf:knows)+ ?y) as ?user2.

      filter(?x=?y)

      }

       

       

      but i get error, i know that my query has a lot of problems, would you please rewrite it for me?

       

       

      best,

      david