是否可以创建一个SPARQL查询,该查询根据两个谓词生成排名结果?我搜索了类似的查询,我可以找到最近的解决方案thread。这个解决方案给了我超时,因为我有大约600三倍,所以一个有效的解决方案将非常感激。考虑下面的RDF:
const items = {
"questionlist": [{
"question": "Test question 1",
"option1": "Answer1A",
"option2": "Answer1B",
"option3": "Answer1C"
},
{
"question": "Test question 2",
"option1": "Answer2A",
"option2": "Answer2B",
"option3": "Answer2C"
},
{
"question": "Test question 3",
"option1": "Answer3A",
"option2": "Answer3B",
"option3": "Answer3C"
},
{
"question": "Test question 4",
"option1": "Answer3A",
"option2": "Answer3B",
"option3": "Answer3C"
},
{
"question": "Test question 5",
"option1": "Answer3A",
"option2": "Answer3B",
"option3": "Answer3C"
},
{
"question": "Test question 6",
"option1": "Answer3A",
"option2": "Answer3B",
"option3": "Answer3C"
},
{
"question": "Test question 7",
"option1": "Answer3A",
"option2": "Answer3B",
"option3": "Answer3C"
},
{
"question": "Test question 8",
"option1": "Answer3A",
"option2": "Answer3B",
"option3": "Answer3C"
}
]
}
function random_item(questions, n) {
var arr = [];
for (let i = 0; i < n; i++) {
arr.push(questions[Math.floor(Math.random() * questions.length)])
}
return arr
}
console.log(random_item(items.questionlist, 2))
我想得到以下结果:
@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.
答案 0 :(得分:0)
正如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