Search in sources :

Example 1 with TupleSourceOperator

use of edu.uci.ics.textdb.exp.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 TextDBException {
    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(), 1);
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.textdb.exp.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 2 with TupleSourceOperator

use of edu.uci.ics.textdb.exp.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 TextDBException {
    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(), 3);
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.textdb.exp.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 3 with TupleSourceOperator

use of edu.uci.ics.textdb.exp.source.tuple.TupleSourceOperator 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 TextDBException {
    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(), 2);
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.textdb.exp.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 4 with TupleSourceOperator

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

the class NlpSplitTest method test1.

@Test
public void test1() throws TextDBException, ParseException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(NlpSplitTestConstants.getOneToOneTestTuple(), NlpSplitTestConstants.SPLIT_SCHEMA);
    NlpSplitOperator sentence_list = new NlpSplitOperator(new NlpSplitPredicate(NLPOutputType.ONE_TO_ONE, NlpSplitTestConstants.TEXT, SchemaConstants.SPAN_LIST));
    TupleSink tupleSink = new TupleSink();
    sentence_list.setInputOperator(tupleSource);
    tupleSink.setInputOperator(sentence_list);
    tupleSink.open();
    List<Tuple> results = tupleSink.collectAllTuples();
    tupleSink.close();
    Assert.assertTrue(TestUtils.equals(NlpSplitTestConstants.getOneToOneResultTuple(), results));
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.textdb.exp.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 5 with TupleSourceOperator

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

the class NlpSplitTest method test2.

@Test
public void test2() throws TextDBException, ParseException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(NlpSplitTestConstants.getOneToManyTestTuple(), NlpSplitTestConstants.SPLIT_SCHEMA);
    NlpSplitOperator sentence_list = new NlpSplitOperator(new NlpSplitPredicate(NLPOutputType.ONE_TO_MANY, NlpSplitTestConstants.TEXT, PropertyNameConstants.NLP_OUTPUT_TYPE));
    TupleSink tupleSink = new TupleSink();
    sentence_list.setInputOperator(tupleSource);
    tupleSink.setInputOperator(sentence_list);
    tupleSink.open();
    List<Tuple> results = tupleSink.collectAllTuples();
    tupleSink.close();
    Assert.assertTrue(TestUtils.equals(NlpSplitTestConstants.getOneToManyResultTuple(), results));
    Set<IDField> compset = new HashSet<IDField>();
    for (Tuple result : results) {
        Assert.assertFalse(compset.contains(result.getField(SchemaConstants._ID)));
        compset.add(result.getField(SchemaConstants._ID));
    }
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) IDField(edu.uci.ics.textdb.api.field.IDField) TupleSourceOperator(edu.uci.ics.textdb.exp.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Tuple (edu.uci.ics.textdb.api.tuple.Tuple)5 TupleSink (edu.uci.ics.textdb.exp.sink.tuple.TupleSink)5 TupleSourceOperator (edu.uci.ics.textdb.exp.source.tuple.TupleSourceOperator)5 Test (org.junit.Test)5 IDField (edu.uci.ics.textdb.api.field.IDField)1 HashSet (java.util.HashSet)1