SPARQL 查询平均持续时间
如何在 SPARQL 中计算平均持续时间?我使用以 xsd:duration 表示的持续时间,例如“PT4H15M53S”^^xsd:duration 以下查询不返回任何内容:
SELECT (AVG(?Duration) AS ?avg)
WHERE {
?Time rdf:type tl:Interval ;
tl:duration ?Duration .
}
How is it possible to compute in SPARQL the average of time durations? I am using durations expressed in xsd:duration e.g., "PT4H15M53S"^^xsd:duration
The following query does not return anything:
SELECT (AVG(?Duration) AS ?avg)
WHERE {
?Time rdf:type tl:Interval ;
tl:duration ?Duration .
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能不是很干净,但如果您使用正则表达式提取持续时间的组成部分,它仍然与标准 SPARQL 兼容:
这会将持续时间转换为总秒数,然后您可以在您希望的任何计算中使用它,然后将其转换为以秒为单位的持续时间。
请注意,不会考虑基于月份的组件的持续时间,因为没有为该子集定义平均值(不能有小数月份)。换句话说,这仅对
xs:dayTimeDuration
的值有意义。It may not be very clean, but it is nonetheless compatible with standard SPARQL, if you use regular expressions to extract the components of the duration:
This converts the duration into the total number of seconds, which you can then use in any calculations you wish, and then convert that to duration in seconds.
Note that durations with month-based components will not be taken into account, since average is not defined for that subset (you cannot have fractional months). In other words, this only makes sense for values of
xs:dayTimeDuration
.