In case someone is interested, here is how I implemented it:
public class LevenshteinFilter extends FunctionBase2 { public NodeValue exec(NodeValue value1, NodeValue value2){ int i = StringUtils.getLevenshteinDistance(value1.asString(), value2.asString()); return NodeValue.makeInteger(i); } }
using:
String functionUri = "http://www.example.org/LevenshteinFunction"; FunctionRegistry.get().put(functionUri , LevenshteinFilter.class); String s = "..."; String sparql = "SELECT ?x WHERE { ?xa Something . " + "?x hasString ?str . " + "FILTER(<"+functionUri +">(?str, \"" + s + "\") < 5) }"; QueryExecution qexec = QueryExecutionFactory.create(sparql, model); ResultSet rs = qexec.execSelect(); while(rs.hasNext()){ ... }
source share