计算两个SPARQL xsd:dateTime之间差异的函数是什么?
我找到了对datediff的引用,但这不起作用.SPARQL中是否存在这样的内置函数,就像大多数其他查询语言一样?
Jos*_*lor 11
某些SPARQL引擎可能直接支持日期算法.例如,正如在这个answers.semanticweb.com问题和答案中提到的,Jena支持日期算术,你可以从另一个中减去一个日期并获得xsd:Duration.其他实现可以支持日期功能.例如,这个Virtuoso示例包括使用bif:datediff.但是,这些是扩展,并不保证在任何特定的SPARQL实现中都存在.
对于更便携,但可能效率更低的解决方案,您可以使用年份从日期时间中提取年份部分.例如,这可以让你做到
select ?age where {
bind( "1799-12-14"^^<http://www.w3.org/2001/XMLSchema#date> as ?death )
bind( "1732-02-22"^^<http://www.w3.org/2001/XMLSchema#date> as ?birth )
bind( year(?death)-year(?birth) as ?age )
}
Run Code Online (Sandbox Code Playgroud)
并得到结果
-------
| age |
=======
| 67 |
-------
Run Code Online (Sandbox Code Playgroud)
根据两个日期的月份和日期,这可能会被一个人关闭,但您可以通过使用月和日函数来解决此问题. 该线程描述了某种类型的实现.
小智 9
当我在搜索如何计算SPARQL中的年龄时,我发现了这篇文章.感谢Joshua Taylor提供了正确的提示.然而,我通过添加调整来改进代码段,因此如果该人在他们去世的那一年没有过生日,那么它不会被禁用一年.我认为对于那些在搜索主题时找到这篇文章的人可能会有所帮助,就像我做的那样:
select ?age where {
bind( "1799-12-14"^^<http://www.w3.org/2001/XMLSchema#date> as ?death )
bind( "1732-02-22"^^<http://www.w3.org/2001/XMLSchema#date> as ?birth )
bind( year(?death) - year(?birth) - if(month(?death)<month(?birth) || (month(?death)=month(?birth) && day(?death)<day(?birth)),1,0) as ?age )
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5419 次 |
| 最近记录: |