use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class TwitterConverter method getNextTuple.
@Override
public Tuple getNextTuple() throws TexeraException {
if (cursor == CLOSED) {
throw new DataflowException(ErrorMessages.OPERATOR_NOT_OPENED);
}
Tuple tuple;
while ((tuple = inputOperator.getNextTuple()) != null) {
List<IField> tweetFields = generateFieldsFromJson(tuple.getField(rawDataAttribute).getValue().toString());
if (!tweetFields.isEmpty()) {
cursor++;
List<IField> tupleFields = new ArrayList<>();
final Tuple finalTuple = tuple;
tupleFields.addAll(tuple.getSchema().getAttributeNames().stream().filter(attrName -> !attrName.equalsIgnoreCase(rawDataAttribute)).map(attrName -> finalTuple.getField(attrName, IField.class)).collect(Collectors.toList()));
tupleFields.addAll(tweetFields);
return new Tuple(outputSchema, tupleFields);
}
}
return null;
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class NltkSentimentOperator method popupOneTuple.
private Tuple popupOneTuple() {
Tuple outputTuple = tupleBuffer.get(0);
tupleBuffer.remove(0);
if (tupleBuffer.isEmpty()) {
tupleBuffer = null;
}
List<IField> outputFields = new ArrayList<>();
outputFields.addAll(outputTuple.getFields());
Integer className = idClassMap.get(outputTuple.getField(SchemaConstants._ID).getValue().toString());
outputFields.add(new IntegerField(className));
return new Tuple(outputSchema, outputFields);
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class NltkSentimentOperatorTest method test1.
/*
* Test sentiment test result should be positive.
*/
@Test
public void test1() throws TexeraException {
TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(NltkSentimentTestConstants.POSITIVE_TUPLE), NlpSentimentTestConstants.SENTIMENT_SCHEMA);
NltkSentimentOperator nltkSentimentOperator = new NltkSentimentOperator(new NltkSentimentOperatorPredicate(NlpSentimentTestConstants.TEXT, "sentiment", BATCH_SIZE, MODEL_FILE_NAME));
TupleSink tupleSink = new TupleSink();
nltkSentimentOperator.setInputOperator(tupleSource);
tupleSink.setInputOperator(nltkSentimentOperator);
tupleSink.open();
List<Tuple> results = tupleSink.collectAllTuples();
tupleSink.close();
Tuple tuple = results.get(0);
Assert.assertEquals(tuple.getField("sentiment").getValue(), SentimentConstants.POSITIVE);
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class NltkSentimentOperatorTest method test2.
/*
* Test sentiment test result should be negative
*/
@Test
public void test2() throws TexeraException {
TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(NltkSentimentTestConstants.NEGATIVE_TUPLE), NlpSentimentTestConstants.SENTIMENT_SCHEMA);
NltkSentimentOperator nltkSentimentOperator = new NltkSentimentOperator(new NltkSentimentOperatorPredicate(NltkSentimentTestConstants.TEXT, "sentiment", BATCH_SIZE, MODEL_FILE_NAME));
TupleSink tupleSink = new TupleSink();
nltkSentimentOperator.setInputOperator(tupleSource);
tupleSink.setInputOperator(nltkSentimentOperator);
tupleSink.open();
List<Tuple> results = tupleSink.collectAllTuples();
tupleSink.close();
Tuple tuple = results.get(0);
Assert.assertEquals(tuple.getField("sentiment").getValue(), SentimentConstants.NEGATIVE);
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class FileSourceOperatorTest method test4.
/*
* Test FileSourceOperator with a Directory with recursive = true and maxDepth = 2.
*
* The files under the recursive sub-directories with recursive depth 2 will be read.
*
* expected results: test1.txt, test2.txt and test4.txt will be included
*/
@Test
public void test4() throws Exception {
String attrName = "content";
Schema schema = new Schema(new Attribute(attrName, AttributeType.TEXT));
FileSourcePredicate predicate = new FileSourcePredicate(tempFolderPath.toString(), attrName, true, 2);
FileSourceOperator fileSource = new FileSourceOperator(predicate);
Tuple tuple;
ArrayList<Tuple> exactResults = new ArrayList<>();
fileSource.open();
while ((tuple = fileSource.getNextTuple()) != null) {
exactResults.add(tuple);
}
fileSource.close();
List<Tuple> expectedResults = Arrays.asList(new Tuple(schema, new TextField(tempFile1String)), new Tuple(schema, new TextField(tempFile2String)), new Tuple(schema, new TextField(tempFile4String)));
Assert.assertTrue(TestUtils.equals(expectedResults, exactResults));
}
Aggregations