Search in sources :

Example 26 with DateField

use of edu.uci.ics.textdb.api.field.DateField 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 27 with DateField

use of edu.uci.ics.textdb.api.field.DateField 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)

Example 28 with DateField

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

the class ComparableMatcherTest method testIntegerMatching2.

/**
     * Verifies the behavior of ComparableMatcher<Integer> with matching type GREATER_THAN
     *
     * @throws Exception
     */
@Test
public void testIntegerMatching2() throws Exception {
    // Prepare the query
    int threshold = 45;
    Attribute attribute = TestConstants.AGE_ATTR;
    String attributeName = attribute.getAttributeName();
    ComparisonType matchingType = ComparisonType.GREATER_THAN;
    // 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") };
    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)

Example 29 with DateField

use of edu.uci.ics.textdb.api.field.DateField 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.getAttributeName();
    ComparisonType matchingType = ComparisonType.LESS_THAN_OR_EQUAL_TO;
    // Perform the query
    List<Tuple> returnedResults = getIntegerQueryResults(attributeName, matchingType, threshold);
    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") };
    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") };
    IField[] fields3 = { 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));
    // check the results
    Assert.assertEquals(3, 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 DateField

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

the class ExcelSinkTest method attributeTypeTest.

@Test
public // writing 10000 tuples
void attributeTypeTest() throws Exception {
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstants.FIRST_NAME);
    attributeNames.add(TestConstants.LAST_NAME);
    attributeNames.add(TestConstants.AGE);
    attributeNames.add(TestConstants.HEIGHT);
    attributeNames.add(TestConstants.DATE_OF_BIRTH);
    attributeNames.add(TestConstants.DESCRIPTION);
    // Prepare Schema
    Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length];
    for (int count = 0; count < schemaAttributes.length; count++) {
        schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
    }
    // Prepare 10000 tuples as a tupleList
    int testSize = 10000;
    Random rand = new Random();
    List<Tuple> tupleList = new ArrayList<Tuple>();
    for (int i = 0; i < testSize; i++) {
        IField[] fields = { new StringField(getRandomString()), new StringField(getRandomString()), new IntegerField(rand.nextInt()), new DoubleField(rand.nextDouble() * rand.nextInt()), new DateField(getRandomDate()), new TextField(getRandomString()) };
        tupleList.add(new Tuple(new Schema(schemaAttributes), fields));
    }
    assert (tupleList.size() == testSize);
    IOperator inputOperator = Mockito.mock(IOperator.class);
    Mockito.when(inputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes));
    OngoingStubbing<Tuple> stubbing = Mockito.when(inputOperator.getNextTuple());
    for (Tuple t : tupleList) {
        stubbing = stubbing.thenReturn(t);
    }
    stubbing = stubbing.thenReturn(null);
    // excel writing test
    excelSink = new ExcelSink(new ExcelSinkPredicate());
    excelSink.setInputOperator(inputOperator);
    excelSink.open();
    excelSink.collectAllTuples();
    excelSink.close();
    Files.deleteIfExists(Paths.get(excelSink.getFilePath()));
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) 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) Random(java.util.Random) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Test(org.junit.Test)

Aggregations

DateField (edu.uci.ics.textdb.api.field.DateField)65 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 IField (edu.uci.ics.textdb.api.field.IField)64 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)64 StringField (edu.uci.ics.textdb.api.field.StringField)64 TextField (edu.uci.ics.textdb.api.field.TextField)64 SimpleDateFormat (java.text.SimpleDateFormat)63 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)61 ArrayList (java.util.ArrayList)60 Test (org.junit.Test)60 Attribute (edu.uci.ics.textdb.api.schema.Attribute)53 Schema (edu.uci.ics.textdb.api.schema.Schema)48 Span (edu.uci.ics.textdb.api.span.Span)46 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)24 ParseException (java.text.ParseException)4 IOperator (edu.uci.ics.textdb.api.dataflow.IOperator)2 ListField (edu.uci.ics.textdb.api.field.ListField)1 Date (java.util.Date)1 Random (java.util.Random)1