use of edu.uci.ics.textdb.api.field.DateField in project textdb by TextDB.
the class DictionaryMatcherTest method testSingleWordQueryInStringFieldUsingPhrase.
/**
* Scenario: verifies GetNextTuple of DictionaryMatcher and multiple word
* queries in String Field using PHRASEOPERATOR
*/
@Test
public void testSingleWordQueryInStringFieldUsingPhrase() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("john Lee", "bruce"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list1 = new ArrayList<Span>();
List<Span> list2 = new ArrayList<Span>();
Span span1 = new Span("lastName", 0, 8, "john Lee", "john Lee");
Span span2 = new Span("firstName", 0, 5, "bruce", "bruce");
list1.add(span1);
list2.add(span2);
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] = RESULTS_ATTRIBUTE;
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>(list1) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
IField[] fields2 = { 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>(list2) };
Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
List<Tuple> expectedResults = new ArrayList<Tuple>();
expectedResults.add(tuple1);
expectedResults.add(tuple2);
List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_TABLE, dictionary, attributeNames, KeywordMatchingType.PHRASE_INDEXBASED);
boolean contains = TestUtils.equals(expectedResults, returnedResults);
Assert.assertTrue(contains);
}
use of edu.uci.ics.textdb.api.field.DateField in project textdb by TextDB.
the class TestConstantsRegexSplit method constructSamplePeopleTuples.
public static List<Tuple> constructSamplePeopleTuples() {
try {
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("banana") };
IField[] fields2 = { new StringField("tom hanks"), new StringField("cruise"), new IntegerField(45), new DoubleField(5.95), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1971")), new TextField("mississippi") };
Tuple tuple1 = new Tuple(SCHEMA_PEOPLE, fields1);
Tuple tuple2 = new Tuple(SCHEMA_PEOPLE, fields2);
return Arrays.asList(tuple1, tuple2);
} catch (ParseException e) {
// exception should not happen because we know the data is correct
e.printStackTrace();
return Arrays.asList();
}
}
use of edu.uci.ics.textdb.api.field.DateField in project textdb by TextDB.
the class SpanTupleTest method testGetters.
@Test
public void testGetters() throws ParseException {
// create data tuple first
Attribute[] attributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < attributes.length - 1; count++) {
attributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
attributes[attributes.length - 1] = SchemaConstants.SPAN_LIST_ATTRIBUTE;
List<IField> fields = new ArrayList<IField>(Arrays.asList(new IField[] { new StringField("bruce"), new StringField("lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("bruce was born in new york city and was grown up in los angeles") }));
IField spanField = createSpanListField();
fields.add(spanField);
spanTuple = new Tuple(new Schema(attributes), fields.toArray(new IField[fields.size()]));
IField spanFieldRetrieved = spanTuple.getField(SchemaConstants.SPAN_LIST);
Assert.assertTrue(spanFieldRetrieved instanceof ListField);
Assert.assertSame(spanField, spanFieldRetrieved);
}
use of edu.uci.ics.textdb.api.field.DateField in project textdb by TextDB.
the class DictionaryMatcherTest method testSingleWordQueryInStringFieldUsingScan.
/**
* Scenario: verifies GetNextTuple of DictionaryMatcher and single word
* queries in String Field using SCANOPERATOR
*/
@Test
public void testSingleWordQueryInStringFieldUsingScan() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("bruce"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list = new ArrayList<Span>();
Span span = new Span("firstName", 0, 5, "bruce", "bruce");
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] = RESULTS_ATTRIBUTE;
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>(list) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
List<Tuple> expectedResults = new ArrayList<Tuple>();
expectedResults.add(tuple1);
List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_TABLE, dictionary, attributeNames, KeywordMatchingType.SUBSTRING_SCANBASED);
boolean contains = TestUtils.equals(expectedResults, returnedResults);
Assert.assertTrue(contains);
}
use of edu.uci.ics.textdb.api.field.DateField in project textdb by TextDB.
the class FuzzyTokenMatcherTest method TestFuzzyTokenMatcherWithLimitOffset.
@Test
public void TestFuzzyTokenMatcherWithLimitOffset() 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, 1);
Assert.assertEquals(expectedResultList.size(), 4);
Assert.assertEquals(results.size(), 2);
Assert.assertTrue(TestUtils.containsAll(expectedResultList, results));
}
Aggregations