use of edu.uci.ics.textdb.api.field.DoubleField 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));
}
use of edu.uci.ics.textdb.api.field.DoubleField 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));
}
use of edu.uci.ics.textdb.api.field.DoubleField in project textdb by TextDB.
the class ExcelSinkTest method writeSampleExcelFile.
/**
* Create two tuples, write into a excel file. Need to manually delete the generated file.
* @throws ParseException
*/
@Test
public void writeSampleExcelFile() throws Exception {
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 span1 = new Span("firstName", 0, 5, "bruce", "bruce");
Span span2 = new Span("lastnName", 0, 5, "jacki", "jacki");
list.add(span1);
list.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] = SchemaConstants.SPAN_LIST_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<>(list) };
IField[] fields2 = { new StringField("test"), new StringField("jackie chan"), new IntegerField(0), new DoubleField(6.0), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("09-18-1994")), new TextField("Angry Bird"), new ListField<>(list) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
IOperator inputOperator = Mockito.mock(IOperator.class);
Mockito.when(inputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes)).thenReturn(null);
Mockito.when(inputOperator.getNextTuple()).thenReturn(tuple1).thenReturn(tuple2).thenReturn(null);
excelSink = new ExcelSink(new ExcelSinkPredicate());
excelSink.setInputOperator(inputOperator);
excelSink.open();
excelSink.collectAllTuples();
excelSink.close();
Files.deleteIfExists(Paths.get(excelSink.getFilePath()));
}
use of edu.uci.ics.textdb.api.field.DoubleField in project textdb by TextDB.
the class DictionaryMatcherTest method testSingleWordQueryInTextFieldUsingScan.
/**
* Scenario S-5:verifies GetNextTuple of DictionaryMatcher and single word
* queries in Text Field using SCANOPERATOR
*/
@Test
public void testSingleWordQueryInTextFieldUsingScan() 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");
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.SUBSTRING_SCANBASED);
boolean contains = TestUtils.equals(expectedResults, returnedResults);
Assert.assertTrue(contains);
}
use of edu.uci.ics.textdb.api.field.DoubleField in project textdb by TextDB.
the class DictionaryMatcherTest method testWordInMultipleFieldsQueryUsingScan.
/**
* Scenario S-11:verifies: data source has multiple attributes, and an
* entity can appear in all the fields and multiple times using SUBSTRING_SCANBASE
* OPERATOR.
*/
@Test
public void testWordInMultipleFieldsQueryUsingScan() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("lin clooney"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list = new ArrayList<Span>();
Span span1 = new Span("lastName", 0, 11, "lin clooney", "lin clooney");
Span span2 = new Span("description", 0, 11, "lin clooney", "Lin Clooney");
Span span3 = new Span("description", 25, 36, "lin clooney", "lin clooney");
list.add(span1);
list.add(span2);
list.add(span3);
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);
}
Aggregations