Search in sources :

Example 56 with DoubleField

use of edu.uci.ics.textdb.api.field.DoubleField 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));
}
Also used : Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 57 with DoubleField

use of edu.uci.ics.textdb.api.field.DoubleField in project textdb by TextDB.

the class FuzzyTokenMatcherTest method TestFuzzyTokenMatcherWithThresholdVariation.

@Test
public void TestFuzzyTokenMatcherWithThresholdVariation() throws Exception {
    String query = "Twelve Angry Men Cafe";
    double threshold = 0.25;
    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);
}
Also used : Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 58 with DoubleField

use of edu.uci.ics.textdb.api.field.DoubleField 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));
}
Also used : Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 59 with DoubleField

use of edu.uci.ics.textdb.api.field.DoubleField 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);
}
Also used : Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 60 with DoubleField

use of edu.uci.ics.textdb.api.field.DoubleField 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);
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

DoubleField (edu.uci.ics.textdb.api.field.DoubleField)69 IField (edu.uci.ics.textdb.api.field.IField)68 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)68 StringField (edu.uci.ics.textdb.api.field.StringField)68 TextField (edu.uci.ics.textdb.api.field.TextField)68 DateField (edu.uci.ics.textdb.api.field.DateField)64 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)64 SimpleDateFormat (java.text.SimpleDateFormat)63 ArrayList (java.util.ArrayList)63 Test (org.junit.Test)63 Attribute (edu.uci.ics.textdb.api.schema.Attribute)56 Schema (edu.uci.ics.textdb.api.schema.Schema)51 Span (edu.uci.ics.textdb.api.span.Span)49 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)24 ParseException (java.text.ParseException)4 IOperator (edu.uci.ics.textdb.api.dataflow.IOperator)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ListField (edu.uci.ics.textdb.api.field.ListField)1 Random (java.util.Random)1