GraphDB 中的聚合函数 AVG

问题描述

对于我在 GraphDB 9.4.1 中的项目,我使用 owl rl(优化)创建了一个存储库。

在我的数据中,我需要查询数据属性的平均值。当我按照 SPARQL 指令执行步骤时,结果为空。我使用了以下查询

PREFIX : <http://www.BLB.de/Ontologie#>
select ?s (AVG(?TP) as ?AP) where { 
?s a :MachinestatusID .
?s :hastotalpower_Kalender ?TP.
?s <http://www.BLB.de/Ontologie#Is_switched_on_Kalender> ?K
} Group by ?s ?K 

Result:

s                                                     AP
http://www.BLB.de/Daten/Anlagenstatus/id/1  
http://www.BLB.de/Daten/Anlagenstatus/id/2  
http://www.BLB.de/Daten/Anlagenstatus/id/3  

为了验证数据,我已经选择了没有聚合函数的数据。 Al ?TP 是 0 到 5000 之间的值。没有指定数据格式。 ?K 为 1 或 0。由于 GraphDB 文档支持 AVG 函数

s                                           TP      K
http://www.BLB.de/Daten/Anlagenstatus/id/1  4186    1
http://www.BLB.de/Daten/Anlagenstatus/id/2  4183    1
http://www.BLB.de/Daten/Anlagenstatus/id/3  4177    1
http://www.BLB.de/Daten/Anlagenstatus/id/4  4171    1

是否有任何解决方案可以将实际平均值作为输出

解决方法

?TP 的数据格式需要显式转换。将平均函数修改为以下解决了问题:

(AVG(xsd:integer(?TP)) as ?AP)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...