На случай, если кому-то интересно, я так и реализовал:
public class LevenshteinFilter extends FunctionBase2
{
public NodeValue exec(NodeValue value1, NodeValue value2){
int i = StringUtils.getLevenshteinDistance(value1.asString(), value2.asString());
return NodeValue.makeInteger(i);
}
}
использование:
String functionUri = "http://www.example.org/LevenshteinFunction";
FunctionRegistry.get().put(functionUri , LevenshteinFilter.class);
String s = "...";
String sparql = "SELECT ?x WHERE { ?x a Something . " +
"?x hasString ?str . " +
"FILTER(<"+functionUri +">(?str, \"" + s + "\") < 5) }";
QueryExecution qexec = QueryExecutionFactory.create(sparql, model);
ResultSet rs = qexec.execSelect();
while(rs.hasNext()){
...
}