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;
}
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();
}
}
Aggregations