Search in sources :

Example 6 with TupleSink

use of edu.uci.ics.textdb.exp.sink.tuple.TupleSink 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 7 with TupleSink

use of edu.uci.ics.textdb.exp.sink.tuple.TupleSink 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)

Example 8 with TupleSink

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

the class LogicalPlanTest method testLogicalPlan2.

/*
     * Test a valid operator graph.
     *                  -> RegexMatcher -->
     * KeywordSource --<                     >-- Join --> TupleSink
     *                  -> NlpEntityOperator -->
     * 
     */
@Test
public void testLogicalPlan2() throws Exception {
    LogicalPlan logicalPlan = getLogicalPlan2();
    Plan queryPlan = logicalPlan.buildQueryPlan();
    ISink tupleSink = queryPlan.getRoot();
    Assert.assertTrue(tupleSink instanceof TupleSink);
    IOperator join = ((TupleSink) tupleSink).getInputOperator();
    Assert.assertTrue(join instanceof Join);
    IOperator joinInput1 = ((Join) join).getInnerInputOperator();
    Assert.assertTrue(joinInput1 instanceof RegexMatcher);
    IOperator joinInput2 = ((Join) join).getOuterInputOperator();
    Assert.assertTrue(joinInput2 instanceof NlpEntityOperator);
    IOperator connectorOut1 = ((RegexMatcher) joinInput1).getInputOperator();
    Assert.assertTrue(connectorOut1 instanceof ConnectorOutputOperator);
    IOperator connectorOut2 = ((NlpEntityOperator) joinInput2).getInputOperator();
    Assert.assertTrue(connectorOut2 instanceof ConnectorOutputOperator);
    HashSet<Integer> connectorIndices = new HashSet<>();
    connectorIndices.add(((ConnectorOutputOperator) connectorOut1).getOutputIndex());
    connectorIndices.add(((ConnectorOutputOperator) connectorOut2).getOutputIndex());
    Assert.assertEquals(connectorIndices.size(), 2);
    OneToNBroadcastConnector connector1 = ((ConnectorOutputOperator) connectorOut1).getOwnerConnector();
    OneToNBroadcastConnector connector2 = ((ConnectorOutputOperator) connectorOut2).getOwnerConnector();
    Assert.assertSame(connector1, connector2);
    IOperator keywordSource = connector1.getInputOperator();
    Assert.assertTrue(keywordSource instanceof KeywordMatcherSourceOperator);
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) Join(edu.uci.ics.textdb.exp.join.Join) Plan(edu.uci.ics.textdb.api.engine.Plan) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) ISink(edu.uci.ics.textdb.api.dataflow.ISink) ConnectorOutputOperator(edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector.ConnectorOutputOperator) NlpEntityOperator(edu.uci.ics.textdb.exp.nlp.entity.NlpEntityOperator) RegexMatcher(edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher) OneToNBroadcastConnector(edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with TupleSink

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

the class TupleSinkTest method testOpenClose.

@Test
public void testOpenClose() throws Exception {
    TupleSink tupleSink = new TupleSink();
    tupleSink.setInputOperator(inputOperator);
    tupleSink.open();
    // verify that inputOperator called open() method
    Mockito.verify(inputOperator).open();
    // assert that the tuple stream sink removes the PAYLOAD attribute
    Assert.assertEquals(new Schema(SchemaConstants._ID_ATTRIBUTE, new Attribute("content", AttributeType.TEXT)), tupleSink.getOutputSchema());
    tupleSink.close();
    // verify that inputOperator called close() method
    Mockito.verify(inputOperator).close();
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) Test(org.junit.Test)

Example 10 with TupleSink

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

the class TupleSinkTest method testGetNextTuple.

@Test
public void testGetNextTuple() throws Exception {
    TupleSink tupleSink = new TupleSink();
    tupleSink.setInputOperator(inputOperator);
    Tuple sampleTuple = Mockito.mock(Tuple.class);
    Mockito.when(sampleTuple.toString()).thenReturn("Sample Tuple");
    Mockito.when(sampleTuple.getSchema()).thenReturn(inputSchema);
    // Set the behavior for inputOperator,
    // first it returns some non-null tuple and second time it returns null
    Mockito.when(inputOperator.getNextTuple()).thenReturn(sampleTuple).thenReturn(null);
    tupleSink.open();
    tupleSink.getNextTuple();
    // Verify that input operator's getNextTuple is called
    Mockito.verify(inputOperator, Mockito.times(1)).getNextTuple();
    tupleSink.close();
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

TupleSink (edu.uci.ics.textdb.exp.sink.tuple.TupleSink)12 Test (org.junit.Test)11 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)8 TupleSourceOperator (edu.uci.ics.textdb.exp.source.tuple.TupleSourceOperator)5 ISink (edu.uci.ics.textdb.api.dataflow.ISink)4 Plan (edu.uci.ics.textdb.api.engine.Plan)4 IOperator (edu.uci.ics.textdb.api.dataflow.IOperator)3 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)3 RegexMatcher (edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher)3 HashSet (java.util.HashSet)3 OneToNBroadcastConnector (edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector)2 ConnectorOutputOperator (edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector.ConnectorOutputOperator)2 Join (edu.uci.ics.textdb.exp.join.Join)2 NlpEntityOperator (edu.uci.ics.textdb.exp.nlp.entity.NlpEntityOperator)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IDField (edu.uci.ics.textdb.api.field.IDField)1 Attribute (edu.uci.ics.textdb.api.schema.Attribute)1 Schema (edu.uci.ics.textdb.api.schema.Schema)1