sparql 如何将子查询转换为另一个查询
sparql how to sub query into another query
我有这个数据
@prefix : <http://test.example/> .
:alice :likes :beethoven.
:alice :likes :verdi.
:sofia :likes :beethoven.
:sofia :likes :verdi.
:sofia :likes :rossini.
:ania :likes :verdi.
:ania :likes :beethoven.
:ania :likes :david.
:david :likes :ania.
:david :likes :beethoven.
:david :likes :verdi.
:antonino :likes :verdi.
:antonino :likes :mozart.
:weirdo :likes :katyperry.
:beethoven a :recommendable.
:verdi a :recommendable.
:rossini a :recommendable.
:katyperry a :recommendable.
:mozart a :recommendable.
然后我进行查询以获取与特定用户喜欢相同商品的用户
select ?anotherUser (COUNT(?anotherItem) as ?countOfItems) WHERE {
values ?user {:ania}
?anotherUser :likes ?anotherItem.
filter (?anotherUser != ?user)
filter exists {?user :likes ?anotherItem}
}group by ?anotherUser
order by desc(?countOfItems)
现在我想获取这些用户喜欢的项目(但当然没有他们与该特定用户共享的项目 (:ania
))
我知道我必须在另一个中包含一个查询,我自己尝试了很多但没有成功,你能帮忙吗?
now I want to get the items that these users like (but of course without the items that they share with that specific user (:ania))
I know I have to include a query inside the other, I tried a lot myself but no success, could you help please?
我认为要牢记的主要事情是子查询是最先评估的,即查询是从最内层开始评估的,到最外层。
所以下面的查询:
prefix : <http://test.example>
select distinct ?user ?anotherUser ?item WHERE {
?anotherUser :likes ?item.
filter not exists {?user :likes ?item}
{select ?user ?anotherUser where {
values ?user {:ania}
?anotherUser :likes ?anotherItem.
filter (?anotherUser != ?user)
filter exists {?user :likes ?anotherItem}
}}
}
将产生结果:
----------------------------------
| user | anotherUser | item |
==================================
| :ania | :sofia | :rossini |
| :ania | :antonino | :mozart |
| :ania | :david | :ania |
----------------------------------
你问的是哪个?
我有这个数据
@prefix : <http://test.example/> .
:alice :likes :beethoven.
:alice :likes :verdi.
:sofia :likes :beethoven.
:sofia :likes :verdi.
:sofia :likes :rossini.
:ania :likes :verdi.
:ania :likes :beethoven.
:ania :likes :david.
:david :likes :ania.
:david :likes :beethoven.
:david :likes :verdi.
:antonino :likes :verdi.
:antonino :likes :mozart.
:weirdo :likes :katyperry.
:beethoven a :recommendable.
:verdi a :recommendable.
:rossini a :recommendable.
:katyperry a :recommendable.
:mozart a :recommendable.
然后我进行查询以获取与特定用户喜欢相同商品的用户
select ?anotherUser (COUNT(?anotherItem) as ?countOfItems) WHERE {
values ?user {:ania}
?anotherUser :likes ?anotherItem.
filter (?anotherUser != ?user)
filter exists {?user :likes ?anotherItem}
}group by ?anotherUser
order by desc(?countOfItems)
现在我想获取这些用户喜欢的项目(但当然没有他们与该特定用户共享的项目 (:ania
))
我知道我必须在另一个中包含一个查询,我自己尝试了很多但没有成功,你能帮忙吗?
now I want to get the items that these users like (but of course without the items that they share with that specific user (:ania))
I know I have to include a query inside the other, I tried a lot myself but no success, could you help please?
我认为要牢记的主要事情是子查询是最先评估的,即查询是从最内层开始评估的,到最外层。
所以下面的查询:
prefix : <http://test.example>
select distinct ?user ?anotherUser ?item WHERE {
?anotherUser :likes ?item.
filter not exists {?user :likes ?item}
{select ?user ?anotherUser where {
values ?user {:ania}
?anotherUser :likes ?anotherItem.
filter (?anotherUser != ?user)
filter exists {?user :likes ?anotherItem}
}}
}
将产生结果:
----------------------------------
| user | anotherUser | item |
==================================
| :ania | :sofia | :rossini |
| :ania | :antonino | :mozart |
| :ania | :david | :ania |
----------------------------------
你问的是哪个?