use of edu.uci.ics.textdb.api.field.TextField in project textdb by TextDB.
the class FuzzyTokenMatcherTest method TestFuzzyTokenMatcherWithLimit.
@Test
public void TestFuzzyTokenMatcherWithLimit() throws Exception {
String query = "Twelve Angry Men";
// The ratio of tokens that need to be matched
double threshold = 0.5;
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstants.DESCRIPTION);
Schema schema = Utils.addAttributeToSchema(TestConstants.SCHEMA_PEOPLE, RESULTS_ATTR);
List<Span> list = new ArrayList<>();
Span span = new Span(TestConstants.DESCRIPTION, 5, 10, "angry", "Angry", 1);
list.add(span);
IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry"), new ListField<>(list) };
list = new ArrayList<>();
span = new Span(TestConstants.DESCRIPTION, 6, 11, "angry", "Angry", 1);
list.add(span);
IField[] fields2 = { new StringField("brad lie angelina"), new StringField("pitt"), new IntegerField(44), new DoubleField(6.10), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-12-1972")), new TextField("White Angry"), new ListField<>(list) };
list = new ArrayList<>();
span = new Span(TestConstants.DESCRIPTION, 40, 45, "angry", "Angry", 8);
list.add(span);
IField[] fields3 = { new StringField("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is Angry"), new ListField<>(list) };
list = new ArrayList<>();
span = new Span(TestConstants.DESCRIPTION, 6, 11, "angry", "angry", 1);
list.add(span);
IField[] fields4 = { new StringField("Mary brown"), new StringField("Lake Forest"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Short angry"), new ListField<>(list) };
Tuple tuple1 = new Tuple(schema, fields1);
Tuple tuple2 = new Tuple(schema, fields2);
Tuple tuple3 = new Tuple(schema, fields3);
Tuple tuple4 = new Tuple(schema, fields4);
List<Tuple> expectedResultList = new ArrayList<>();
expectedResultList.add(tuple1);
expectedResultList.add(tuple2);
expectedResultList.add(tuple3);
expectedResultList.add(tuple4);
List<Tuple> results = FuzzyTokenMatcherTestHelper.getQueryResults(PEOPLE_TABLE, query, threshold, attributeNames, 2, 0);
Assert.assertEquals(expectedResultList.size(), 4);
Assert.assertEquals(results.size(), 2);
Assert.assertTrue(TestUtils.containsAll(expectedResultList, results));
}
use of edu.uci.ics.textdb.api.field.TextField in project textdb by TextDB.
the class FuzzyTokenMatcherTest method TestFuzzyTokenMatcher2.
@Test
public void TestFuzzyTokenMatcher2() throws Exception {
String query = "Twelve Angry Men";
// The ratio of tokens that need to be matched
double threshold = 0.5;
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstants.DESCRIPTION);
Schema schema = Utils.addAttributeToSchema(TestConstants.SCHEMA_PEOPLE, RESULTS_ATTR);
List<Span> spanList1 = Arrays.asList(new Span(TestConstants.DESCRIPTION, 5, 10, "angry", "Angry", 1));
IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry"), new ListField<Span>(spanList1) };
List<Span> spanList2 = Arrays.asList(new Span(TestConstants.DESCRIPTION, 6, 11, "angry", "Angry", 1));
IField[] fields2 = { new StringField("brad lie angelina"), new StringField("pitt"), new IntegerField(44), new DoubleField(6.10), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-12-1972")), new TextField("White Angry"), new ListField<Span>(spanList2) };
List<Span> spanList3 = Arrays.asList(new Span(TestConstants.DESCRIPTION, 40, 45, "angry", "Angry", 8));
IField[] fields3 = { new StringField("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is Angry"), new ListField<Span>(spanList3) };
List<Span> spanList4 = Arrays.asList(new Span(TestConstants.DESCRIPTION, 6, 11, "angry", "angry", 1));
IField[] fields4 = { new StringField("Mary brown"), new StringField("Lake Forest"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Short angry"), new ListField<Span>(spanList4) };
Tuple tuple1 = new Tuple(schema, fields1);
Tuple tuple2 = new Tuple(schema, fields2);
Tuple tuple3 = new Tuple(schema, fields3);
Tuple tuple4 = new Tuple(schema, fields4);
List<Tuple> expectedResultList = new ArrayList<>();
expectedResultList.add(tuple1);
expectedResultList.add(tuple2);
expectedResultList.add(tuple3);
expectedResultList.add(tuple4);
List<Tuple> results = FuzzyTokenMatcherTestHelper.getQueryResults(PEOPLE_TABLE, query, threshold, attributeNames);
boolean contains = TestUtils.equals(expectedResultList, results);
Assert.assertTrue(contains);
}
use of edu.uci.ics.textdb.api.field.TextField 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.api.field.TextField in project textdb by TextDB.
the class SimilarityJoinTest method test3.
/*
* Tests the Similarity Join Predicate on two similar words:
* Galaxy S8
* Galaxy Note 7
* Under the condition of similarity (NormalizedLevenshtein) > 0.5, these two words should match.
*
*/
@Test
public void test3() throws TextDBException {
JoinTestHelper.insertToTable(NEWS_TABLE_OUTER, JoinTestConstants.getNewsTuples().get(2));
JoinTestHelper.insertToTable(NEWS_TABLE_INNER, JoinTestConstants.getNewsTuples().get(3));
String phoneRegex = "[Gg]alaxy.{1,6}\\d";
RegexMatcher regexMatcherInner = JoinTestHelper.getRegexMatcher(JoinTestHelper.NEWS_TABLE_INNER, phoneRegex, JoinTestConstants.NEWS_BODY);
RegexMatcher regexMatcherOuter = JoinTestHelper.getRegexMatcher(JoinTestHelper.NEWS_TABLE_OUTER, phoneRegex, JoinTestConstants.NEWS_BODY);
SimilarityJoinPredicate similarityJoinPredicate = new SimilarityJoinPredicate(JoinTestConstants.NEWS_BODY, 0.5);
List<Tuple> results = JoinTestHelper.getJoinDistanceResults(regexMatcherInner, regexMatcherOuter, similarityJoinPredicate, Integer.MAX_VALUE, 0);
Schema joinInputSchema = Utils.addAttributeToSchema(JoinTestConstants.NEWS_SCHEMA, SchemaConstants.SPAN_LIST_ATTRIBUTE);
Schema resultSchema = similarityJoinPredicate.generateOutputSchema(joinInputSchema, joinInputSchema);
List<Span> resultSpanList = Arrays.asList(new Span("inner_" + JoinTestConstants.NEWS_BODY, 327, 336, phoneRegex, "Galaxy S8", -1), new Span("outer_" + JoinTestConstants.NEWS_BODY, 21, 34, phoneRegex, "Galaxy Note 7", -1));
Tuple resultTuple = new Tuple(resultSchema, new IDField(UUID.randomUUID().toString()), new IntegerField(4), new TextField("This is how Samsung plans to prevent future phones from catching fire"), new TextField("Samsung said that it has implemented a new eight-step testing process for " + "its lithium ion batteries, and that it’s forming a battery advisory board as well, " + "comprised of academics from Cambridge, Berkeley, and Stanford. " + "Note, this is for all lithium ion batteries in Samsung products, " + "not just Note phablets or the anticipated Galaxy S8 phone."), new IntegerField(3), new TextField("Samsung Explains Note 7 Battery Explosions, And Turns Crisis Into Opportunity"), new TextField("Samsung launched the Galaxy Note 7 to record preorders and sales in August, " + "but the rosy start soon turned sour. Samsung had to initiate a recall in September of " + "the first version of the Note 7 due to faulty batteries that overheated and exploded. " + "By October it had to recall over 2 million devices and discontinue the product. " + "It’s estimated that the recall will cost Samsung $5.3 billion."), new ListField<>(resultSpanList));
Assert.assertTrue(TestUtils.equals(Arrays.asList(resultTuple), results));
}
use of edu.uci.ics.textdb.api.field.TextField in project textdb by TextDB.
the class KeywordConjunctionTest method testSingleWordQueryInTextField.
/**
* Verifies GetNextTuple of Keyword Matcher and single word queries in Text
* Field
*
* @throws Exception
*/
@Test
public void testSingleWordQueryInTextField() throws Exception {
// Prepare the query
String query = "TaLL";
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstants.FIRST_NAME);
attributeNames.add(TestConstants.LAST_NAME);
attributeNames.add(TestConstants.DESCRIPTION);
// Prepare the expected result list
List<Span> list = new ArrayList<>();
Span span = new Span("description", 0, 4, "tall", "Tall", 0);
list.add(span);
Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < schemaAttributes.length - 1; count++) {
schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry"), new ListField<>(list) };
IField[] fields2 = { new StringField("christian john wayne"), new StringField("rock bale"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Tall Fair"), new ListField<>(list) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
List<Tuple> expectedResultList = new ArrayList<>();
expectedResultList.add(tuple1);
expectedResultList.add(tuple2);
// Perform the query
List<Tuple> resultList = KeywordTestHelper.getQueryResults(PEOPLE_TABLE, query, attributeNames, conjunction);
// check the results
boolean contains = TestUtils.equals(expectedResultList, resultList);
Assert.assertTrue(contains);
}
Aggregations