use of edu.uci.ics.textdb.exp.sink.tuple.TupleSink in project textdb by TextDB.
the class LogicalPlanTest method testLogicalPlan3.
/*
* Test a valid operator graph.
*
* --> RegexMatcher -->
* | >-- Join1
* KeywordSource --< -> NlpEntityOperator --> >-- Join2 --> TupleSink
* | /
* --> FuzzyTokenMatcher ----->
*
*/
@Test
public void testLogicalPlan3() throws Exception {
LogicalPlan logicalPlan = getLogicalPlan3();
Plan queryPlan = logicalPlan.buildQueryPlan();
ISink tupleSink = queryPlan.getRoot();
Assert.assertTrue(tupleSink instanceof TupleSink);
IOperator join2 = ((TupleSink) tupleSink).getInputOperator();
Assert.assertTrue(join2 instanceof Join);
IOperator join2Input1 = ((Join) join2).getOuterInputOperator();
Assert.assertTrue(join2Input1 instanceof Join);
IOperator join2Input2 = ((Join) join2).getInnerInputOperator();
Assert.assertTrue(join2Input2 instanceof FuzzyTokenMatcher);
IOperator join1Input1 = ((Join) join2Input1).getInnerInputOperator();
Assert.assertTrue(join1Input1 instanceof RegexMatcher);
IOperator join1Input2 = ((Join) join2Input1).getOuterInputOperator();
Assert.assertTrue(join1Input2 instanceof NlpEntityOperator);
IOperator connectorOut1 = ((RegexMatcher) join1Input1).getInputOperator();
Assert.assertTrue(connectorOut1 instanceof ConnectorOutputOperator);
IOperator connectorOut2 = ((NlpEntityOperator) join1Input2).getInputOperator();
Assert.assertTrue(connectorOut2 instanceof ConnectorOutputOperator);
IOperator connectorOut3 = ((FuzzyTokenMatcher) join2Input2).getInputOperator();
Assert.assertTrue(connectorOut3 instanceof ConnectorOutputOperator);
HashSet<Integer> connectorIndices = new HashSet<>();
connectorIndices.add(((ConnectorOutputOperator) connectorOut1).getOutputIndex());
connectorIndices.add(((ConnectorOutputOperator) connectorOut2).getOutputIndex());
connectorIndices.add(((ConnectorOutputOperator) connectorOut3).getOutputIndex());
Assert.assertEquals(connectorIndices.size(), 3);
OneToNBroadcastConnector connector1 = ((ConnectorOutputOperator) connectorOut1).getOwnerConnector();
OneToNBroadcastConnector connector2 = ((ConnectorOutputOperator) connectorOut2).getOwnerConnector();
OneToNBroadcastConnector connector3 = ((ConnectorOutputOperator) connectorOut3).getOwnerConnector();
Assert.assertSame(connector1, connector2);
Assert.assertSame(connector1, connector3);
IOperator keywordSource = connector1.getInputOperator();
Assert.assertTrue(keywordSource instanceof KeywordMatcherSourceOperator);
}
use of edu.uci.ics.textdb.exp.sink.tuple.TupleSink in project textdb by TextDB.
the class LogicalPlanTest method testLogicalPlan1.
/*
* Test a valid operator graph.
*
* KeywordSource --> RegexMatcher --> TupleSink
*
*/
@Test
public void testLogicalPlan1() throws Exception {
LogicalPlan logicalPlan = getLogicalPlan1();
Plan queryPlan = logicalPlan.buildQueryPlan();
ISink tupleSink = queryPlan.getRoot();
Assert.assertTrue(tupleSink instanceof TupleSink);
IOperator regexMatcher = ((TupleSink) tupleSink).getInputOperator();
Assert.assertTrue(regexMatcher instanceof RegexMatcher);
IOperator keywordSource = ((RegexMatcher) regexMatcher).getInputOperator();
Assert.assertTrue(keywordSource instanceof KeywordMatcherSourceOperator);
}
use of edu.uci.ics.textdb.exp.sink.tuple.TupleSink 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);
}
use of edu.uci.ics.textdb.exp.sink.tuple.TupleSink 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);
}
use of edu.uci.ics.textdb.exp.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 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);
}
Aggregations