[英]SPARQL ranking on two predicates
Is it possible to create a SPARQL query that produces a result with the ranking based on two predicates? 是否可以创建一个SPARQL查询,该查询根据两个谓词生成具有排名的结果? I have searched for similar queries the closest solution I could find is given in this thread .
我已经搜索了类似的查询,该线程给出了我能找到的最接近的解决方案。 That solution gave me a timeout since I have about 600 triples so an efficient solution will be greatly appreciated.
该解决方案给了我一个超时,因为我有大约600个三元组,因此非常感谢一个有效的解决方案。 Consider the RDF below:
考虑下面的RDF:
@prefix : <http://example.org#> .
:A :groupid 119;
:date 2018-04-01.
:B :groupid 119 ;
:date 2018-03-01.
:C :groupid 119 ;
:date 2018-05-01.
:D :groupid 120 ;
:date 2018-02-01.
:E :groupid 120 ;
:date 2018-03-01.
I would like to get the following result: 我想得到以下结果:
| id | date |ranking |
==============================
| 119 | 2018-03-01 | 1 |
| 119 | 2018-04-01 | 2 |
| 119 | 2018-05-01 | 3 |
| 120 | 2018-02-01 | 1 |
| 120 | 2018-03-01 | 2 |
--------------------------------
As answered by AKSW, this script works perfectly: 正如AKSW回答的那样,此脚本可以完美运行:
PREFIX : <http://example.org#>
SELECT ?id ?date (COUNT(*) as ?ranking)
{
?x :groupid ?id ; :date ?date .
?y :groupid ?id ; :date ?date2 .
filter(?date2 <= ?date)
}
GROUP BY ?id ?date
ORDER BY ?id ?date ?ranking
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.