use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class VectorPolynomialExpandTest method pipelineStreamTest.
@Test
public void pipelineStreamTest() throws Exception {
StreamOperator streamOperator = new VectorPolynomialExpand().setDegree(2).setOutputCol("outv").setSelectedCol("c1").transform((StreamOperator) getData(false));
CollectSinkStreamOp collectSinkStreamOp = new CollectSinkStreamOp().linkFrom(streamOperator);
StreamOperator.execute();
List<Row> result = collectSinkStreamOp.getAndRemoveValues();
result.sort(new RowComparator(0));
assertEquals(VectorUtil.getVector(result.get(2).getField(4)), new DenseVector(new double[] { 2.0, 4.0, 3.0, 6.0, 9.0 }));
assertEquals(VectorUtil.getVector(result.get(1).getField(4)), new DenseVector(new double[] { 3.0, 9.0, 2.0, 6.0, 4.0, 3.0, 9.0, 6.0, 9.0 }));
assertEquals(VectorUtil.getVector(result.get(0).getField(4)), new DenseVector(new double[] { 3.0, 9.0, 2.0, 6.0, 4.0, 3.0, 9.0, 6.0, 9.0 }));
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class VectorSlicerTest method pipelineStreamTest.
@Test
public void pipelineStreamTest() throws Exception {
StreamOperator streamOperator = new VectorSlicer().setSelectedCol("c0").setOutputCol("slicer_result").setIndices(new int[] { 1, 5 }).transform((StreamOperator) getData(false));
CollectSinkStreamOp collectSinkStreamOp = new CollectSinkStreamOp().linkFrom(streamOperator);
StreamOperator.execute();
List<Row> result = collectSinkStreamOp.getAndRemoveValues();
result.sort(new RowComparator(0));
assertEquals(VectorUtil.getSparseVector(result.get(0).getField(4)), new SparseVector(2, new int[] { 0, 1 }, new double[] { 2.0, 4.3 }));
assertEquals(VectorUtil.getSparseVector(result.get(1).getField(4)), new SparseVector(2, new int[] { 0 }, new double[] { 2.0 }));
assertEquals(VectorUtil.getSparseVector(result.get(2).getField(4)), new SparseVector(2, new int[] { 0 }, new double[] { 2.0 }));
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class BinarizerTest method test.
@Test
public void test() throws Exception {
Row[] rows = new Row[] { Row.of(1, 1.218, 16.0, "1.560 -0.605"), Row.of(2, 2.949, 4.0, "0.346 2.158"), Row.of(3, 3.627, 2.0, "1.380 0.231"), Row.of(4, 0.273, 15.0, "0.520 1.151"), Row.of(5, 4.199, 7.0, "0.795 -0.226") };
List<Row> expectedRows = Arrays.asList(Row.of(1, 1.0), Row.of(2, 0.0), Row.of(3, 0.0), Row.of(4, 1.0), Row.of(5, 0.0));
BatchOperator<?> data = new MemSourceBatchOp(rows, new String[] { "id", "label", "censor", "features" });
StreamOperator<?> dataStream = new MemSourceStreamOp(rows, new String[] { "id", "label", "censor", "features" });
Binarizer op = new Binarizer().setSelectedCol("censor").setThreshold(8.0);
// batch
List<Row> list = op.transform(data).select("id, censor").collect();
AlinkTestBase.assertListRowEqual(expectedRows, list, 0);
CollectSinkStreamOp resS = op.transform(dataStream).select("id, censor").link(new CollectSinkStreamOp());
StreamOperator.execute();
AlinkTestBase.assertListRowEqual(expectedRows, resS.getAndRemoveValues(), 0);
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class ReadImageToTensorStreamOpTest method testReadImageToTensorStreamOp.
@Test
public void testReadImageToTensorStreamOp() throws Exception {
List<Row> data = Collections.singletonList(Row.of("sphx_glr_plot_scripted_tensor_transforms_001.png"));
MemSourceStreamOp memSourceStreamOp = new MemSourceStreamOp(data, "path string");
CollectSinkStreamOp collectSinkStreamOp = new ReadImageToTensorStreamOp().setRootFilePath("http://alink-test-datatset.oss-cn-hangzhou-zmf.aliyuncs.com/images/").setRelativeFilePathCol("path").setOutputCol("tensor").linkFrom(memSourceStreamOp).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> rows = collectSinkStreamOp.getAndRemoveValues();
Assert.assertEquals(1, rows.size());
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class KeywordsExtractionStreamOpTest method testKeywordsExtractionStream.
@Test
public void testKeywordsExtractionStream() throws Exception {
Row[] array = new Row[] { Row.of(1, text), Row.of(1, text), Row.of(1, text), Row.of(1, text) };
List<Row> expected = Arrays.asList(Row.of(1, "基于 算法 建模"), Row.of(1, "基于 算法 建模"), Row.of(1, "基于 算法 建模"), Row.of(1, "基于 算法 建模"));
MemSourceStreamOp words = new MemSourceStreamOp(Arrays.asList(array), new String[] { "ID", "text" });
KeywordsExtractionStreamOp op = new KeywordsExtractionStreamOp().setSelectedCol("text").setTopN(3).linkFrom(words);
CollectSinkStreamOp sink = new CollectSinkStreamOp().linkFrom(op);
StreamOperator.execute();
assertListRowEqualWithoutOrder(expected, sink.getAndRemoveValues());
}
Aggregations