如何使用python在Sparql中执行算术运算? [英] How to perform arithmetic operations in Sparql with python?

查看:111
本文介绍了如何使用python在Sparql中执行算术运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个公共领域的计算器,其代码可从以下网址获取: https://github.com/okfn/pdcalc/blob/master/pd/map.rdf

I am writting a public domain calculator, whose code is available at: https://github.com/okfn/pdcalc/blob/master/pd/map.rdf

由于sparql 1.0遇到问题,该代码当前无法正确确定作品的公共领域状态:似乎无法对日期执行算术运算,这意味着计算器无法确定例如作品在作者去世70年后是否已经出版. 不幸的是,标准python的rdf库都尚未实现对sparql 1.1的支持. 因此,我想知道是否有人对如何克服此限制有任何建议,或者是否知道任何支持sparql更好的python库?

The code is currently unable to properly determine the public domain status of a work because of an issue that has been encountered with sparql 1.0: it does not appear to be possible to perform arithmetic operation on dates, which means that the calculator cannot determine e.g. whether or not the work has been published 70 years after the death of the author. Unfortunately, none of the standard python's rdf libraries have yet implemented a support for sparql 1.1 Hence, I was wondering whether anyone had any suggestion as to how to overcome this limitation, or maybe knows of any python library with a better support of sparql ?

期待您的退款!

推荐答案

默认情况下,即使SPARQL 1.1也不支持对日期进行算术运算.请参阅关于 SPARQL运算符映射的部分:算术运算仅在数字数据类型上定义

Even SPARQL 1.1 does not support arithmetic operations on dates by default. See the section on SPARQL operator mapping: arithmetic operations are only defined on numeric datatypes.

可能有一些SPARQL 1.1实现为此目的提供了扩展,但是我现在还没有立即意识到具有此内置功能的任何实现,当然不是在Python中.

There may be some SPARQL 1.1 implementations that offer an extension for this purpose, but I'm not immediately aware of any that have this built-in now, certainly not in Python.

您最好的选择是与您选择的SPARQL引擎的开发人员联系,并诱使他们实施这样的扩展,或者当然也可以自行开发.

Your best bet is to get in touch with developers of the SPARQL engine of your choice and pester them to implement such an extension, or alternatively roll your own of course.

作为一种解决方法,大多数SPARQL引擎(甚至是1.0)都支持对日期进行比较操作,因此您可以执行诸如排序和比较之类的操作,但是您必须对查询结果进行一些自定义的后处理.

As a workaround, most SPARQL engines (even 1.0) do support compare operations on dates, so you can do things like sorting and comparing, but you'll have to do some custom post-processing on your query result.

更新我只是意识到我忽略了一些非常重要的事情:SPARQL 1.1当然支持诸如year()month()等的函数,这些函数返回日期时间值的年和月组成部分作为一个整数,可以想像它可以用来对日期进行回旋算术.

Update I just realized I overlooked something rather important: SPARQL 1.1 of course does support functions like year(), month() etc, which return the year and month-component of a datetime-value as an integer, and which you could conceivably use to do a roundabout arithmetic on dates.

这篇关于如何使用python在Sparql中执行算术运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