Logarithm Function in SPARQL Query

Deadly 提交于 2019-12-21 20:07:28

问题


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

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

Example query that works:

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!


回答1:


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)
{
   ...
}


来源:https://stackoverflow.com/questions/16280758/logarithm-function-in-sparql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!