Search in sources :

Example 46 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTestWithLimitOffset.

public void getNextTupleTestWithLimitOffset() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getOneSentenceTestTuple();
    DataWriter oneSentenceDataWriter = RelationManager.getRelationManager().getTableDataWriter(ONE_SENTENCE_TABLE);
    oneSentenceDataWriter.open();
    for (Tuple tuple : data) {
        oneSentenceDataWriter.insertTuple(tuple);
    }
    oneSentenceDataWriter.close();
    String attribute1 = NlpEntityTestConstants.SENTENCE_ONE;
    List<String> attributeNames = Arrays.asList(attribute1);
    List<Tuple> returnedResults = getQueryResults(ONE_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL, 2, 2);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest10ResultTuples();
    Assert.assertEquals(returnedResults.size(), 2);
    Assert.assertTrue(TestUtils.containsAll(expectedResults, returnedResults));
}
Also used : Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 47 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple 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 48 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple 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 49 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple 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 50 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple 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)

Aggregations

Tuple (edu.uci.ics.textdb.api.tuple.Tuple)234 ArrayList (java.util.ArrayList)144 Test (org.junit.Test)135 IField (edu.uci.ics.textdb.api.field.IField)102 Schema (edu.uci.ics.textdb.api.schema.Schema)95 TextField (edu.uci.ics.textdb.api.field.TextField)92 StringField (edu.uci.ics.textdb.api.field.StringField)85 Attribute (edu.uci.ics.textdb.api.schema.Attribute)84 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)80 Span (edu.uci.ics.textdb.api.span.Span)80 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 DateField (edu.uci.ics.textdb.api.field.DateField)61 SimpleDateFormat (java.text.SimpleDateFormat)60 DataWriter (edu.uci.ics.textdb.storage.DataWriter)31 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)25 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)20 RelationManager (edu.uci.ics.textdb.storage.RelationManager)19 JoinDistancePredicate (edu.uci.ics.textdb.exp.join.JoinDistancePredicate)18 ScanBasedSourceOperator (edu.uci.ics.textdb.exp.source.scan.ScanBasedSourceOperator)17 ScanSourcePredicate (edu.uci.ics.textdb.exp.source.scan.ScanSourcePredicate)17