Search in sources :

Example 6 with Attribute

use of edu.uci.ics.texera.api.schema.Attribute 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.getName();
    ComparisonType matchingType = ComparisonType.NOT_EQUAL_TO;
    // Perform the query
    List<Tuple> returnedResults = getQueryResults(attributeName, matchingType, threshold);
    List<Tuple> expectedResults = new ArrayList<>();
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(0));
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(1));
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(2));
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(4));
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(5));
    // check the results
    Assert.assertEquals(expectedResults.size(), returnedResults.size());
    Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) ArrayList(java.util.ArrayList) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 7 with Attribute

use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.

the class ComparableMatcherTest method testIntegerMatching4.

/**
 * Verifies the behavior of ComparableMatcher<Integer> with matching type LESS_THAN_OR_EQAUL_TO
 *
 * @throws Exception
 */
@Test
public void testIntegerMatching4() throws Exception {
    // Prepare the query
    int threshold = 43;
    Attribute attribute = TestConstants.AGE_ATTR;
    String attributeName = attribute.getName();
    ComparisonType matchingType = ComparisonType.LESS_THAN_OR_EQUAL_TO;
    // Perform the query
    List<Tuple> returnedResults = getQueryResults(attributeName, matchingType, threshold);
    List<Tuple> expectedResults = new ArrayList<>();
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(3));
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(4));
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(5));
    // check the results
    Assert.assertEquals(expectedResults.size(), returnedResults.size());
    Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) ArrayList(java.util.ArrayList) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 8 with Attribute

use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.

the class ComparableMatcherTest method testIntegerMatching5.

/**
 * Verifies the behavior of ComparableMatcher<Integer> with matching type LESS_THAN
 *
 * @throws Exception
 */
@Test
public void testIntegerMatching5() throws Exception {
    // Prepare the query
    int threshold = 43;
    Attribute attribute = TestConstants.AGE_ATTR;
    String attributeName = attribute.getName();
    ComparisonType matchingType = ComparisonType.LESS_THAN;
    // Perform the query
    List<Tuple> returnedResults = getQueryResults(attributeName, matchingType, threshold);
    List<Tuple> expectedResults = new ArrayList<>();
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(4));
    expectedResults.add(TestConstants.getSamplePeopleTuples().get(5));
    // check the results
    Assert.assertEquals(expectedResults.size(), returnedResults.size());
    Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) ArrayList(java.util.ArrayList) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 9 with Attribute

use of edu.uci.ics.texera.api.schema.Attribute 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>();
    Span span1 = new Span("lastName", 0, 8, "john Lee", "john Lee");
    Span span2 = new Span("firstName", 0, 5, "bruce", "bruce");
    list1.add(span1);
    list1.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);
    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.texera.dataflow.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 10 with Attribute

use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.

the class DictionaryMatcherTest method testSingleWordQueryInTextFieldUsingKeyword.

/**
 * Scenario: verifies GetNextTuple of DictionaryMatcher and single word
 * queries in Text Field using KEYWORD OPERATOR
 */
@Test
public void testSingleWordQueryInTextFieldUsingKeyword() throws Exception {
    ArrayList<String> names = new ArrayList<String>(Arrays.asList("tall"));
    Dictionary dictionary = new Dictionary(names);
    // create a data tuple first
    List<Span> list = new ArrayList<Span>();
    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] = 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) };
    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<Span>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    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.CONJUNCTION_INDEXBASED);
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : Dictionary(edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

Attribute (edu.uci.ics.texera.api.schema.Attribute)98 Test (org.junit.Test)81 Tuple (edu.uci.ics.texera.api.tuple.Tuple)78 ArrayList (java.util.ArrayList)76 Schema (edu.uci.ics.texera.api.schema.Schema)75 IField (edu.uci.ics.texera.api.field.IField)60 StringField (edu.uci.ics.texera.api.field.StringField)56 TextField (edu.uci.ics.texera.api.field.TextField)56 IntegerField (edu.uci.ics.texera.api.field.IntegerField)54 DoubleField (edu.uci.ics.texera.api.field.DoubleField)53 Span (edu.uci.ics.texera.api.span.Span)51 DateField (edu.uci.ics.texera.api.field.DateField)50 SimpleDateFormat (java.text.SimpleDateFormat)47 Dictionary (edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary)28 AttributeType (edu.uci.ics.texera.api.schema.AttributeType)9 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)8 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)6 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)5