Search in sources :

Example 6 with TupleSourceOperator

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

the class NltkSentimentOperatorTest method test2.

/*
     * Test sentiment test result should be negative
     */
@Test
public void test2() throws TexeraException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(NltkSentimentTestConstants.NEGATIVE_TUPLE), NlpSentimentTestConstants.SENTIMENT_SCHEMA);
    NltkSentimentOperator nltkSentimentOperator = new NltkSentimentOperator(new NltkSentimentOperatorPredicate(NltkSentimentTestConstants.TEXT, "sentiment", BATCH_SIZE, MODEL_FILE_NAME));
    TupleSink tupleSink = new TupleSink();
    nltkSentimentOperator.setInputOperator(tupleSource);
    tupleSink.setInputOperator(nltkSentimentOperator);
    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 7 with TupleSourceOperator

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

the class NlpSplitTest method test2.

@Test
public void test2() throws TexeraException, 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.texera.dataflow.sink.tuple.TupleSink) IDField(edu.uci.ics.texera.api.field.IDField) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with TupleSourceOperator

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

the class NlpSplitTest method test1.

@Test
public void test1() throws TexeraException, 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.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 9 with TupleSourceOperator

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

the class DownloadFileResource method downloadExcelFile.

@GET
@Path("/result")
public Response downloadExcelFile(@QueryParam("resultID") String resultID) throws JsonParseException, JsonMappingException, IOException {
    java.nio.file.Path resultFile = QueryPlanResource.resultDirectory.resolve(resultID + ".json");
    if (Files.notExists(resultFile)) {
        System.out.println(resultFile + " file does not found");
        return Response.status(Status.NOT_FOUND).build();
    }
    ArrayList<Tuple> result = new ObjectMapper().readValue(Files.readAllBytes(resultFile), TypeFactory.defaultInstance().constructCollectionLikeType(ArrayList.class, Tuple.class));
    if (result.size() == 0) {
        System.out.println(resultFile + " file is empty");
        return Response.status(Status.NOT_FOUND).build();
    }
    TupleSourceOperator tupleSource = new TupleSourceOperator(result, result.get(0).getSchema());
    ExcelSink excelSink = new ExcelSinkPredicate().newOperator();
    excelSink.setInputOperator(tupleSource);
    excelSink.open();
    excelSink.collectAllTuples();
    excelSink.close();
    StreamingOutput fileStream = new StreamingOutput() {

        @Override
        public void write(OutputStream output) throws IOException, WebApplicationException {
            byte[] data = Files.readAllBytes(excelSink.getFilePath());
            output.write(data);
            output.flush();
        }
    };
    return Response.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM).header("content-disposition", "attachment; filename=result.xlsx").build();
}
Also used : OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) ExcelSinkPredicate(edu.uci.ics.texera.dataflow.sink.excel.ExcelSinkPredicate) StreamingOutput(javax.ws.rs.core.StreamingOutput) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) ExcelSink(edu.uci.ics.texera.dataflow.sink.excel.ExcelSink) Tuple(edu.uci.ics.texera.api.tuple.Tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 10 with TupleSourceOperator

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

the class EmojiSentimentTest method test1.

@Test
public void test1() throws TexeraException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(EmojiSentimentTestConstants.POSITIVE_TUPLE1), 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.POSITIVE);
}
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)

Aggregations

Tuple (edu.uci.ics.texera.api.tuple.Tuple)14 TupleSourceOperator (edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator)14 TupleSink (edu.uci.ics.texera.dataflow.sink.tuple.TupleSink)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IDField (edu.uci.ics.texera.api.field.IDField)1 ExcelSink (edu.uci.ics.texera.dataflow.sink.excel.ExcelSink)1 ExcelSinkPredicate (edu.uci.ics.texera.dataflow.sink.excel.ExcelSinkPredicate)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1