SPARQL查询中的对数函数 [英] Logarithm Function in SPARQL Query

查看:92
本文介绍了SPARQL查询中的对数函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个SPARQL查询,该查询对返回的结果执行对数函数.我已经在Java程序中实现了Jena SPARQL引擎,但只能找到以下可用功能:

I am trying to create a SPARQL query that performs the logarithm function on the returned results. I have implemented the Jena SPARQL engine in my java program, but have only been able to find these available functions : http://jena.sourceforge.net/ARQ/library-function.html

有人知道采用SPARQL返回变量的对数(最好是自然对数)的方法吗?

Does anybody know of a way to take the logarithm (preferably the natural log) of a SPARQL return variable?

有效的示例查询:

SELECT DISTINCT ((?Transactions_Num) AS ?BusinessValue) 
WHERE {{?BusinessProcess relation:Transactions_Num ?Transactions_Num ;} }

我要工作的查询示例(尽管当前不运行):

Example of query that I want to work (though currently does not):

SELECT DISTINCT (LOG(?Transactions_Num) AS ?BusinessValue) 
WHERE {{?BusinessProcess relation:Transactions_Num ?Transactions_Num ;} }

非常感谢您的提前帮助!

Thanks you very much for the help in advance!

推荐答案

日志不属于标准或非常容易编写您的自己的.

Log isn't part of the standard or ARQ's additions, however it's very easy to write your own.

package app;

public class log extends FunctionBase1
{
    public log() { super() ; }

    public NodeValue exec(NodeValue v)
    {
        return Math.log(v.getDouble());
    }
}

最简单的注册方法如下:

The easiest way to register it is like this:

FunctionRegistry.get().put("http://example.org/function#log", log.class) ;

然后您可以像这样使用它:

You can then use it like this:

PREFIX myfun: <http://example.org/function#>
SELECT DISTINCT (myfun:log(?Transactions_Num) AS ?BusinessValue)
{
   ...
}

这篇关于SPARQL查询中的对数函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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