new LevenshteinAutomata(UnicodeUtil.newString(termText, realPrefixLength, termText.length - realPrefixLength), transpositions); Automaton a = builder.toAutomaton(i, prefix); prevAutomata[i] = new CompiledAutomaton(a, true, false);
/** * Create a new LevenshteinAutomata for some input String. * Optionally count transpositions as a primitive edit. */ public LevenshteinAutomata(String input, boolean withTranspositions) { this(codePoints(input), Character.MAX_CODE_POINT, withTranspositions); }
/** * Compute a DFA that accepts all strings within an edit distance of <code>n</code>. * <p> * All automata have the following properties: * <ul> * <li>They are deterministic (DFA). * <li>There are no transitions to dead states. * <li>They are not minimal (some transitions could be combined). * </ul> */ public Automaton toAutomaton(int n) { return toAutomaton(n, ""); }
final int ch = alphabet[x]; final int cvec = getVector(ch, xpos, end); int dest = description.transition(k, xpos, cvec); if (dest >= 0) {
/** * Compute a DFA that accepts all strings within an edit distance of <code>n</code>. * <p> * All automata have the following properties: * <ul> * <li>They are deterministic (DFA). * <li>There are no transitions to dead states. * <li>They are not minimal (some transitions could be combined). * </ul> */ public Automaton toAutomaton(int n) { return toAutomaton(n, ""); }
final int ch = alphabet[x]; final int cvec = getVector(ch, xpos, end); int dest = description.transition(k, xpos, cvec); if (dest >= 0) {
LevenshteinAutomata lev = new LevenshteinAutomata( ints, unicodeAware ? Character.MAX_CODE_POINT : 255, transpositions); subs.add(lev.toAutomaton(maxEdits, UnicodeUtil.newString(string.ints, string.offset, nonFuzzyPrefix)));
/** * Compute a DFA that accepts all strings within an edit distance of <code>n</code>. * <p> * All automata have the following properties: * <ul> * <li>They are deterministic (DFA). * <li>There are no transitions to dead states. * <li>They are not minimal (some transitions could be combined). * </ul> */ public Automaton toAutomaton(int n) { return toAutomaton(n, ""); }
/** * Create a new LevenshteinAutomata for some input String. * Optionally count transpositions as a primitive edit. */ public LevenshteinAutomata(String input, boolean withTranspositions) { this(codePoints(input), Character.MAX_CODE_POINT, withTranspositions); }
final int ch = alphabet[x]; final int cvec = getVector(ch, xpos, end); int dest = description.transition(k, xpos, cvec); if (dest >= 0) {
@Override public Automaton getAutomaton(Options schema) { Properties properties = schema.getProperties(field); String message; Type fieldType = properties != null ? properties.getType() : Type.text; if (fieldType == Type.string || fieldType == Type.text) { String analyzedValue = analyze(field, value, schema.analyzer); LevenshteinAutomata levenshteinAutomata = new LevenshteinAutomata(analyzedValue, transpositions); return levenshteinAutomata.toAutomaton(maxEdits); } message = String.format("Fuzzy queries cannot be supported for field type %s", fieldType); throw new UnsupportedOperationException(message); }
/** * Compute a DFA that accepts all strings within an edit distance of <code>n</code>. * <p> * All automata have the following properties: * <ul> * <li>They are deterministic (DFA). * <li>There are no transitions to dead states. * <li>They are not minimal (some transitions could be combined). * </ul> */ public Automaton toAutomaton(int n) { return toAutomaton(n, ""); }
/** * Create a new LevenshteinAutomata for some input String. * Optionally count transpositions as a primitive edit. */ public LevenshteinAutomata(String input, boolean withTranspositions) { this(codePoints(input), Character.MAX_CODE_POINT, withTranspositions); }
final int ch = alphabet[x]; final int cvec = getVector(ch, xpos, end); int dest = description.transition(k, xpos, cvec); if (dest >= 0) {
/** initialize levenshtein DFAs up to maxDistance, if possible */ private List<CompiledAutomaton> initAutomata(int maxDistance) { final List<CompiledAutomaton> runAutomata = dfaAtt.automata(); //System.out.println("cached automata size: " + runAutomata.size()); if (runAutomata.size() <= maxDistance && maxDistance <= LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE) { LevenshteinAutomata builder = new LevenshteinAutomata(UnicodeUtil.newString(termText, realPrefixLength, termText.length - realPrefixLength), transpositions); String prefix = UnicodeUtil.newString(termText, 0, realPrefixLength); for (int i = runAutomata.size(); i <= maxDistance; i++) { Automaton a = builder.toAutomaton(i, prefix); //System.out.println("compute automaton n=" + i); runAutomata.add(new CompiledAutomaton(a, true, false)); } } return runAutomata; }
LevenshteinAutomata builder = new LevenshteinAutomata(s); Automaton automata = builder.toAutomaton(n); boolean result1 = BasicOperations.run(automata, "foo"); boolean result2 = BasicOperations.run(automata, "bar");
/** * Create a new LevenshteinAutomata for some input String. * Optionally count transpositions as a primitive edit. */ public LevenshteinAutomata(String input, boolean withTranspositions) { this(codePoints(input), Character.MAX_CODE_POINT, withTranspositions); }
/** initialize levenshtein DFAs up to maxDistance, if possible */ private List<CompiledAutomaton> initAutomata(int maxDistance) { final List<CompiledAutomaton> runAutomata = dfaAtt.automata(); //System.out.println("cached automata size: " + runAutomata.size()); if (runAutomata.size() <= maxDistance && maxDistance <= LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE) { LevenshteinAutomata builder = new LevenshteinAutomata(UnicodeUtil.newString(termText, realPrefixLength, termText.length - realPrefixLength), transpositions); String prefix = UnicodeUtil.newString(termText, 0, realPrefixLength); for (int i = runAutomata.size(); i <= maxDistance; i++) { Automaton a = builder.toAutomaton(i, prefix); //System.out.println("compute automaton n=" + i); runAutomata.add(new CompiledAutomaton(a, true, false)); } } return runAutomata; }
LevenshteinAutomata lev = new LevenshteinAutomata( ints, unicodeAware ? Character.MAX_CODE_POINT : 255, transpositions); subs.add(lev.toAutomaton(maxEdits, UnicodeUtil.newString(string.ints, string.offset, nonFuzzyPrefix)));
LevenshteinAutomata lev = new LevenshteinAutomata(ints, unicodeAware ? Character.MAX_CODE_POINT : 255, transpositions); subs.add(lev.toAutomaton(maxEdits, UnicodeUtil.newString(string.ints, string.offset, nonFuzzyPrefix)));