Search in sources :

Example 1 with TupleSourceOperator

use of edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator in project textdb by TextDB.

the class EmojiSentimentTest method test5.

@Test
public void test5() throws TexeraException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(EmojiSentimentTestConstants.NEGATIVE_TUPLE2), EmojiSentimentTestConstants.SENTIMENT_SCHEMA);
    EmojiSentimentOperator sentiment = new EmojiSentimentOperator(new EmojiSentimentPredicate(NlpSentimentTestConstants.TEXT, "sentiment"));
    TupleSink tupleSink = new TupleSink();
    sentiment.setInputOperator(tupleSource);
    tupleSink.setInputOperator(sentiment);
    tupleSink.open();
    List<Tuple> results = tupleSink.collectAllTuples();
    tupleSink.close();
    Tuple tuple = results.get(0);
    Assert.assertEquals(tuple.getField("sentiment").getValue(), SentimentConstants.NEGATIVE);
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 2 with TupleSourceOperator

use of edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator in project textdb by TextDB.

the class EmojiSentimentTest method test4.

@Test
public void test4() throws TexeraException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(EmojiSentimentTestConstants.POSITIVE_TUPLE2), EmojiSentimentTestConstants.SENTIMENT_SCHEMA);
    EmojiSentimentOperator sentiment = new EmojiSentimentOperator(new EmojiSentimentPredicate(EmojiSentimentTestConstants.TEXT, "sentiment"));
    TupleSink tupleSink = new TupleSink();
    sentiment.setInputOperator(tupleSource);
    tupleSink.setInputOperator(sentiment);
    tupleSink.open();
    List<Tuple> results = tupleSink.collectAllTuples();
    tupleSink.close();
    Tuple tuple = results.get(0);
    Assert.assertEquals(tuple.getField("sentiment").getValue(), SentimentConstants.POSITIVE);
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 3 with TupleSourceOperator

use of edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator in project textdb by TextDB.

the class NlpSentimentTest method test1.

/*
     * Test sentiment with a positive sentence, result should be 3 (positive)
     */
@Test
public void test1() throws TexeraException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(NlpSentimentTestConstants.POSITIVE_TUPLE), NlpSentimentTestConstants.SENTIMENT_SCHEMA);
    NlpSentimentOperator sentiment = new NlpSentimentOperator(new NlpSentimentPredicate(NlpSentimentTestConstants.TEXT, "sentiment"));
    TupleSink tupleSink = new TupleSink();
    sentiment.setInputOperator(tupleSource);
    tupleSink.setInputOperator(sentiment);
    tupleSink.open();
    List<Tuple> results = tupleSink.collectAllTuples();
    tupleSink.close();
    Tuple tuple = results.get(0);
    Assert.assertEquals(tuple.getField("sentiment").getValue(), SentimentConstants.POSITIVE);
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 4 with TupleSourceOperator

use of edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator in project textdb by TextDB.

the class NlpSentimentTest method test3.

/*
     * Test sentiment with a negative sentence, result should be 1 (negative)
     */
@Test
public void test3() throws TexeraException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(NlpSentimentTestConstants.NEGATIVE_TUPLE), NlpSentimentTestConstants.SENTIMENT_SCHEMA);
    NlpSentimentOperator sentiment = new NlpSentimentOperator(new NlpSentimentPredicate(NlpSentimentTestConstants.TEXT, "sentiment"));
    TupleSink tupleSink = new TupleSink();
    sentiment.setInputOperator(tupleSource);
    tupleSink.setInputOperator(sentiment);
    tupleSink.open();
    List<Tuple> results = tupleSink.collectAllTuples();
    tupleSink.close();
    Tuple tuple = results.get(0);
    Assert.assertEquals(tuple.getField("sentiment").getValue(), SentimentConstants.NEGATIVE);
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 5 with TupleSourceOperator

use of edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator 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);
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

Tuple (edu.uci.ics.texera.api.tuple.Tuple)14 TupleSourceOperator (edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator)14 TupleSink (edu.uci.ics.texera.dataflow.sink.tuple.TupleSink)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IDField (edu.uci.ics.texera.api.field.IDField)1 ExcelSink (edu.uci.ics.texera.dataflow.sink.excel.ExcelSink)1 ExcelSinkPredicate (edu.uci.ics.texera.dataflow.sink.excel.ExcelSinkPredicate)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1