在下面的查询中,我试图获取包含超过 3 个对象的谓词 sctap:提到的所有条目的列表。但是,我不断收到此搜索的格式错误的查询错误。有人看到我的查询有什么问题吗?
谢谢
SELECT ?s
WHERE {
?s sctap:mentionedBy ?o
FILTER (count(?o) > 3)
}
Run Code Online (Sandbox Code Playgroud)
sparql 错误说:“聚合表达式不合法”。我不确定这意味着什么。
Does anyone see anything wrong with my query?
Sure. Just like the error message says, you're using an aggregate expression (count(?o)) where one isn't legal. You can see in the table of contents of SPARQL 1.1 Query Language what things are filter functions that you can use in a filter, and what things are aggregates, and where you can use each. You can also try parsing queries at sparql.org's query validator. For your query, it will give you the line and column numbers where something went wrong. It's at count(?o).
In this case, you're trying to count the number of ?o values for each s, which means that you need to group by ?s, and that your filter will need to be father out. E.g.,
select ?s where {
?s sctap:mentionedBy ?o
}
group by ?s
having (count(?o) > 3)
Run Code Online (Sandbox Code Playgroud)
在这种情况下不太可能有所作为,但您可能只想计算?o 的不同值,因此您还可以考虑:
select ?s where {
?s sctap:mentionedBy ?o
}
group by ?s
having (count(distinct ?o) > 3)
Run Code Online (Sandbox Code Playgroud)