Search in sources :

Example 26 with DoubleField

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

the class DictionaryMatcherTest method testMultipleWordsQueryUsingScan.

/**
     * Scenario S-8:verifies ITuple returned by DictionaryMatcher and multiple
     * word queries using SCAN OPERATOR
     */
@Test
public void testMultipleWordsQueryUsingScan() throws Exception {
    ArrayList<String> names = new ArrayList<String>(Arrays.asList("george lin lin"));
    Dictionary dictionary = new Dictionary(names);
    // create a data tuple first
    List<Span> list = new ArrayList<Span>();
    Span span = new Span("firstName", 0, 14, "george lin lin", "george lin lin");
    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("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>(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);
}
Also used : Dictionary(edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary) 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)

Example 27 with DoubleField

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

the class DictionaryMatcherTest method testMultipleWordsQueryUsingPhraseChinese.

/**
     * Scenario S-10C:verifies ITuple returned by DictionaryMatcher and multiple
     * word queries using PHRASE OPERATOR in Chinese
     */
@Test
public void testMultipleWordsQueryUsingPhraseChinese() throws Exception {
    ArrayList<String> names = new ArrayList<String>(Arrays.asList("洛克贝尔"));
    Dictionary dictionary = new Dictionary(names);
    // create a data tuple first
    List<Span> list = new ArrayList<Span>();
    Span span = new Span("lastName", 0, 4, "洛克贝尔", "洛克贝尔");
    ;
    list.add(span);
    Attribute[] schemaAttributes = new Attribute[TestConstantsChinese.ATTRIBUTES_PEOPLE.length + 1];
    for (int count = 0; count < schemaAttributes.length - 1; count++) {
        schemaAttributes[count] = TestConstantsChinese.ATTRIBUTES_PEOPLE[count];
    }
    schemaAttributes[schemaAttributes.length - 1] = RESULTS_ATTRIBUTE;
    IField[] fields1 = { new StringField("孔明"), new StringField("洛克贝尔"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("北京大学计算机学院"), 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(TestConstantsChinese.FIRST_NAME, TestConstantsChinese.LAST_NAME, TestConstantsChinese.DESCRIPTION);
    List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(CHINESE_TABLE, dictionary, attributeNames, KeywordMatchingType.PHRASE_INDEXBASED);
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : Dictionary(edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary) 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)

Example 28 with DoubleField

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

the class DictionaryMatcherTest method testSingleWordQueryInStringFieldUsingPhraseChinese.

/**
     * Scenario: verifies GetNextTuple of DictionaryMatcher and multiple word
     * queries in String Field using PHRASE_INDEXBASED in Chinese.
     */
@Test
public void testSingleWordQueryInStringFieldUsingPhraseChinese() throws Exception {
    ArrayList<String> names = new ArrayList<String>(Arrays.asList("长孙", "无忌"));
    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, 2, "长孙", "长孙");
    Span span2 = new Span("firstName", 0, 2, "无忌", "无忌");
    list1.add(span1);
    list2.add(span2);
    Attribute[] schemaAttributes = new Attribute[TestConstantsChinese.ATTRIBUTES_PEOPLE.length + 1];
    for (int count = 0; count < schemaAttributes.length - 1; count++) {
        schemaAttributes[count] = TestConstantsChinese.ATTRIBUTES_PEOPLE[count];
    }
    schemaAttributes[schemaAttributes.length - 1] = RESULTS_ATTRIBUTE;
    IField[] fields1 = { new StringField("无忌"), new StringField("长孙"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("北京大学电气工程学院"), new ListField<Span>(list1) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    IField[] fields2 = { new StringField("无忌"), new StringField("长孙"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("北京大学电气工程学院"), 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(TestConstantsChinese.FIRST_NAME, TestConstantsChinese.LAST_NAME, TestConstantsChinese.DESCRIPTION);
    List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(CHINESE_TABLE, dictionary, attributeNames, KeywordMatchingType.PHRASE_INDEXBASED);
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : Dictionary(edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary) 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)

Example 29 with DoubleField

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

the class ComparableMatcherTest method testIntegerMatching3.

/**
     * Verifies the behavior of ComparableMatcher<Integer> with matching type GREATER_THAN_OR_EQAUL_TO
     *
     * @throws Exception
     */
@Test
public void testIntegerMatching3() throws Exception {
    // Prepare the query
    int threshold = 45;
    Attribute attribute = TestConstants.AGE_ATTR;
    String attributeName = attribute.getAttributeName();
    ComparisonType matchingType = ComparisonType.GREATER_THAN_OR_EQUAL_TO;
    // Perform the query
    List<Tuple> returnedResults = getIntegerQueryResults(attributeName, matchingType, threshold);
    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") };
    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("Short Brown") };
    List<Tuple> expectedResults = new ArrayList<>();
    expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields1));
    expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields2));
    // check the results
    Assert.assertEquals(2, returnedResults.size());
    Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) 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) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Test(org.junit.Test)

Example 30 with DoubleField

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

the class ComparableMatcherTest method testDoubleMatching5.

/**
     * Verifies the behavior of ComparableMatcher<Double> with matching type EQUAL_TO
     *
     * @throws Exception
     */
@Test
public void testDoubleMatching5() throws Exception {
    // Prepare the query
    double threshold = 6.10;
    Attribute attribute = TestConstants.HEIGHT_ATTR;
    String attributeName = attribute.getAttributeName();
    ComparisonType matchingType = ComparisonType.EQUAL_TO;
    // Perform the query
    List<Tuple> returnedResults = getDoubleQueryResults(attributeName, matchingType, threshold);
    IField[] fields1 = { 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") };
    List<Tuple> expectedResults = new ArrayList<>();
    expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields1));
    // check the results
    Assert.assertEquals(1, returnedResults.size());
    Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) 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) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) 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