在 WHERE 子句 SPARQL 查询中对主题执行 DISTINCT
Doing DISTINCT on a subject in WHERE clause SPARQL query
我的数据模式如下:
<user> <:bought> <book>
我正在尝试编写推荐查询以向用户推荐新书。例如。如果用户 u_a
购买了书籍 b_1
和 b_2
。我找到所有购买了 b_1
和 b_2
的用户(u_a
除外),以及其他用户购买了其他书籍(b_1
和 b_2
除外) .
SELECT ?otherbooks (COUNT(*) AS ?t)
FROM <https://book_store1>
WHERE {
<https://book_store1/userId/1495865> <https://book_store1/bought> ?booksbought .
FILTER (?user != <https://book_store1/userId/1495865>)
?user <https://book_store1/bought> ?booksbought .
FILTER (?otherbooks != ?booksbought)
?user <https://book_store1/bought> ?otherbooks .
}
GROUP BY ?otherbooks
ORDER BY DESC (?t)
LIMIT 10
在 WHERE
子句的第 3 行,即 ?user <https://book_store1/bought> ?booksbought .
,我想做 DISTINCT
用户,即 u_b
和 u_c
可能同时购买了 b_1
和 b_2
。所以,我想在后续的 WHERE 子句
中将单个值作为 u_b
和 u_c
分别作为 ?user
传递
调整您的计数以查看唯一身份用户,如下所示:
SELECT ?otherbooks (COUNT(DISTINCT ?user) AS ?t)
我的数据模式如下:
<user> <:bought> <book>
我正在尝试编写推荐查询以向用户推荐新书。例如。如果用户 u_a
购买了书籍 b_1
和 b_2
。我找到所有购买了 b_1
和 b_2
的用户(u_a
除外),以及其他用户购买了其他书籍(b_1
和 b_2
除外) .
SELECT ?otherbooks (COUNT(*) AS ?t)
FROM <https://book_store1>
WHERE {
<https://book_store1/userId/1495865> <https://book_store1/bought> ?booksbought .
FILTER (?user != <https://book_store1/userId/1495865>)
?user <https://book_store1/bought> ?booksbought .
FILTER (?otherbooks != ?booksbought)
?user <https://book_store1/bought> ?otherbooks .
}
GROUP BY ?otherbooks
ORDER BY DESC (?t)
LIMIT 10
在 WHERE
子句的第 3 行,即 ?user <https://book_store1/bought> ?booksbought .
,我想做 DISTINCT
用户,即 u_b
和 u_c
可能同时购买了 b_1
和 b_2
。所以,我想在后续的 WHERE 子句
u_b
和 u_c
分别作为 ?user
传递
调整您的计数以查看唯一身份用户,如下所示:
SELECT ?otherbooks (COUNT(DISTINCT ?user) AS ?t)