Search in sources :

Example 16 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class EmojiSentimentTest method test2.

/*
     * Test sentiment with a neutral sentence, result should be 2 (neutral)
     */
@Test
public void test2() throws TexeraException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(EmojiSentimentTestConstants.NEUTRAL_TUPLE), 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.NEUTRAL);
}
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 17 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class EmojiSentimentTest 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(EmojiSentimentTestConstants.NEGATIVE_TUPLE1), 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 18 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class NlpSentimentTest method test2.

/*
     * Test sentiment with a neutral sentence, result should be 2 (neutral)
     */
@Test
public void test2() throws TexeraException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(NlpSentimentTestConstants.NEUTRAL_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.NEUTRAL);
}
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 19 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class NltkSentimentOperatorTest method test3.

/*
     * Test batch processing of operator. All test results should be negative
     */
@Test
public void test3() throws TexeraException {
    int batchSize = 30;
    int tupleSourceSize = 101;
    List<Tuple> listTuple = new ArrayList<>();
    for (int i = 0; i < tupleSourceSize; i++) {
        listTuple.add(NltkSentimentTestConstants.NEGATIVE_TUPLE);
    }
    TupleSourceOperator tupleSource = new TupleSourceOperator(listTuple, NltkSentimentTestConstants.SENTIMENT_SCHEMA);
    NltkSentimentOperator nltkSentimentOperator = new NltkSentimentOperator(new NltkSentimentOperatorPredicate(NlpSentimentTestConstants.TEXT, "sentiment", batchSize, MODEL_FILE_NAME));
    TupleSink tupleSink = new TupleSink();
    nltkSentimentOperator.setInputOperator(tupleSource);
    tupleSink.setInputOperator(nltkSentimentOperator);
    tupleSink.open();
    List<Tuple> results = tupleSink.collectAllTuples();
    tupleSink.close();
    for (int i = 0; i < tupleSourceSize; i++) {
        Tuple tuple = results.get(i);
        Assert.assertEquals(tuple.getField("sentiment").getValue(), SentimentConstants.NEGATIVE);
    }
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) ArrayList(java.util.ArrayList) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 20 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class LogicalPlanTest method testGetOutputSchema4.

/*
     * Test getOutputSchema on a operator graph without a sink operator
     *
     * KeywordSource --> RegexMatcher
     *
     */
@Test
public void testGetOutputSchema4() throws Exception {
    LogicalPlan validLogicalPlan = getLogicalPlan1();
    Plan queryPlan = validLogicalPlan.buildQueryPlan();
    ISink tupleSink = queryPlan.getRoot();
    IOperator regexMatcher = ((TupleSink) tupleSink).getInputOperator();
    IOperator keywordSource = ((RegexMatcher) regexMatcher).getInputOperator();
    regexMatcher.open();
    Schema expectedSourceOutputSchema = keywordSource.getOutputSchema();
    Schema expectedMatcherOutputSchema = regexMatcher.getOutputSchema();
    regexMatcher.close();
    LogicalPlan logicalPlan = new LogicalPlan();
    logicalPlan.addOperator(keywordSourcePredicate);
    logicalPlan.addOperator(regexPredicate);
    logicalPlan.addLink(new OperatorLink(KEYWORD_SOURCE_ID, REGEX_ID));
    Schema sourceOutputSchema = logicalPlan.getOperatorOutputSchema(KEYWORD_SOURCE_ID);
    Schema matcherOutputSchema = logicalPlan.getOperatorOutputSchema(REGEX_ID);
    Assert.assertEquals(expectedSourceOutputSchema, sourceOutputSchema);
    Assert.assertEquals(expectedMatcherOutputSchema, matcherOutputSchema);
}
Also used : ISink(edu.uci.ics.texera.api.dataflow.ISink) TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) Schema(edu.uci.ics.texera.api.schema.Schema) RegexMatcher(edu.uci.ics.texera.dataflow.regexmatcher.RegexMatcher) Plan(edu.uci.ics.texera.api.engine.Plan) Test(org.junit.Test)

Aggregations

TupleSink (edu.uci.ics.texera.dataflow.sink.tuple.TupleSink)25 Test (org.junit.Test)23 Tuple (edu.uci.ics.texera.api.tuple.Tuple)17 TupleSourceOperator (edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator)13 ISink (edu.uci.ics.texera.api.dataflow.ISink)8 Plan (edu.uci.ics.texera.api.engine.Plan)8 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)7 RegexMatcher (edu.uci.ics.texera.dataflow.regexmatcher.RegexMatcher)7 Schema (edu.uci.ics.texera.api.schema.Schema)5 OneToNBroadcastConnector (edu.uci.ics.texera.dataflow.connector.OneToNBroadcastConnector)3 ConnectorOutputOperator (edu.uci.ics.texera.dataflow.connector.OneToNBroadcastConnector.ConnectorOutputOperator)3 Join (edu.uci.ics.texera.dataflow.join.Join)3 KeywordMatcherSourceOperator (edu.uci.ics.texera.dataflow.keywordmatcher.KeywordMatcherSourceOperator)3 NlpEntityOperator (edu.uci.ics.texera.dataflow.nlp.entity.NlpEntityOperator)3 HashSet (java.util.HashSet)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 BasicClient (com.twitter.hbc.httpclient.BasicClient)1