对WHERE子句SPARQL查询中的主题执行DISTINCT

时间:2019-08-07 18:05:11

标签: sparql rdf

我的数据模式如下: <user> <:bought> <book>

我正在尝试编写一个向用户推荐新书的推荐查询。例如。如果用户u_a购买了书籍b_1b_2。我发现所有购买u_ab_1的用户(除了b_2之外,其他用户也购买了其他图书(b_1b_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子句的第三行,即?user <https://book_store1/bought> ?booksbought .,我想做DISTINCT个用户,即u_bu_c可能都购买了{{1 }}和b_1。因此,我想在后续的WHERE子句中将单个值分别作为b_2u_b传递为u_c

1 个答案:

答案 0 :(得分:0)

调整您的人数以查看唯一身份用户,例如:

SELECT ?otherbooks (COUNT(DISTINCT ?user) AS ?t)