3

我是 SPARQL 的初学者,所以如果你能帮助我,那就太好了。. 我有一个这样的 RDF 文档:

  @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 .

并且我想找到所有可以lb:bob通过foaf:knows最多关注 3 次并且至少听过两首曲目的用户。我写了一个这样的查询:

  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 ?user
  where
  {
   lb:bob foaf:knows | foaf:knows/foaf:knows| foaf:knows/foaf:knows/foaf:knows ?user.
    ?user lb:listenedTo ?tracks
     minus{lb:bob lb:listenedTo ?track}
      filter (?tracks count(*)>=2)
  }

但是这个错误:

Encountered " "count" "count "" at line 12, column 23. Was expecting one of:
 "not" ...
 "in" ...
 <INTEGER_POSITIVE> ...
 <DECIMAL_POSITIVE> ...
 <DOUBLE_POSITIVE> ...
 <INTEGER_NEGATIVE> ...
 <DECIMAL_NEGATIVE> ...
 <DOUBLE_NEGATIVE> ...
 ")" ...
 "=" ...
 "!=" ...
 ">" ...
 "<" ...
 "<=" ...
 ">=" ...
 "||" ...
 "&&" ...
 "+" ...
 "-" ...
 "*" ...
 "/" ...

我知道我的查询有很多问题,请您帮我重写一下好吗?

4

1 回答 1

5

怎么样:

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 ?user
where
{
  lb:bob foaf:knows | foaf:knows/foaf:knows| foaf:knows/foaf:knows/foaf:knows ?user.
  ?user lb:listenedTo ?tracks
}
group by ?user
having (count(?tracks) > 2)

你有minus我不确定的原始查询。您是否尝试将其lb:bob作为绑定删除?userfilter (?user != lb:bob)会阻止的。

于 2013-07-11T13:55:49.047 回答