Search in sources :

Example 1 with KeywordMatcherSourceOperator

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

the class JoinDistanceTest method testWhenOpenOrCloseIsCalledTwiceAndTryToGetNextTupleWhenClosed.

// ------------------------<Test cases for cursor.>------------------------
/*
     * This case tests for the scenario when open and/or close is called twice 
     * and also when getNextTuple() is called when operator is closed.
     * Test result: Opening or closing the operator twice shouldn't result in 
     * any noticeable difference in operation. But, calling getNetTuple() when 
     * operator is closed should throw an exception.
     */
@Test(expected = DataFlowException.class)
public void testWhenOpenOrCloseIsCalledTwiceAndTryToGetNextTupleWhenClosed() throws Exception {
    List<Tuple> tuples = JoinTestConstants.bookGroup1.subList(1, 5);
    JoinTestHelper.insertToTable(BOOK_TABLE, tuples);
    KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "typical", conjunction);
    KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "actually", conjunction);
    JoinDistancePredicate distancePredicate = new JoinDistancePredicate(JoinTestConstants.REVIEW, 90);
    Join join = new Join(distancePredicate);
    join.setOuterInputOperator(keywordSourceOuter);
    join.setInnerInputOperator(keywordSourceInner);
    Tuple tuple;
    List<Tuple> resultList = new ArrayList<>();
    join.open();
    join.open();
    while ((tuple = join.getNextTuple()) != null) {
        resultList.add(tuple);
    }
    join.close();
    join.close();
    Assert.assertEquals(4, resultList.size());
    // this line should throw an exception because operator is already closed
    if ((tuple = join.getNextTuple()) != null) {
        resultList.add(tuple);
    }
}
Also used : ArrayList(java.util.ArrayList) Join(edu.uci.ics.textdb.exp.join.Join) JoinDistancePredicate(edu.uci.ics.textdb.exp.join.JoinDistancePredicate) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) Test(org.junit.Test)

Example 2 with KeywordMatcherSourceOperator

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

the class JoinDistanceTest method testOneOfTheOperatorResultIsEmpty.

// This case tests for the scenario when either/both of the operators'
// result lists are empty (i.e. when one/both of the operators' are
// not able to find any suitable matches)
// Test result: Join should return an empty list.
@Test
public void testOneOfTheOperatorResultIsEmpty() throws Exception {
    JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
    KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "special", conjunction);
    KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "book", conjunction);
    List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 20), Integer.MAX_VALUE, 0);
    Assert.assertEquals(0, resultList.size());
}
Also used : JoinDistancePredicate(edu.uci.ics.textdb.exp.join.JoinDistancePredicate) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) Test(org.junit.Test)

Example 3 with KeywordMatcherSourceOperator

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

the class JoinDistanceTest method testBothTheSpansAreSame.

// This case tests for the scenario when the spans to be joined are the same, i.e. both the keywords
// are same.
// e.g.
// [<11, 18>]
// [<11, 18>]
// threshold = 20 (can be any non-negative number)
// [ ]
// [ ]
// Test result: Join should return same span and key and the value in span
// should be the same.
// [<11, 18>]
@Test
public void testBothTheSpansAreSame() throws Exception {
    JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
    KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "special", conjunction);
    KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "special", conjunction);
    List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 20), Integer.MAX_VALUE, 0);
    Schema resultSchema = Utils.createSpanSchema(JoinTestConstants.BOOK_SCHEMA);
    List<Span> spanList = new ArrayList<>();
    Span span1 = new Span(JoinTestConstants.REVIEW, 11, 18, "special_special", "special");
    spanList.add(span1);
    IField[] book1 = { new IntegerField(52), new StringField("Mary Roach"), new StringField("Grunt: The Curious Science of Humans at War"), new IntegerField(288), new TextField("It takes a special kind " + "of writer to make topics ranging from death to our " + "gastrointestinal tract interesting (sometimes " + "hilariously so), and pop science writer Mary Roach is " + "always up to the task."), new ListField<>(spanList) };
    Tuple expectedTuple = new Tuple(resultSchema, book1);
    List<Tuple> expectedResult = new ArrayList<>();
    expectedResult.add(expectedTuple);
    Assert.assertEquals(1, resultList.size());
    Assert.assertTrue(TestUtils.equals(expectedResult, resultList));
}
Also used : Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) JoinDistancePredicate(edu.uci.ics.textdb.exp.join.JoinDistancePredicate) Span(edu.uci.ics.textdb.api.span.Span) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 4 with KeywordMatcherSourceOperator

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

the class JoinDistanceTest method testForLimitWhenLimitIsLesserThanActualNumberOfResultsAndHasOffset.

/*
     * This case tests for the scenario when limit is some integer greater than
     * 0 and less than the actual number of results and offset is some integer
     * greater than 0 and less than actual number of results and join is 
     * performed.
     * Test result: A list of tuples with number of tuples equal to limit 
     * starting from the set offset.
     */
