Search in sources :

Example 86 with IField

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

the class ComparableMatcherTest method testIntegerMatching6.

/**
     * Verifies the behavior of ComparableMatcher<Integer> with matching type NOT_EQAUL_TO
     *
     * @throws Exception
     */
@Test
public void testIntegerMatching6() throws Exception {
    // Prepare the query
    int threshold = 43;
    Attribute attribute = TestConstants.AGE_ATTR;
    String attributeName = attribute.getAttributeName();
    ComparisonType matchingType = ComparisonType.NOT_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") };
    IField[] fields3 = { 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") };
    IField[] fields4 = { 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") };
    IField[] fields5 = { 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") };
    List<Tuple> expectedResults = new ArrayList<>();
    expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields1));
    expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields2));
    expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields3));
    expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields4));
    expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields5));
    // check the results
    Assert.assertEquals(5, 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 87 with IField

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

the class DictionaryMatcherTest method testMultipleWordsQueryUsingPhrase.

/**
     * Scenario S-10:verifies ITuple returned by DictionaryMatcher and multiple
     * word queries using PHRASE OPERATOR
     */
@Test
public void testMultipleWordsQueryUsingPhrase() 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.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 88 with IField

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

the class DictionaryMatcherTest method testMatchingWithLimit.

public void testMatchingWithLimit() throws Exception {
    ArrayList<String> word = new ArrayList<String>(Arrays.asList("angry"));
    Dictionary dictionary = new Dictionary(word);
    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;
    Span span1 = new Span("description", 5, 10, "angry", "Angry", 1);
    Span span2 = new Span("description", 6, 11, "angry", "Angry", 1);
    Span span3 = new Span("description", 40, 45, "angry", "Angry", 8);
    Span span4 = new Span("description", 6, 11, "angry", "angry", 1);
    List<Span> list1 = new ArrayList<>();
    list1.add(span1);
    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<>(list1) };
    List<Span> list2 = new ArrayList<>();
    list2.add(span2);
    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<>(list2) };
    List<Span> list3 = new ArrayList<>();
    list3.add(span3);
    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<>(list3) };
    List<Span> list4 = new ArrayList<>();
    list4.add(span4);
    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<>(list4) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
    Tuple tuple3 = new Tuple(new Schema(schemaAttributes), fields3);
    Tuple tuple4 = new Tuple(new Schema(schemaAttributes), fields4);
    List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
    List<Tuple> expectedList = new ArrayList<>();
    List<Tuple> resultList = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_TABLE, dictionary, attributeNames, KeywordMatchingType.PHRASE_INDEXBASED, 3, 0);
    expectedList.add(tuple1);
    expectedList.add(tuple2);
    expectedList.add(tuple3);
    expectedList.add(tuple4);
    Assert.assertEquals(expectedList.size(), 4);
    Assert.assertEquals(resultList.size(), 3);
    Assert.assertTrue(expectedList.containsAll(resultList));
}
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)

Example 89 with IField

use of edu.uci.ics.textdb.api.field.IField 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);
}
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 90 with IField

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

the class WordCountOperator method computeNextMatchingTuple.

@Override
protected Tuple computeNextMatchingTuple() throws TextDBException {
    if (sortedWordCountMap == null) {
        computeWordCount();
    }
    if (wordCountIterator.hasNext()) {
        Entry<String, Integer> entry = wordCountIterator.next();
        List<IField> tupleFieldList = new ArrayList<>();
        // Generate the new UUID.
        tupleFieldList.add(IDField.newRandomID());
        tupleFieldList.add(new StringField(entry.getKey()));
        tupleFieldList.add(new IntegerField(entry.getValue()));
        return new Tuple(outputSchema, tupleFieldList);
    }
    return null;
}
Also used : StringField(edu.uci.ics.textdb.api.field.StringField) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Aggregations

IField (edu.uci.ics.textdb.api.field.IField)140 ArrayList (java.util.ArrayList)110 TextField (edu.uci.ics.textdb.api.field.TextField)105 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)102 Schema (edu.uci.ics.textdb.api.schema.Schema)90 Span (edu.uci.ics.textdb.api.span.Span)85 StringField (edu.uci.ics.textdb.api.field.StringField)84 Attribute (edu.uci.ics.textdb.api.schema.Attribute)84 Test (org.junit.Test)84 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)80 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)68 DateField (edu.uci.ics.textdb.api.field.DateField)64 SimpleDateFormat (java.text.SimpleDateFormat)63 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)24 ListField (edu.uci.ics.textdb.api.field.ListField)16 JoinDistancePredicate (edu.uci.ics.textdb.exp.join.JoinDistancePredicate)9 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)9 AttributeType (edu.uci.ics.textdb.api.schema.AttributeType)5 IOperator (edu.uci.ics.textdb.api.dataflow.IOperator)4 StorageException (edu.uci.ics.textdb.api.exception.StorageException)4