Search in sources :

Example 1 with RegexMatcherSourceOperator

use of edu.uci.ics.textdb.exp.regexmatcher.RegexMatcherSourceOperator in project textdb by TextDB.

the class RegexMatcherPerformanceTest method matchRegex.

/*
     *         This function does match for a list of regex queries
     */
public static void matchRegex(List<String> regexes, String tableName) throws TextDBException, IOException {
    List<String> attributeNames = Arrays.asList(MedlineIndexWriter.ABSTRACT);
    for (String regex : regexes) {
        // analyzer should generate grams all in lower case to build a lower
        // case index.
        RegexSourcePredicate predicate = new RegexSourcePredicate(regex, attributeNames, tableName, null);
        RegexMatcherSourceOperator regexSource = new RegexMatcherSourceOperator(predicate);
        long startMatchTime = System.currentTimeMillis();
        regexSource.open();
        int counter = 0;
        Tuple nextTuple = null;
        while ((nextTuple = regexSource.getNextTuple()) != null) {
            ListField<Span> spanListField = nextTuple.getField(SchemaConstants.SPAN_LIST);
            List<Span> spanList = spanListField.getValue();
            counter += spanList.size();
        }
        regexSource.close();
        long endMatchTime = System.currentTimeMillis();
        double matchTime = (endMatchTime - startMatchTime) / 1000.0;
        totalMatchingTime += matchTime;
        totalRegexResultCount += counter;
    }
}
Also used : RegexSourcePredicate(edu.uci.ics.textdb.exp.regexmatcher.RegexSourcePredicate) RegexMatcherSourceOperator(edu.uci.ics.textdb.exp.regexmatcher.RegexMatcherSourceOperator) Span(edu.uci.ics.textdb.api.span.Span) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Aggregations

Span (edu.uci.ics.textdb.api.span.Span)1 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)1 RegexMatcherSourceOperator (edu.uci.ics.textdb.exp.regexmatcher.RegexMatcherSourceOperator)1 RegexSourcePredicate (edu.uci.ics.textdb.exp.regexmatcher.RegexSourcePredicate)1