2017-03-18 39 views
1

錯誤我只是在將應用程序從芝麻移動到Blazegraph並與以下查詢有問題。它的工作原理確定芝麻,但Blazegraph報告錯誤:彙總查詢導致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 

這是一個Ubuntu安裝Blazegraph的:

Build Version=2.0.0 
Build Git Commit=516e5a7014af1fbe378772c02d51ba1046f53e08 

如何解決這個問題?

回答

1

根據SPARQL 1.1 specification

In aggregate queries and sub-queries, variables that appear in the query pattern, but are not in the GROUP BY clause, can only be projected or used in select expressions if they are aggregated.

這也許,是芝麻實現擴展SPARQL 1.1規範允許在投影子句中的變量,它不是由組提及。

但通常你既需要在選擇和條款組指定的所有變量:

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 
1

我可以在Blazegraph上重現錯誤。這顯然是group by的問題。它適用於:

group by ?name ?otherperson