I'm not as familiar with the extension points of ARQ as I would like to be, but 
as I understand what you are doing, you are registering a new function with 
your _local_ registry, then firing a query at a _remote_ endpoint (which has a 
completely independent registry in a different JVM in a different process, 
potentially in a different _system_).

The query is getting interpreted and executed by that remote service, not 
locally. So you need to register the function _there_.

Take a look at this thread:

https://lists.apache.org/thread.html/1cda23332af4264883e88697d994605770edcde2f93ddea51240e4b8@%3Cusers.jena.apache.org%3E

It should get you started as to how to register extension functionality in 
Fuseki.


Adam Soroka

> On Dec 26, 2017, at 9:34 AM, Marc Agate <[email protected]> wrote:
> 
> Hi !
> 
> I successfully implemented sparql queries using custom ARQ functions
> using the following (custom function code):
> 
> ****************
> public class LevenshteinFilter extends FunctionBase2 {
> 
>     public LevenshteinFilter() { super() ; }
> 
>     public NodeValue exec(NodeValue value1, NodeValue value2){
>         LevenshteinDistance LD=new LevenshteinDistance();
>         int i = LD.apply(value1.asString(), value2.asString()); 
>         return NodeValue.makeInteger(i); 
>     }
> }
> ***************
> 
> it works fine when I query against a Model loaded from a turtle file,
> like this:
> 
> ***************
> InputStream input =
> QueryProcessor.class.getClassLoader().getResourceAsStream("full.ttl");
>             model =
> ModelFactory.createMemModelMaker().createModel("default");
>             model.read(input,null,"TURTLE"); // null base URI, since
> model URIs are absolute
>             input.close();
> ***************
> 
> with the query being sent like this :
> 
> ***************
> String functionUri = "http://www.example1.org/LevenshteinFunction";; 
>         FunctionRegistry.get().put(functionUri ,
> LevenshteinFilter.class);
> 
>         String s = "whatever you want";
>         String sparql = prefixes+" SELECT DISTINCT ?l WHERE { ?x
> rdfs:label ?l . " +  "FILTER(fct:LevenshteinFunction(?l, \"" + s + "\")
> < 4) }";                                              
>         Query query = QueryFactory.create(sparql);
>         QueryExecution qexec = QueryExecutionFactory.create(query,
> model); 
>         ResultSet rs = qexec.execSelect();
> ***************
> 
> However, if i use a working fuseki endpoint for the same dataset
> (full.ttl) like this :
> 
> ***************
> fusekiUrl="http://localhost:3030/ds/query";;
> ***************
> 
> sending the query like this (using
> QueryExecutionFactory.sparqlService(fusekiUrl,query) instead of
> QueryExecutionFactory.create(query,model) ):
> 
> ***************
> String functionUri = "http://www.example1.org/LevenshteinFunction";; 
>         FunctionRegistry.get().put(functionUri ,
> LevenshteinFilter.class);
> 
>         String s = "whatever you want";
>         String sparql = prefixes+" SELECT DISTINCT ?l WHERE { ?x
> rdfs:label ?l . " + "FILTER(fct:LevenshteinFunction(?l, \"" + s + "\")
> < 4) }";                                       
>         Query query = QueryFactory.create(sparql);
>         QueryExecution qexec =
> QueryExecutionFactory.sparqlService(fusekiUrl,query); 
>         ResultSet rs = qexec.execSelect();
> ***************
> 
> Then I don't get any results back. In both cases I printed out the
> FunctionRegistry and they contain exactly the same entries, especially
> :
> 
> key=http://www.example1.org/LevenshteinFunction value:
> org.apache.jena.sparql.function.FunctionFactoryAuto@5a45133e
> 
> Any clue ?
> 
> Thanks

Reply via email to