Sparql 组合任意属性路径、独立属性和计数

Sparql 组合任意属性路径、独立属性和计数,sparql,rdf,Sparql,Rdf,我有一个bellow SPARQL查询,希望得到所有唯一的?z值的?myInt之和。可以在SPARQL 1.1中表达这样的查询吗 SELECT ?z SUM(xsd:int(?myInt)) where{ ?x property1+ ?y ?x property2 ?k ?k property3 ?z ?x property4 ?myInt } group by distinct(?z) 我在Jena ARQ中运行此命令,并得到以下错误: Exception in thread "main"

我有一个bellow SPARQL查询,希望得到所有唯一的?z值的?myInt之和。可以在SPARQL 1.1中表达这样的查询吗

SELECT ?z SUM(xsd:int(?myInt)) 
where{
?x property1+ ?y
?x property2 ?k
?k property3 ?z
?x property4 ?myInt
} group by distinct(?z)
我在Jena ARQ中运行此命令,并得到以下错误:

Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " "sum" "SUM "" at line 1, column 11.
这里还有一个示例数据:

<http://a.com/6>  <http://aq.com/p>  <http://e.com/c5>.

<http://a.com/6>  <http://aq.com/q>  <http://a.com/5>.

<http://e.com/c5>  <http://aq.com/a>  <http://eoq.com/u1>.

<http://a.com/6>  <http://aq.com/num>  "10"^^<http://www.w3.org/2001/XMLSchema#integer> .

<http://a.com/5>  <http://aq.com/p>  <http://e.com/c4>.

<http://a.com/5>  <http://aq.com/q>  <http://a.com/4>.

<http://e.com/c4>  <http://aq.com/a>  <http://eoq.com/u1>.

<http://a.com/5>  <http://aq.com/num>  "10"^^<http://www.w3.org/2001/XMLSchema#integer>.
。
.
.
"10"^^ .
.
.
.
"10"^^.

不能直接选择表达式,必须将其作为变量选择。即,您需要执行以下操作:

SELECT ?z (SUM(xsd:int(?myInt)) as ?sum)
这是一个常见的错误,因为某些端点(例如,运行Virtuoso的公共DBpedia端点)确实允许使用原始表单,即使它不是合法的SPARQL


正如在评论中提到的,您应该按?0分组,而不是按不同的(?z)分组。

按不同的(?z)分组。
没有意义。您必须给出将对结果进行分组的变量。并且必须包装
SUM
类,以便知道变量名称,例如
(SUM(…)作为?SUM)
。顺便说一句,下一次最好有一个语法正确的SPARQL查询(缺少前缀和点,等等),这样人们就可以测试它,例如:这里:第一个三重模式的想法是什么?我的意思是,
?y
没有在任何地方使用,所以使用
?x property1?y
就足够了。