use of edu.uci.ics.textdb.exp.source.scan.ScanSourcePredicate 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.exp.source.scan.ScanSourcePredicate 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.exp.source.scan.ScanSourcePredicate in project textdb by TextDB.
the class OneToNBroadcastConnectorTest method testThreeOutputsWithItself.
/*
* This test tests if the connectors' three outputs are the same.
*/
@Test
public void testThreeOutputsWithItself() throws Exception {
IOperator sourceOperator = new ScanBasedSourceOperator(new ScanSourcePredicate(PEOPLE_TABLE));
OneToNBroadcastConnector connector = new OneToNBroadcastConnector(3);
connector.setInputOperator(sourceOperator);
IOperator output1 = connector.getOutputOperator(0);
IOperator output2 = connector.getOutputOperator(1);
IOperator output3 = connector.getOutputOperator(2);
output1.open();
output2.open();
output3.open();
List<Tuple> output1Results = new ArrayList<>();
Tuple nextTuple = null;
while ((nextTuple = output1.getNextTuple()) != null) {
output1Results.add(nextTuple);
}
List<Tuple> output2Results = new ArrayList<>();
nextTuple = null;
while ((nextTuple = output2.getNextTuple()) != null) {
output2Results.add(nextTuple);
}
List<Tuple> output3Results = new ArrayList<>();
nextTuple = null;
while ((nextTuple = output3.getNextTuple()) != null) {
output3Results.add(nextTuple);
}
output1.close();
output2.close();
output3.close();
List<Tuple> expectedResults = TestConstants.getSamplePeopleTuples();
Assert.assertTrue(TestUtils.equals(expectedResults, output1Results));
Assert.assertTrue(TestUtils.equals(expectedResults, output2Results));
Assert.assertTrue(TestUtils.equals(expectedResults, output3Results));
}
use of edu.uci.ics.textdb.exp.source.scan.ScanSourcePredicate in project textdb by TextDB.
the class PredicateBaseTest method testScanSource.
@Test
public void testScanSource() throws Exception {
ScanSourcePredicate scanSourcePredicate = new ScanSourcePredicate("tableName");
testPredicate(scanSourcePredicate);
}
use of edu.uci.ics.textdb.exp.source.scan.ScanSourcePredicate in project textdb by TextDB.
the class WordCountTest method computePayLoadWordCount.
//Compute result by tuple's PayLoad.
public static HashMap<String, Integer> computePayLoadWordCount(String tableName, String attribute) throws TextDBException {
ScanBasedSourceOperator scanSource = new ScanBasedSourceOperator(new ScanSourcePredicate(tableName));
WordCountOperator wordCount = null;
HashMap<String, Integer> result = new HashMap<String, Integer>();
if (tableName.equals(COUNT_TABLE)) {
wordCount = new WordCountOperator(new WordCountOperatorPredicate(TestConstants.DESCRIPTION, LuceneAnalyzerConstants.standardAnalyzerString()));
} else if (tableName.equals(COUNT_CHINESE_TABLE)) {
wordCount = new WordCountOperator(new WordCountOperatorPredicate(TestConstantsChineseWordCount.DESCRIPTION, LuceneAnalyzerConstants.chineseAnalyzerString()));
}
wordCount.setInputOperator(scanSource);
wordCount.open();
Tuple tuple;
while ((tuple = wordCount.getNextTuple()) != null) {
result.put((String) tuple.getField(WordCountOperator.WORD).getValue(), (Integer) tuple.getField(WordCountOperator.COUNT).getValue());
}
wordCount.close();
return result;
}
Aggregations