use of edu.uci.ics.texera.api.field.TextField in project textdb by TextDB.
the class JoinDistanceTest method testQueryHasResultsOverMultipleFields.
/*
* This case tests for the scenario when the query has results over multiple
* fields and join has to be performed only on the field mentioned in the attribute.
*
* Test result: Join should return only those tuples which satisfy all the constraints.
*/
@Test
public void testQueryHasResultsOverMultipleFields() throws Exception {
List<Tuple> tuples = JoinTestConstants.bookGroup1.subList(1, 5);
JoinTestHelper.insertToTable(BOOK_TABLE, tuples);
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "typical", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "actually", conjunction);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 90), Integer.MAX_VALUE, 0);
Schema resultSchema = new Schema.Builder().add(JoinTestConstants.BOOK_SCHEMA).add(SchemaConstants.SPAN_LIST_ATTRIBUTE).build();
List<Span> spanList = new ArrayList<>();
Span span1 = new Span(JoinTestConstants.REVIEW, 28, 119, "typical_actually", "typical review. " + "This is a test. A book review test. " + "A test to test queries without actually");
spanList.add(span1);
Span span2 = new Span(JoinTestConstants.REVIEW, 186, 234, "typical_actually", "actually a review " + "even if it is not your typical");
spanList.add(span2);
IField[] book1 = { new IntegerField(51), new StringField("author unknown"), new StringField("typical"), new IntegerField(300), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
IField[] book2 = { new IntegerField(53), new StringField("Noah Hawley"), new StringField("Before the Fall"), new IntegerField(400), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
IField[] book3 = { new IntegerField(54), new StringField("Andria Williams"), new StringField("The Longest Night: A Novel"), new IntegerField(400), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
IField[] book4 = { new IntegerField(55), new StringField("Matti Friedman"), new StringField("Pumpkinflowers: A Soldier's " + "Story"), new IntegerField(256), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
Tuple expectedTuple1 = new Tuple(resultSchema, book1);
Tuple expectedTuple2 = new Tuple(resultSchema, book2);
Tuple expectedTuple3 = new Tuple(resultSchema, book3);
Tuple expectedTuple4 = new Tuple(resultSchema, book4);
List<Tuple> expectedResult = new ArrayList<>();
expectedResult.add(expectedTuple1);
expectedResult.add(expectedTuple2);
expectedResult.add(expectedTuple3);
expectedResult.add(expectedTuple4);
Assert.assertEquals(4, resultList.size());
Assert.assertTrue(TestUtils.equals(expectedResult, resultList));
}
use of edu.uci.ics.texera.api.field.TextField in project textdb by TextDB.
the class JoinDistanceTest method testForLimitWhenLimitIsLesserThanActualNumberOfResultsAndHasOffset.
/*
* This case tests for the scenario when limit is some integer greater than
* 0 and less than the actual number of results and offset is some integer
* greater than 0 and less than actual number of results and join is
* performed.
* Test result: A list of tuples with number of tuples equal to limit
* starting from the set offset.
*/
@Test
public void testForLimitWhenLimitIsLesserThanActualNumberOfResultsAndHasOffset() throws Exception {
List<Tuple> tuples = JoinTestConstants.bookGroup1.subList(1, 5);
JoinTestHelper.insertToTable(BOOK_TABLE, tuples);
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "typical", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "actually", conjunction);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 90), 1, 2);
Schema resultSchema = new Schema.Builder().add(JoinTestConstants.BOOK_SCHEMA).add(SchemaConstants.SPAN_LIST_ATTRIBUTE).build();
List<Span> spanList = new ArrayList<>();
Span span1 = new Span(JoinTestConstants.REVIEW, 28, 119, "typical_actually", "typical review. " + "This is a test. A book review test. " + "A test to test queries without actually");
spanList.add(span1);
Span span2 = new Span(JoinTestConstants.REVIEW, 186, 234, "typical_actually", "actually a review " + "even if it is not your typical");
spanList.add(span2);
IField[] book1 = { new IntegerField(54), new StringField("Andria Williams"), new StringField("The Longest Night: A Novel"), new IntegerField(400), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
Tuple expectedTuple1 = new Tuple(resultSchema, book1);
List<Tuple> expectedResult = new ArrayList<>(1);
expectedResult.add(expectedTuple1);
Assert.assertEquals(1, resultList.size());
Assert.assertTrue(TestUtils.equals(expectedResult, resultList));
}
use of edu.uci.ics.texera.api.field.TextField in project textdb by TextDB.
the class JoinDistanceTest method testBothOperatorsMultipleTuplesSpanWithinThreshold.
// --------------------<END of single tuple test cases>--------------------
/*
* This case tests for the scenario when both the operators' have multiple
* tuples and spans are within threshold.
*
* Test result: Join should result in a list containing tuples with spans.
* The number of tuples is equal to the number of tuples with spans within threshold.
*/
@Test
public void testBothOperatorsMultipleTuplesSpanWithinThreshold() throws Exception {
List<Tuple> tuples = new ArrayList<>();
tuples.add(JoinTestConstants.bookGroup1.get(3));
tuples.add(JoinTestConstants.bookGroup2.get(2));
tuples.add(JoinTestConstants.bookGroup2.get(4));
JoinTestHelper.insertToTable(BOOK_TABLE, tuples);
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "review", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "book", conjunction);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 12), Integer.MAX_VALUE, 0);
Schema resultSchema = new Schema.Builder().add(JoinTestConstants.BOOK_SCHEMA).add(SchemaConstants.SPAN_LIST_ATTRIBUTE).build();
List<Span> spanList = new ArrayList<>();
Span span1 = new Span(JoinTestConstants.REVIEW, 0, 16, "review_book", "Review of a " + "Book");
spanList.add(span1);
Span span2 = new Span(JoinTestConstants.REVIEW, 62, 73, "review_book", "book review");
spanList.add(span2);
Span span3 = new Span(JoinTestConstants.REVIEW, 235, 246, "review_book", "book review");
spanList.add(span3);
IField[] book1 = { new IntegerField(54), new StringField("Andria Williams"), new StringField("The Longest Night: A Novel"), new IntegerField(400), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
IField[] book2 = { new IntegerField(65), new StringField("Sharon Guskin"), new StringField("The Forgetting Time: A Novel"), new IntegerField(368), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
IField[] book3 = { new IntegerField(63), new StringField("Paul Kalanithi"), new StringField("When Breath Becomes Air"), new IntegerField(256), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
Tuple expectedTuple1 = new Tuple(resultSchema, book1);
Tuple expectedTuple2 = new Tuple(resultSchema, book2);
Tuple expectedTuple3 = new Tuple(resultSchema, book3);
List<Tuple> expectedResult = new ArrayList<>();
expectedResult.add(expectedTuple1);
expectedResult.add(expectedTuple2);
expectedResult.add(expectedTuple3);
Assert.assertEquals(3, resultList.size());
Assert.assertTrue(TestUtils.equals(expectedResult, resultList));
}
use of edu.uci.ics.texera.api.field.TextField in project textdb by TextDB.
the class AsterixSource method getNextTuple.
@Override
public Tuple getNextTuple() throws TexeraException {
if (cursor == CLOSED) {
throw new DataflowException(ErrorMessages.OPERATOR_NOT_OPENED);
}
if (cursor < resultJsonArray.length()) {
Tuple tuple = new Tuple(ATERIX_SOURCE_SCHEMA, IDField.newRandomID(), new TextField(resultJsonArray.getJSONObject(cursor).get("ds").toString()));
cursor++;
return tuple;
}
return null;
}
use of edu.uci.ics.texera.api.field.TextField in project textdb by TextDB.
the class FileSourceOperator method getNextTuple.
@Override
public Tuple getNextTuple() throws TexeraException {
if (cursor == CLOSED || cursor >= pathList.size()) {
return null;
}
// 2) the cursor reaches the end
while (cursor < pathList.size()) {
try {
Path path = pathIterator.next();
String extension = com.google.common.io.Files.getFileExtension(path.toString());
String content;
if (extension.equalsIgnoreCase("pdf")) {
content = FileExtractorUtils.extractPDFFile(path);
} else if (extension.equalsIgnoreCase("ppt") || extension.equalsIgnoreCase("pptx")) {
content = FileExtractorUtils.extractPPTFile(path);
} else if (extension.equalsIgnoreCase("doc") || extension.equalsIgnoreCase("docx")) {
content = FileExtractorUtils.extractWordFile(path);
} else {
content = FileExtractorUtils.extractPlainTextFile(path);
}
Tuple tuple = new Tuple(outputSchema, IDField.newRandomID(), new TextField(content));
cursor++;
return tuple;
} catch (DataflowException e) {
// ignore error and move on
// TODO: use log4j
System.out.println("FileSourceOperator: file read error, file is ignored. " + e.getMessage());
}
}
return null;
}
Aggregations