Search in sources :

Example 1 with KeywordMatcher

use of edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcher in project textdb by TextDB.

the class DictionaryMatcher method open.

@Override
public void open() throws DataFlowException {
    if (cursor != CLOSED) {
        return;
    }
    try {
        if (inputOperator == null) {
            throw new DataFlowException(ErrorMessages.INPUT_OPERATOR_NOT_SPECIFIED);
        }
        predicate.getDictionary().resetCursor();
        currentDictionaryEntry = predicate.getDictionary().getNextEntry();
        if (currentDictionaryEntry == null) {
            throw new DataFlowException("Dictionary is empty");
        }
        keywordPredicate = new KeywordPredicate(currentDictionaryEntry, predicate.getAttributeNames(), predicate.getAnalyzerString(), predicate.getKeywordMatchingType(), predicate.getSpanListName());
        keywordMatcher = new KeywordMatcher(keywordPredicate);
        cacheOperator = new DictionaryTupleCacheOperator();
        cacheOperator.setInputOperator(inputOperator);
        keywordMatcher.setInputOperator(cacheOperator);
        cacheOperator.openAll();
        keywordMatcher.open();
        outputSchema = keywordMatcher.getOutputSchema();
    } catch (Exception e) {
        throw new DataFlowException(e.getMessage(), e);
    }
    cursor = OPENED;
}
Also used : DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) KeywordMatcher(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcher) KeywordPredicate(edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException)

Example 2 with KeywordMatcher

use of edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcher in project textdb by TextDB.

the class DictionaryMatcher method getNextTuple.

@Override
public Tuple getNextTuple() throws TextDBException {
    if (cursor == CLOSED) {
        throw new DataFlowException(ErrorMessages.OPERATOR_NOT_OPENED);
    }
    if (resultCursor >= limit + offset - 1) {
        return null;
    }
    Tuple sourceTuple;
    while (true) {
        // If there's result from current keywordMatcher, return it.
        if ((sourceTuple = keywordMatcher.getNextTuple()) != null) {
            resultCursor++;
            if (resultCursor >= offset) {
                return sourceTuple;
            }
            continue;
        }
        // return null if reach the end of dictionary.
        if ((currentDictionaryEntry = predicate.getDictionary().getNextEntry()) == null) {
            return null;
        }
        // Update the KeywordMatcher with the new dictionary entry.
        keywordMatcher.close();
        keywordPredicate = new KeywordPredicate(currentDictionaryEntry, predicate.getAttributeNames(), predicate.getAnalyzerString(), predicate.getKeywordMatchingType(), predicate.getSpanListName());
        keywordMatcher = new KeywordMatcher(keywordPredicate);
        keywordMatcher.setInputOperator(cacheOperator);
        keywordMatcher.open();
    }
}
Also used : DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) KeywordMatcher(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcher) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) KeywordPredicate(edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate)

Aggregations

DataFlowException (edu.uci.ics.textdb.api.exception.DataFlowException)2 KeywordMatcher (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcher)2 KeywordPredicate (edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate)2 TextDBException (edu.uci.ics.textdb.api.exception.TextDBException)1 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)1