Java Examples for org.apache.lucene.util.automaton.BasicOperations

The following java examples will help you to understand the usage of org.apache.lucene.util.automaton.BasicOperations. These source code samples are taken from different open source projects.

Example 1
Project: solrcene-master  File: FuzzyTermsEnum.java View source code
/** initialize levenshtein DFAs up to maxDistance, if possible */
private void initAutomata(int maxDistance) {
    if (runAutomata == null && maxDistance <= LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE) {
        LevenshteinAutomata builder = new LevenshteinAutomata(UnicodeUtil.newString(termText, realPrefixLength, termText.length - realPrefixLength));
        final ByteRunAutomaton[] ra = new ByteRunAutomaton[maxDistance + 1];
        for (int i = 0; i <= maxDistance; i++) {
            Automaton a = builder.toAutomaton(i);
            // constant prefix
            if (realPrefixLength > 0) {
                Automaton prefix = BasicAutomata.makeString(UnicodeUtil.newString(termText, 0, realPrefixLength));
                a = BasicOperations.concatenate(prefix, a);
            }
            ra[i] = new ByteRunAutomaton(a);
        }
        runAutomata = Arrays.asList(ra);
    }
}
Example 2
Project: heliosearch-master  File: AnalyzingSuggester.java View source code
final Automaton toLookupAutomaton(final CharSequence key) throws IOException {
    // TODO: is there a Reader from a CharSequence?
    // Turn tokenstream into automaton:
    Automaton automaton = null;
    try (TokenStream ts = queryAnalyzer.tokenStream("", key.toString())) {
        automaton = (getTokenStreamToAutomaton()).toAutomaton(ts);
    }
    // TODO: we could use the end offset to "guess"
    // whether the final token was a partial token; this
    // would only be a heuristic ... but maybe an OK one.
    // This way we could eg differentiate "net" from "net ",
    // which we can't today...
    replaceSep(automaton);
    // TODO: we can optimize this somewhat by determinizing
    // while we convert
    BasicOperations.determinize(automaton);
    return automaton;
}
Example 3
Project: solr-analytics-master  File: FuzzyTermsEnum.java View source code
/** 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);
        for (int i = runAutomata.size(); i <= maxDistance; i++) {
            Automaton a = builder.toAutomaton(i);
            // constant prefix
            if (realPrefixLength > 0) {
                Automaton prefix = BasicAutomata.makeString(UnicodeUtil.newString(termText, 0, realPrefixLength));
                a = BasicOperations.concatenate(prefix, a);
            }
            runAutomata.add(new CompiledAutomaton(a, true, false));
        }
    }
    return runAutomata;
}
Example 4
Project: siren-master  File: NodeAutomatonQuery.java View source code
@Override
public boolean equals(final Object obj) {
    if (this == obj)
        return true;
    if (!super.equals(obj))
        return false;
    if (this.getClass() != obj.getClass())
        return false;
    final NodeAutomatonQuery other = (NodeAutomatonQuery) obj;
    if (automaton == null) {
        if (other.automaton != null)
            return false;
    } else if (!BasicOperations.sameLanguage(automaton, other.automaton))
        return false;
    if (term == null) {
        if (other.term != null)
            return false;
    } else if (!term.equals(other.term))
        return false;
    return true;
}
Example 5
Project: ClusterBasedRelevanceFeedback-master  File: FuzzyTermsEnum.java View source code
/** initialize levenshtein DFAs up to maxDistance, if possible */
private List<CompiledAutomaton> initAutomata(int maxDistance) {
    final List<CompiledAutomaton> runAutomata = dfaAtt.automata();
    if (runAutomata.size() <= maxDistance && maxDistance <= LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE) {
        LevenshteinAutomata builder = new LevenshteinAutomata(UnicodeUtil.newString(termText, realPrefixLength, termText.length - realPrefixLength));
        for (int i = runAutomata.size(); i <= maxDistance; i++) {
            Automaton a = builder.toAutomaton(i);
            // constant prefix
            if (realPrefixLength > 0) {
                Automaton prefix = BasicAutomata.makeString(UnicodeUtil.newString(termText, 0, realPrefixLength));
                a = BasicOperations.concatenate(prefix, a);
            }
            runAutomata.add(new CompiledAutomaton(a, true));
        }
    }
    return runAutomata;
}
Example 6
Project: quickdialer-master  File: FuzzyTermsEnum.java View source code
/** 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);
        for (int i = runAutomata.size(); i <= maxDistance; i++) {
            Automaton a = builder.toAutomaton(i);
            // constant prefix
            if (realPrefixLength > 0) {
                Automaton prefix = BasicAutomata.makeString(UnicodeUtil.newString(termText, 0, realPrefixLength));
                a = BasicOperations.concatenate(prefix, a);
            }
            runAutomata.add(new CompiledAutomaton(a, true, false));
        }
    }
    return runAutomata;
}