Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logarithm Function in SPARQL Query

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!

like image 740
BigDataBill Avatar asked Mar 01 '26 00:03

BigDataBill


1 Answers

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)
{
   ...
}
like image 180
user205512 Avatar answered Mar 04 '26 15:03

user205512



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!