How do you use custom functions in fuseki?

I have a Fuseki endpoint running on some kind of server. I would like to pass custom functions using the Jena com.hp.hpl.jena.sparql.function library. Sorry, I get an error:

 URI <java:path.to.functions.halfString> has no registered function factory 

I have definitely added a class (the jar containing the file) to the class path, and I can access this class from other applications that use this class on this server.

The example I'm trying to apply now is some function that takes an object of all triples in a graph and returns the first half of each object.

As a reference, I added a function below:

 public class halfString extends FunctionBase1 { public halfString() { super() ; } public NodeValue exec(NodeValue nv1) { if (!nv1.isString()) { return nv1; } String hey = nv1.toString(); int mid = hey.length() / 2; String nay = hey.substring(0, mid); return NodeValue.makeString(nay); } } 

Here is the SPARQL query that I used:

 PREFIX f: <path.to.functions.> SELECT ?half ?s ?o ?g WHERE { ?s ?p ?o BIND (f:halfString(str(?s)) as ?half) } 

Running Fuseki (using the default configuration provided with fuseki):

 cd FUSEKI_HOME ./fuseki-server --mem /ds 
+4
source share
1 answer

The problem is not with Fuseki. The Java documentation states that when using the java command with the -jar option,

The JAR file is the source of all user classes, while other user classes ignore path parameters.

Just adding a jar file with user-defined functions to the CLASSPATH variable will not solve the problem, as this environment variable will be ignored. In addition, the use of the --classpath or -cp also ignored.

In order for Fuseki to load jar files, you need to add the location to the jar file with your user-defined functions to the Class-Path key in the fuseki-server.jar manifest file.

To do this, run:

 jar umf manifest-file fuseki-server.jar 

manifest file:

 Class-Path: path/to/functions/udf.jar 

As a reference, this describes the process of adding classes to the jar file class path in more detail.

+1
source

Source: https://habr.com/ru/post/1497329/


All Articles