问题描述
对于我在 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)