2

我正在将应用程序从 Sesame 移动到 Blazegraph,并且对以下查询有疑问。在 Sesame 上运行正常,但 Blazegraph 报告错误:

PREFIX schema: <http://schema.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?otherperson ?name (count(?name) as ?count) WHERE {
    ?article schema:mentions <http://trove.alveo.edu.au/name/8e0fd54e145f0d0643fec64731d488fa> .
    ?article schema:mentions ?otherperson .
    ?article dcterms:title ?articletitle .
    ?otherperson foaf:name ?name .
  filter (<http://trove.alveo.edu.au/name/8e0fd54e145f0d0643fec64731d488fa> != ?otherperson)
} group by ?name
order by desc(?count)
    LIMIT 50

Blazegraph 错误是:

java.util.concurrent.ExecutionException: org.openrdf.query.MalformedQueryException: Bad aggregate

这是 Blazegraph 的 Ubuntu 安装:

Build Version=2.0.0  
Build Git Commit=516e5a7014af1fbe378772c02d51ba1046f53e08

我该如何解决这个问题?

4

2 回答 2

1

我可以在 Blazegraph 上重现错误。这显然是一个问题group by。它适用于:

group by ?name ?otherperson
于 2017-03-18T23:51:16.387 回答
1

根据SPARQL 1.1 规范

在聚合查询和子查询中,出现在查询模式中但不在 GROUP BY 子句中的变量只有在聚合后才能在选择表达式中投影或使用。

可能是 Sesame 实现扩展了 SPARQL 1.1 规范以允许在投影子句中使用变量,这些变量在 group by 中未提及。

但通常您需要在 select 和 group by 子句中指定所有变量:

PREFIX schema: <http://schema.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?otherperson ?name (count(?name) as ?count) WHERE {
    ?article schema:mentions <http://trove.alveo.edu.au/name/8e0fd54e145f0d0643fec64731d488fa> .
    ?article schema:mentions ?otherperson .
    ?article dcterms:title ?articletitle .
    ?otherperson foaf:name ?name .
    filter (<http://trove.alveo.edu.au/name/8e0fd54e145f0d0643fec64731d488fa> != ?otherperson)
}
group by ?otherperson ?name
order by desc(?count)
LIMIT 50

或使用样本聚合:

PREFIX schema: <http://schema.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT (sample(?otherperson) as ?otherperson) ?name (count(?name) as ?count) WHERE {
    ?article schema:mentions <http://trove.alveo.edu.au/name/8e0fd54e145f0d0643fec64731d488fa> .
    ?article schema:mentions ?otherperson .
    ?article dcterms:title ?articletitle .
    ?otherperson foaf:name ?name .
    filter (<http://trove.alveo.edu.au/name/8e0fd54e145f0d0643fec64731d488fa> != ?otherperson)
}
group by ?name
order by desc(?count)
LIMIT 50
于 2017-03-28T06:35:36.713 回答