use of edu.uci.ics.textdb.exp.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.textdb.exp.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.textdb.exp.join.JoinDistancePredicate in project textdb by TextDB.
the class JoinDistanceTest method testSpansOverlapAndWithinThreshold.
/*
* This case tests for the spans to be joined have some overlap and both
* |(span 1 spanStartIndex) - (span 2 spanStartIndex)|,
* |(span 1 spanEndIndex) - (span 2 spanEndIndex)| are within threshold.
*
* e.g.
* [<75, 97>]
* [<92, 109>]
* threshold = 20 (within threshold)
* result: [<75, 109>]
*
* Test result: The list contains a tuple with all the fields and a span
* list consisting of the joined span. The joined span is made up of the
* field name, start and stop index (computed as <min(span1 spanStartIndex,
* span2 spanStartIndex), max(span1 spanEndIndex, span2 spanEndIndex)>)
* key (combination of span1 key and span2 key) and value (combination of
* span1 value and span2 value).
*/
@Test
public void testSpansOverlapAndWithinThreshold() throws Exception {
JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "gastrointestinal tract", phrase);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "tract interesting", phrase);
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, 75, 109, "gastrointestinal tract_" + "tract interesting", "gastrointestinal " + "tract interesting");
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.textdb.exp.join.JoinDistancePredicate in project textdb by TextDB.
the class JoinDistanceTest method testOneSpanEncompassesOtherAndDifferenceLessThanThreshold.
// This case tests for the scenario when one of the spans to be joined encompasses the other span
// and both |(span 1 spanStartIndex) - (span 2 spanStartIndex)|,
// |(span 1 spanEndIndex) - (span 2 spanEndIndex)| are within threshold.
// e.g.
// [<11, 18>]
// [<3, 33>]
// threshold = 20 (within threshold)
// Test result: The bigger span should be returned.
// [<3, 33>]
@Test
public void testOneSpanEncompassesOtherAndDifferenceLessThanThreshold() 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, 20), Integer.MAX_VALUE, 0);
Schema resultSchema = Utils.createSpanSchema(JoinTestConstants.BOOK_SCHEMA);
List<Span> spanList = new ArrayList<>();
Span span1 = new Span(JoinTestConstants.REVIEW, 3, 33, "special_takes a special " + "kind of writer", "takes a special " + "kind of writer");
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.textdb.exp.join.JoinDistancePredicate in project textdb by TextDB.
the class JoinDistanceTest method testIdsMatchFieldsMatchSpanExceedThreshold.
/*
* This case tests for the scenario when the difference of keyword spans
* to be joined is greater than the threshold.
*
* [<11, 18>]
* [<42, 48>]
* threshold = 20 (beyond threshold)
*
* Test result: An empty list is returned.
*/
@Test
public void testIdsMatchFieldsMatchSpanExceedThreshold() throws Exception {
JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "special", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "topics", conjunction);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 20), Integer.MAX_VALUE, 0);
Assert.assertEquals(0, resultList.size());
}
Aggregations