use of edu.uci.ics.texera.dataflow.join.JoinDistancePredicate 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.getType() != AttributeType.TEXT).map(Attribute::getName).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);
}
use of edu.uci.ics.texera.dataflow.join.JoinDistancePredicate in project textdb by TextDB.
the class JoinDistanceTest method testSpansOverlapAndExceedThreshold.
// This case tests for the scenario when the spans to be joined have some overlap and
// |(span 1 spanStartIndex) - (span 2 spanStartIndex)| and/or
// |(span 1 spanEndIndex) - (span 2 spanEndIndex)| exceed threshold.
// e.g.
// [<75, 97>]
// [<92, 109>]
// threshold = 10
// [ ]
// [ ]
// <--> <-----> (beyond threshold)
// Test result: Join should return an empty list.
@Test
public void testSpansOverlapAndExceedThreshold() throws Exception {
JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "takes a special", phrase);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "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 testBothOperatorsMultipleTuplesSpanExceedThreshold.
/*
* This case tests for the scenario when both the operators' have multiple
* tuples and none of spans are within threshold.
*
* Test result: Join should result in an empty list.
*/
@Test
public void testBothOperatorsMultipleTuplesSpanExceedThreshold() throws Exception {
List<Tuple> tuples = new ArrayList<>();
tuples.add(JoinTestConstants.bookGroup1.get(3));
tuples.add(JoinTestConstants.bookGroup2.get(2));
tuples.add(JoinTestConstants.bookGroup2.get(4));
JoinTestHelper.insertToTable(BOOK_TABLE, tuples);
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "review", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "book", conjunction);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 4), 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 testForLimitWhenLimitIsGreaterThanActualNumberOfResults.
/*
* This case tests for the scenario when limit is some integer greater than
* 0 and greater than the actual number of results and offset is 0 and join
* is performed.
* Test result: A list of tuples with number of tuples equal to the maximum
* number of tuples operator can generate (which is lesser than limit.)
*/
@Test
public void testForLimitWhenLimitIsGreaterThanActualNumberOfResults() 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), 10, 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, 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(51), new StringField("author unknown"), new StringField("typical"), new IntegerField(300), 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) };
IField[] book2 = { new IntegerField(53), new StringField("Noah Hawley"), new StringField("Before the Fall"), 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) };
IField[] book3 = { 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) };
IField[] book4 = { new IntegerField(55), new StringField("Matti Friedman"), new StringField("Pumpkinflowers: A Soldier's " + "Story"), new IntegerField(256), 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);
Tuple expectedTuple2 = new Tuple(resultSchema, book2);
Tuple expectedTuple3 = new Tuple(resultSchema, book3);
Tuple expectedTuple4 = new Tuple(resultSchema, book4);
List<Tuple> expectedResult = new ArrayList<>(5);
expectedResult.add(expectedTuple1);
expectedResult.add(expectedTuple2);
expectedResult.add(expectedTuple3);
expectedResult.add(expectedTuple4);
Assert.assertEquals(4, 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 testForLimitWhenLimitIsZeroAndHasOffset.
/*
* This case tests for the scenario when limit is 0 and offset is some
* integer greater than 0 and less than the actual number of results and
* join is performed.
* Test result: An empty list.
*/
@Test
public void testForLimitWhenLimitIsZeroAndHasOffset() 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, 2);
Assert.assertEquals(0, resultList.size());
}
Aggregations