use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class RegexMatcherTestHelper method getRegexSourceResults.
public static List<Tuple> getRegexSourceResults(String tableName, String regex, List<String> attributeNames, int limit, int offset) throws TextDBException {
RegexSourcePredicate regexSourcePredicate = new RegexSourcePredicate(regex, attributeNames, tableName, RESULTS);
RegexMatcherSourceOperator regexSource = new RegexMatcherSourceOperator(regexSourcePredicate);
regexSource.setLimit(limit);
regexSource.setOffset(offset);
Tuple tuple;
List<Tuple> results = new ArrayList<>();
regexSource.open();
while ((tuple = regexSource.getNextTuple()) != null) {
results.add(tuple);
}
regexSource.close();
return results;
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class NlpEntityTest method getQueryResults.
public List<Tuple> getQueryResults(String tableName, List<String> attributeNames, NlpEntityType nlpEntityType, int limit, int offset) throws Exception {
ScanBasedSourceOperator scanSource = new ScanBasedSourceOperator(new ScanSourcePredicate(tableName));
NlpEntityPredicate nlpEntityPredicate = new NlpEntityPredicate(nlpEntityType, attributeNames, RESULTS);
NlpEntityOperator nlpEntityOperator = new NlpEntityOperator(nlpEntityPredicate);
nlpEntityOperator.setInputOperator(scanSource);
nlpEntityOperator.setLimit(limit);
nlpEntityOperator.setOffset(offset);
Tuple nextTuple = null;
List<Tuple> results = new ArrayList<Tuple>();
nlpEntityOperator.open();
while ((nextTuple = nlpEntityOperator.getNextTuple()) != null) {
results.add(nextTuple);
}
nlpEntityOperator.close();
return results;
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class NlpEntityTest method getNextTupleTestWithLimit.
public void getNextTupleTestWithLimit() throws Exception {
List<Tuple> data = NlpEntityTestConstants.getOneSentenceTestTuple();
DataWriter oneSentenceDataWriter = RelationManager.getRelationManager().getTableDataWriter(ONE_SENTENCE_TABLE);
oneSentenceDataWriter.open();
for (Tuple tuple : data) {
oneSentenceDataWriter.insertTuple(tuple);
}
oneSentenceDataWriter.close();
String attribute1 = NlpEntityTestConstants.SENTENCE_ONE;
List<String> attributeNames = Arrays.asList(attribute1);
List<Tuple> returnedResults = getQueryResults(ONE_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL, 3, 0);
List<Tuple> expectedResults = NlpEntityTestConstants.getTest10ResultTuples();
// ExpectedResults is the array containing all the matches.
// Since the order of returning records in returnedResults is not deterministic, we use containsAll
// to ensure that the records in returnedResults are included in the ExpectedResults.
Assert.assertEquals(returnedResults.size(), 3);
Assert.assertTrue(TestUtils.containsAll(expectedResults, returnedResults));
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class ProjectionOperatorTest method testProjection1.
@Test
public void testProjection1() throws Exception {
List<String> projectionFields = Arrays.asList(TestConstants.DESCRIPTION);
Schema projectionSchema = new Schema(TestConstants.DESCRIPTION_ATTR);
IField[] fields1 = { new TextField("Tall Angry") };
IField[] fields2 = { new TextField("Short Brown") };
IField[] fields3 = { new TextField("White Angry") };
IField[] fields4 = { new TextField("Lin Clooney is Short and lin clooney is Angry") };
IField[] fields5 = { new TextField("Tall Fair") };
IField[] fields6 = { new TextField("Short angry") };
Tuple tuple1 = new Tuple(projectionSchema, fields1);
Tuple tuple2 = new Tuple(projectionSchema, fields2);
Tuple tuple3 = new Tuple(projectionSchema, fields3);
Tuple tuple4 = new Tuple(projectionSchema, fields4);
Tuple tuple5 = new Tuple(projectionSchema, fields5);
Tuple tuple6 = new Tuple(projectionSchema, fields6);
List<Tuple> expectedResults = Arrays.asList(tuple1, tuple2, tuple3, tuple4, tuple5, tuple6);
List<Tuple> returnedResults = getProjectionResults(new ScanBasedSourceOperator(new ScanSourcePredicate(PEOPLE_TABLE)), projectionFields);
Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class RegexMatcherTest method testRegexWithLimitOffset.
@Test
public void testRegexWithLimitOffset() throws Exception {
String query = "patient";
List<Tuple> exactResultsWithLimitOffset = RegexMatcherTestHelper.getQueryResults(TEXT_TABLE, query, Arrays.asList(RegexTestConstantsText.CONTENT), true, 2, 1);
List<Tuple> expectedResults = new ArrayList<Tuple>();
List<Tuple> data = RegexTestConstantsText.getSampleTextTuples();
Schema spanSchema = Utils.addAttributeToSchema(RegexTestConstantsText.SCHEMA_TEXT, new Attribute(RESULTS, AttributeType.LIST));
List<Span> spans = new ArrayList<Span>();
spans.add(new Span(RegexTestConstantsText.CONTENT, 4, 11, query, "patient"));
IField spanField = new ListField<Span>(new ArrayList<Span>(spans));
List<IField> fields = new ArrayList<IField>(data.get(4).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
spans.clear();
fields.clear();
spans.add(new Span(RegexTestConstantsText.CONTENT, 4, 11, query, "patient"));
spans.add(new Span(RegexTestConstantsText.CONTENT, 65, 72, query, "patient"));
spanField = new ListField<Span>(new ArrayList<Span>(spans));
fields = new ArrayList<IField>(data.get(5).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
spans.clear();
fields.clear();
spans.add(new Span(RegexTestConstantsText.CONTENT, 4, 11, query, "patient"));
spanField = new ListField<Span>(new ArrayList<Span>(spans));
fields = new ArrayList<IField>(data.get(6).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
Assert.assertTrue(TestUtils.containsAll(expectedResults, exactResultsWithLimitOffset));
Assert.assertEquals(expectedResults.size(), 3);
Assert.assertEquals(exactResultsWithLimitOffset.size(), 2);
}
Aggregations