我是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> ...
")" ...
"=" ...
"!=" ...
">" ...
"<" ...
"<=" ...
">=" ...
"||" ...
"&&" ...
"+" ...
"-" ...
"*" ...
"/" ...
但是这个错误:
{{1}}
我知道我的查询有很多问题,请你帮我改写一下?
答案 0 :(得分: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
作为?user
的绑定? filter (?user != lb:bob)
会阻止它。