【问题标题】:Aggregate Function AVG in GraphDBGraphDB 中的聚合函数 AVG
【发布时间】:2021-01-12 09:49:47
【问题描述】:

对于我在 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

有什么解决方案可以将实际平均值作为输出?

【问题讨论】:

  • 查询看起来正确。空的意思是根本没有结果? select ?s ?TP where { ?s a :MachinestatusID . ?s :hastotalpower_Kalender ?TP. ?s &lt;http://www.BLB.de/Ontologie#Is_switched_on_Kalender&gt; ?K } 返回什么?
  • 这里是选择查询的第一个值: s TP K BLB.de/Daten/Anlagenstatus/id/1 4186 1 BLB.de/Daten/Anlagenstatus/id/2 4183 1 BLB.de/Daten/Anlagenstatus/id/3 4177 1 BLB.de/Daten/Anlagenstatus/id/4 4171 1 BLB.de/Daten/Anlagenstatus/id/5 4167 1 我只使用? K 简化查询。在原版中,我使用了另一种模式来订购 ID。确切地说,AVG 根本不显示任何内容。像这样:s AP BLB.de/Daten/Anlagenstatus/id/1 BLB.de/Daten/Anlagenstatus/id/2
  • 只是为了澄清,“没有”对我来说是“根本没有行”。我对AP专栏没有任何意义。 ?TP 值的数据类型是什么?它是数字数据类型吗?你能试试(AVG(xsd:integer(?TP)) as ?AP)吗?
  • 非常感谢!问题通过扩展解决。似乎我无法将其标记为已回答,因为它已被评论或我是新贡献者。
  • hm,但这让我想到了一个问题:1)你的数据中文字的数据类型是什么?或 2) 是否存在一些不存在此类 ?TP 的数据?因为否则,不需要显式转换

标签: sparql aggregate-functions graph-databases semantic-web graphdb


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-16
    • 2020-07-10
    • 1970-01-01
    相关资源
    最近更新 更多