Java Code Examples for dk.brics.automaton.Automaton#run()

The following examples show how to use dk.brics.automaton.Automaton#run() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: imhotep   File: FlamdexUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static void cacheIntFieldRegex(String field, FlamdexReader reader, Automaton automaton, ThreadSafeBitSet ret) {
    try (final IntTermIterator iter = reader.getIntTermIterator(field);
         final DocIdStream dis = reader.getDocIdStream()) {
        while (iter.next()) {
            if (automaton.run(String.valueOf(iter.term()))) {
                dis.reset(iter);
                fillBitSet(dis, ret);
            }
        }
    }
}
 
Example 2
Source Project: imhotep   File: FlamdexUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static void cacheStringFieldRegex(String field, FlamdexReader reader, Automaton automaton, ThreadSafeBitSet ret) {
    try (final StringTermIterator iter = reader.getStringTermIterator(field);
         final DocIdStream dis = reader.getDocIdStream()) {
        while (iter.next()) {
            if (automaton.run(iter.term())) {
                dis.reset(iter);
                fillBitSet(dis, ret);
            }
        }
    }
}
 
Example 3
Source Project: imhotep   File: ImhotepLocalSession.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void regexRegroup(String field, String regex, int targetGroup, int negativeGroup, int positiveGroup) throws ImhotepOutOfMemoryException {
    if (getNumGroups() > 2) {
        throw new IllegalStateException("regexRegroup should be applied as a filter when you have only one group");
    }
    if (targetGroup == 0) {
        clearZeroDocBitsets();
    }
    docIdToGroup =
            GroupLookupFactory.resize(docIdToGroup,
                    Math.max(negativeGroup, positiveGroup),
                    memory);

    final FastBitSetPooler bitSetPooler = new ImhotepBitSetPooler(memory);
    final FastBitSet docRemapped;
    try {
        docRemapped = bitSetPooler.create(numDocs);
    } catch (FlamdexOutOfMemoryException e) {
        throw new ImhotepOutOfMemoryException(e);
    }
    try {
        try (
            final StringTermIterator iter = flamdexReader.getStringTermIterator(field);
            final DocIdStream docIdStream = flamdexReader.getDocIdStream()
        ) {
            final Automaton automaton = new RegExp(regex).toAutomaton();

            while (iter.next()) {
                final String term = iter.term();

                if (automaton.run(term)) {
                    docIdStream.reset(iter);
                    remapPositiveDocs(docIdStream, docRemapped, targetGroup, positiveGroup);
                }
            }
        }
        remapNegativeDocs(docRemapped, targetGroup, negativeGroup);
    } finally {
        bitSetPooler.release(docRemapped.memoryUsage());
    }

    finalizeRegroup();
}