use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class DictionaryMatcherTest method testMultipleWordQueryInTextFieldUsingScan1.
/**
* Testcases for scan-based DictionaryMatcher, use getScanSourceResults method only.
* @throws Exception
*/
@Test
public void testMultipleWordQueryInTextFieldUsingScan1() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("tall", "fair"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list = new ArrayList<Span>();
List<Span> list1 = new ArrayList<Span>();
Span span = new Span("description", 0, 4, "tall", "Tall");
Span span1 = new Span("description", 5, 9, "fair", "Fair");
list.add(span);
list1.add(span);
list1.add(span1);
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>(list1) };
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.texera.api.field.StringField in project textdb by TextDB.
the class RegexTestConstantsCorp method getSampleCorpTuples.
public static List<Tuple> getSampleCorpTuples() {
IField[] fields1 = { new StringField("Facebook"), new StringField("404 Not Found"), new StringField("66.220.144.0") };
IField[] fields2 = { new StringField("Weibo"), new StringField("http://weibo.com"), new StringField("180.149.134.141") };
IField[] fields3 = { new StringField("Microsoft"), new StringField("https://www.microsoft.com/en-us/"), new StringField("131.107.0.89") };
IField[] fields4 = { new StringField("Google"), new StringField("websit: www.google.com"), new StringField("8.8.8.8.8.8") };
Tuple tuple1 = new Tuple(SCHEMA_CORP, fields1);
Tuple tuple2 = new Tuple(SCHEMA_CORP, fields2);
Tuple tuple3 = new Tuple(SCHEMA_CORP, fields3);
Tuple tuple4 = new Tuple(SCHEMA_CORP, fields4);
return Arrays.asList(tuple1, tuple2, tuple3, tuple4);
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class BarChartSinkTestConstants method getResultTuples.
public static List<Tuple> getResultTuples() {
IField[] fields1 = { new StringField("Tom"), new IntegerField(90) };
IField[] fields2 = { new StringField("Jerry"), new IntegerField(80) };
IField[] fields3 = { new StringField("Bob"), new IntegerField(70) };
Tuple tuple1 = new Tuple(BAR_RESULT_SCHEMA, fields1);
Tuple tuple2 = new Tuple(BAR_RESULT_SCHEMA, fields2);
Tuple tuple3 = new Tuple(BAR_RESULT_SCHEMA, fields3);
return Arrays.asList(tuple1, tuple2, tuple3);
}
use of edu.uci.ics.texera.api.field.StringField 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(excelSink.getFilePath());
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class MysqlSinkTest method testTupleListInsertion.
/**
* Create 10000 tuples with all regular fields
* Insert into mysql database
*/
public void testTupleListInsertion() 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 localInputOperator = Mockito.mock(IOperator.class);
Mockito.when(localInputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes));
OngoingStubbing<Tuple> stubbing = Mockito.when(localInputOperator.getNextTuple());
for (Tuple t : tupleList) {
stubbing = stubbing.thenReturn(t);
}
stubbing = stubbing.thenReturn(null);
mysqlSink.setInputOperator(localInputOperator);
mysqlSink.open();
mysqlSink.processTuples();
mysqlSink.close();
}
Aggregations