@Test
public void testForLimitWhenLimitIsLesserThanActualNumberOfResultsAndHasOffset() throws Exception {
    List<Tuple> tuples = JoinTestConstants.bookGroup1.subList(1, 5);
    JoinTestHelper.insertToTable(BOOK_TABLE, tuples);
    KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "typical", conjunction);
    KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "actually", conjunction);
    List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 90), 1, 2);
    Schema resultSchema = Utils.createSpanSchema(JoinTestConstants.BOOK_SCHEMA);
    List<Span> spanList = new ArrayList<>();
    Span span1 = new Span(JoinTestConstants.REVIEW, 28, 119, "typical_actually", "typical review. " + "This is a test. A book review test. " + "A test to test queries without actually");
    spanList.add(span1);
    Span span2 = new Span(JoinTestConstants.REVIEW, 186, 234, "typical_actually", "actually a review " + "even if it is not your typical");
    spanList.add(span2);
    IField[] book1 = { new IntegerField(54), new StringField("Andria Williams"), new StringField("The Longest Night: A Novel"), new IntegerField(400), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
    Tuple expectedTuple1 = new Tuple(resultSchema, book1);
    List<Tuple> expectedResult = new ArrayList<>(1);
    expectedResult.add(expectedTuple1);
    Assert.assertEquals(1, resultList.size());
    Assert.assertTrue(TestUtils.equals(expectedResult, resultList));
}
Also used : Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) JoinDistancePredicate(edu.uci.ics.textdb.exp.join.JoinDistancePredicate) Span(edu.uci.ics.textdb.api.span.Span) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 5 with KeywordMatcherSourceOperator

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

the class JoinDistanceTest method testOneOfTheOperatorResultContainsNoSpan.

// This case tests for the scenario when one of the operators result lists has no span. 
// If one of the operators doesn't have span, then an exception will be thrown.
// Test result: DataFlowException is thrown
@Test(expected = DataFlowException.class)
public void testOneOfTheOperatorResultContainsNoSpan() throws Exception {
    JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
    KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "special", conjunction);
    String fuzzyTokenQuery = "this writer writes well";
    double thresholdRatio = 0.25;
    List<String> textAttributeNames = JoinTestConstants.BOOK_SCHEMA.getAttributes().stream().filter(attr -> attr.getAttributeType() != AttributeType.TEXT).map(Attribute::getAttributeName).collect(Collectors.toList());
    FuzzyTokenSourcePredicate fuzzySourcePredicateInner = new FuzzyTokenSourcePredicate(fuzzyTokenQuery, textAttributeNames, LuceneAnalyzerConstants.standardAnalyzerString(), thresholdRatio, BOOK_TABLE, SchemaConstants.SPAN_LIST);
    FuzzyTokenMatcherSourceOperator fuzzyMatcherInner = new FuzzyTokenMatcherSourceOperator(fuzzySourcePredicateInner);
    ProjectionPredicate removeSpanListPredicate = new ProjectionPredicate(JoinTestConstants.BOOK_SCHEMA.getAttributeNames());
    ProjectionOperator removeSpanListProjection = new ProjectionOperator(removeSpanListPredicate);
    removeSpanListProjection.setInputOperator(fuzzyMatcherInner);
    JoinTestHelper.getJoinDistanceResults(keywordSourceOuter, removeSpanListProjection, new JoinDistancePredicate(JoinTestConstants.REVIEW, 20), Integer.MAX_VALUE, 0);
}
Also used : FuzzyTokenMatcherSourceOperator(edu.uci.ics.textdb.exp.fuzzytokenmatcher.FuzzyTokenMatcherSourceOperator) ProjectionOperator(edu.uci.ics.textdb.exp.projection.ProjectionOperator) FuzzyTokenSourcePredicate(edu.uci.ics.textdb.exp.fuzzytokenmatcher.FuzzyTokenSourcePredicate) ProjectionPredicate(edu.uci.ics.textdb.exp.projection.ProjectionPredicate) JoinDistancePredicate(edu.uci.ics.textdb.exp.join.JoinDistancePredicate) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) Test(org.junit.Test)

Aggregations

KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)26 Test (org.junit.Test)22 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)20 JoinDistancePredicate (edu.uci.ics.textdb.exp.join.JoinDistancePredicate)19 ArrayList (java.util.ArrayList)12 Span (edu.uci.ics.textdb.api.span.Span)10 IField (edu.uci.ics.textdb.api.field.IField)9 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)9 StringField (edu.uci.ics.textdb.api.field.StringField)9 TextField (edu.uci.ics.textdb.api.field.TextField)9 Schema (edu.uci.ics.textdb.api.schema.Schema)9 KeywordSourcePredicate (edu.uci.ics.textdb.exp.keywordmatcher.KeywordSourcePredicate)4 IOperator (edu.uci.ics.textdb.api.dataflow.IOperator)3 ISink (edu.uci.ics.textdb.api.dataflow.ISink)3 Plan (edu.uci.ics.textdb.api.engine.Plan)3 Join (edu.uci.ics.textdb.exp.join.Join)3 RegexMatcher (edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher)3 TupleSink (edu.uci.ics.textdb.exp.sink.tuple.TupleSink)3 Attribute (edu.uci.ics.textdb.api.schema.Attribute)2 OneToNBroadcastConnector (edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector)2