use of edu.uci.ics.texera.dataflow.join.JoinDistancePredicate in project textdb by TextDB.
the class PredicateBaseTest method testJoinDistance.
@Test
public void testJoinDistance() throws Exception {
JoinDistancePredicate joinDistancePredicate = new JoinDistancePredicate("attr1", "attr1", 100);
testPredicate(joinDistancePredicate);
}
use of edu.uci.ics.texera.dataflow.join.JoinDistancePredicate in project textdb by TextDB.
the class JoinDistanceTest method testForLimitWhenLimitIsZero.
/*
* This case tests for the scenario when limit is 0 and offset is 0 and
* join is performed.
* Test result: An empty list.
*/
@Test
public void testForLimitWhenLimitIsZero() 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), 0, 0);
Assert.assertEquals(0, resultList.size());
}
use of edu.uci.ics.texera.dataflow.join.JoinDistancePredicate 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 = new Schema.Builder().add(JoinTestConstants.BOOK_SCHEMA).add(SchemaConstants.SPAN_LIST_ATTRIBUTE).build();
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));
}
use of edu.uci.ics.texera.dataflow.join.JoinDistancePredicate in project textdb by TextDB.
the class JoinDistanceTest method testOneSpanEncompassesOtherAndDifferenceGreaterThanThreshold.
/*
* This case tests for the scenario when one of the spans to be joined encompasses the other span
* and |(span 1 spanStartIndex) - (span 2 spanStartIndex)|
* and/or |(span 1 spanEndIndex) - (span 2 spanEndIndex)| exceed threshold.
*
* e.g.
* [<11, 18>]
* [<3, 33>]
* threshold = 10 (beyond threshold)
* Test result: Join should return an empty list.
*/
@Test
public void testOneSpanEncompassesOtherAndDifferenceGreaterThanThreshold() throws Exception {
JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "special", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "takes a special kind of writer", phrase);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 10), Integer.MAX_VALUE, 0);
Assert.assertEquals(0, resultList.size());
}
use of edu.uci.ics.texera.dataflow.join.JoinDistancePredicate 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);
}
}
Aggregations