Search in sources :

Example 6 with KeywordPredicate

use of edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate 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 7 with KeywordPredicate

use of edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate 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)

Example 8 with KeywordPredicate

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

the class SelectStatementTest method testSelectStatementBeansBuilder04.

/**
     * Test the correctness of the generated beans by a SelectStatement with a
     * ProjectAllFieldsPredicate and a KeywordExtractPredicate.
     * Get a graph by calling getInternalPredicateBases() and getInternalLinkBeans()
     * methods and check if the generated path form the node getInputNodeID() to 
     * the node getOutputNodeID() is correct. Also check whether getInputViews()
     * is returning the correct dependencies.  
     */
@Test
public void testSelectStatementBeansBuilder04() {
    ProjectPredicate projectPredicate = new ProjectAllFieldsPredicate();
    ExtractPredicate extractPredicate = new KeywordExtractPredicate(Arrays.asList("f1"), "keyword", KeywordMatchingType.CONJUNCTION_INDEXBASED.toString());
    SelectStatement selectStatement = new SelectStatement("id", projectPredicate, extractPredicate, "source", null, null);
    List<PredicateBase> expectedGeneratedBeans = Arrays.asList(new KeywordPredicate("keyword", Arrays.asList("f1"), null, KeywordMatchingType.CONJUNCTION_INDEXBASED, "id_e"));
    List<String> dependencies = Arrays.asList("source");
    Assert.assertEquals(selectStatement.getInputViews(), dependencies);
    StatementTestUtils.assertGeneratedBeans(selectStatement, expectedGeneratedBeans);
}
Also used : SelectStatement(edu.uci.ics.textdb.textql.statements.SelectStatement) ProjectPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate) PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) KeywordExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate) ExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.ExtractPredicate) ProjectAllFieldsPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectAllFieldsPredicate) KeywordExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate) KeywordPredicate(edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate) Test(org.junit.Test)

Example 9 with KeywordPredicate

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

the class KeywordExtractPredicateTest method testGeneratePredicateBase02.

/**
     * Test the generatePredicateBase method.
     * Build a KeywordExtractPredicate, invoke the generatePredicateBase and
     * check whether a KeywordMatcherBean with the right attributes is returned.
     * A list with some fields is used as the list of fields to perform the match.
     */
@Test
public void testGeneratePredicateBase02() {
    String operatorId = "keywordExtract00";
    List<String> matchingFields = Arrays.asList("field0", "field1");
    String keywords = "xxx";
    String matchingType = KeywordMatchingType.SUBSTRING_SCANBASED.toString();
    KeywordExtractPredicate keywordExtractPredicate = new KeywordExtractPredicate(matchingFields, keywords, matchingType);
    PredicateBase computedProjectionBean = keywordExtractPredicate.generateOperatorBean(operatorId);
    PredicateBase expectedProjectionBean = new KeywordPredicate(keywords, matchingFields, null, KeywordMatchingType.fromName(matchingType), operatorId);
    expectedProjectionBean.setID(operatorId);
    Assert.assertEquals(expectedProjectionBean, computedProjectionBean);
}
Also used : PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) KeywordPredicate(edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate) Test(org.junit.Test)

Example 10 with KeywordPredicate

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

the class KeywordExtractPredicateTest method testGeneratePredicateBase00.

/**
     * Test the generatePredicateBase method.
     * Build a KeywordExtractPredicate, invoke the generatePredicateBase and
     * check whether a KeywordMatcherBean with the right attributes is returned.
     * An empty list is used as the list of fields to perform the match.
     */
@Test
public void testGeneratePredicateBase00() {
    String operatorId = "xxx";
    List<String> matchingFields = Collections.emptyList();
    String keywords = "keyword";
    String matchingType = KeywordMatchingType.CONJUNCTION_INDEXBASED.toString();
    KeywordExtractPredicate keywordExtractPredicate = new KeywordExtractPredicate(matchingFields, keywords, matchingType);
    PredicateBase computedProjectionBean = keywordExtractPredicate.generateOperatorBean(operatorId);
    PredicateBase expectedProjectionBean = new KeywordPredicate(keywords, matchingFields, null, KeywordMatchingType.fromName(matchingType), operatorId);
    expectedProjectionBean.setID(operatorId);
    Assert.assertEquals(expectedProjectionBean, computedProjectionBean);
}
Also used : PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) KeywordPredicate(edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate) Test(org.junit.Test)

Aggregations

KeywordPredicate (edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate)10 Test (org.junit.Test)7 PredicateBase (edu.uci.ics.textdb.exp.common.PredicateBase)6 SelectStatement (edu.uci.ics.textdb.textql.statements.SelectStatement)3 ExtractPredicate (edu.uci.ics.textdb.textql.statements.predicates.ExtractPredicate)3 KeywordExtractPredicate (edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate)3 DataFlowException (edu.uci.ics.textdb.api.exception.DataFlowException)2 KeywordMatcher (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcher)2 ProjectPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate)2 TextDBException (edu.uci.ics.textdb.api.exception.TextDBException)1 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)1 KeywordSourcePredicate (edu.uci.ics.textdb.exp.keywordmatcher.KeywordSourcePredicate)1 ProjectionPredicate (edu.uci.ics.textdb.exp.projection.ProjectionPredicate)1 ProjectAllFieldsPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectAllFieldsPredicate)1 ProjectSomeFieldsPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectSomeFieldsPredicate)1