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