Package uk.org.ogsadai.activity

Examples of uk.org.ogsadai.activity.MockInputPipe


                "  block = reader.read\n" +
                "  writer = outputs.get(\"output\")\n" +
                "  writer.write(block)\n" +
                "  writer.closeForWriting\n" +
                "end\n";
        MockInputPipe inputScript = new MockInputPipe(new Object[] {
                script
            });
        activity.addInput(GenericActivity.INPUT_SCRIPT, inputScript);
        MockInputPipe inputLanguage = new MockInputPipe("jruby");
        activity.addInput(GenericActivity.INPUT_LANGUAGE, inputLanguage);
        MockInputPipe inputName = new MockInputPipe("Amy");
        activity.addInput("input", inputName);
        MockOutputPipe output = new MockOutputPipe(new Object[] {"Amy"});
        activity.addOutput("output", output);
        activity.process();
        output.verify();
View Full Code Here


    @Test
    public void testNoMethod() throws Exception
    {
        GenericActivity activity = new GenericActivity();
        String script = "x = 5";
        MockInputPipe inputScript = new MockInputPipe(new Object[] {
                script
            });
        activity.addInput(GenericActivity.INPUT_SCRIPT, inputScript);
        MockInputPipe inputLanguage = new MockInputPipe("jruby");
        activity.addInput(GenericActivity.INPUT_LANGUAGE, inputLanguage);
        try
        {
            activity.process();
            TestCase.fail("Exception expected.");
View Full Code Here

    @Test
    public void testRangeGenerator() throws Exception
    {
        GenericActivity activity = new GenericActivity();
        String script = readFile("test/uk/org/ogsadai/generic/GenerateRange.rb");
        MockInputPipe inputScript = new MockInputPipe(new Object[] {script});
        activity.addInput(GenericActivity.INPUT_SCRIPT, inputScript);
        MockInputPipe inputLanguage = new MockInputPipe("jruby");
        activity.addInput(GenericActivity.INPUT_LANGUAGE, inputLanguage);
        double step = 6.5;
        double value = 0.0;
        double max = 100.0;
        MockInputPipe inputMin = new MockInputPipe(value);
        activity.addInput("min", inputMin);
        MockInputPipe inputMax = new MockInputPipe(max);
        activity.addInput("max", inputMax);
        MockInputPipe inputStep = new MockInputPipe(step);
        activity.addInput("step", inputStep);
        MockOutputPipe output = new MockOutputPipe(new Object[] {});
        activity.addOutput("output", output);
        activity.process();
        List<?> actual = output.getActualBlocks();
View Full Code Here

    {
        List<ColumnMetadata> columns = new ArrayList<ColumnMetadata>();
        columns.add(new SimpleColumnMetadata("A", TupleTypes._INT, 0, 0, 0));
        columns.add(new SimpleColumnMetadata("B", TupleTypes._INT, 0, 0, 0));
        TupleMetadata metadata = new SimpleTupleMetadata(columns);
        MockInputPipe dataInput = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                new MetadataWrapper(metadata),
                new SimpleTuple(Arrays.asList(0, 1)),
                new SimpleTuple(Arrays.asList(2, 3)),
                new SimpleTuple(Arrays.asList(4, 5)),
                ControlBlock.LIST_END
        });
        String script =
                "include_class Java::uk.org.ogsadai.generic.TupleHelper;\n" +
                "include_class Java::uk.org.ogsadai.tuple.TupleTypes;\n" +
                "def getMetadata(inputMetadata)\n" +
                "  col = TupleHelper.createColumnMetadata(\"A\", TupleTypes._INT);\n" +
                "  TupleHelper.createTupleMetadata([col].to_java);\n" +
                "end\n" +
                "def process(tuple)\n" +
                "  value = tuple.getInt(0) + tuple.getInt(1);\n" +
                "  tuple = TupleHelper.createTuple([ value ].to_java);\n" +
                "  Java::java.util.Arrays.asList([tuple].to_java);\n" +
                "end\n" +
                "def flush()\n" +
                "  Java::java.util.Collections.emptyList;\n" +
                "end\n";
        MockInputPipe scriptInput = new MockInputPipe(script);
        MockInputPipe languageInput = new MockInputPipe("jruby");
        MockOutputPipe output = new MockOutputPipe(new Object[] {});
        GenericTupleTransformActivity activity = new GenericTupleTransformActivity();
        activity.addInput(GenericTupleTransformActivity.INPUT_DATA, dataInput);
        activity.addInput(GenericTupleTransformActivity.INPUT_SCRIPT, scriptInput);
        activity.addInput(GenericTupleTransformActivity.INPUT_LANGUAGE, languageInput);
View Full Code Here

    {
        List<ColumnMetadata> columns = new ArrayList<ColumnMetadata>();
        columns.add(new SimpleColumnMetadata("A", TupleTypes._INT, 0, 0, 0));
        columns.add(new SimpleColumnMetadata("B", TupleTypes._INT, 0, 0, 0));
        TupleMetadata metadata = new SimpleTupleMetadata(columns);
        MockInputPipe dataInput = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                new MetadataWrapper(metadata),
                new SimpleTuple(Arrays.asList(Null.VALUE, "a")),
                new SimpleTuple(Arrays.asList(0, "b")),
                new SimpleTuple(Arrays.asList(Null.VALUE, "c")),
                new SimpleTuple(Arrays.asList(1, "d")),
                new SimpleTuple(Arrays.asList(2, "e")),
                ControlBlock.LIST_END
        });
        MockInputPipe scriptInput = new MockInputPipe(GenericTupleJoinActivityTest.readFile("src/ogsadai/test/uk/org/ogsadai/generic/ReplaceNull.rb"));
        MockInputPipe languageInput = new MockInputPipe("jruby");
        MockOutputPipe output = new MockOutputPipe(new Object[]{});
        GenericTupleTransformActivity activity = new GenericTupleTransformActivity();
        activity.addInput(GenericTupleTransformActivity.INPUT_DATA, dataInput);
        activity.addInput(GenericTupleTransformActivity.INPUT_SCRIPT, scriptInput);
        activity.addInput(GenericTupleTransformActivity.INPUT_LANGUAGE, languageInput);
View Full Code Here

    public void testSimple() throws Exception
    {
        List<ColumnMetadata> columns = new ArrayList<ColumnMetadata>();
        columns.add(new SimpleColumnMetadata("A", TupleTypes._STRING, 0, 0, 0));
        TupleMetadata metadata = new SimpleTupleMetadata(columns);
        MockInputPipe data1Input = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                new MetadataWrapper(metadata),
                new SimpleTuple(Arrays.asList("Rupert")),
                new SimpleTuple(Arrays.asList("Ally")),
                new SimpleTuple(Arrays.asList("Amy")),
                ControlBlock.LIST_END
        });
        MockInputPipe data2Input = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                new MetadataWrapper(metadata),
                new SimpleTuple(Arrays.asList("Robert")),
                new SimpleTuple(Arrays.asList("Ali")),
                new SimpleTuple(Arrays.asList("Annie")),
                ControlBlock.LIST_END
        });
        String script = readFile("src/ogsadai/test/uk/org/ogsadai/generic/SoundexJoin.rb");
        MockInputPipe scriptInput = new MockInputPipe(script);
        MockInputPipe languageInput = new MockInputPipe("jruby");
        MockOutputPipe output = new MockOutputPipe(new Object[] {});
        GenericTupleJoinActivity activity = new GenericTupleJoinActivity();
        activity.addInput(GenericTupleJoinActivity.INPUT_DATA1, data1Input);
        activity.addInput(GenericTupleJoinActivity.INPUT_DATA2, data2Input);
        activity.addInput(GenericTupleJoinActivity.INPUT_SCRIPT, scriptInput);
View Full Code Here

{
    @Test
    public void testSimple() throws Exception
    {
       
        MockInputPipe inputSize = new MockInputPipe(2);
       
        ColumnMetadata colA = new SimpleColumnMetadata("A", TupleTypes._STRING, 0, 0, 0);
        ColumnMetadata colB = new SimpleColumnMetadata("B", TupleTypes._DOUBLE, 0, 0, 0);
        TupleMetadata metadata = new SimpleTupleMetadata(Arrays.asList(colA, colB));
        Tuple tuple1 = new SimpleTuple(Arrays.<Object>asList("Amy", 0));
        Tuple tuple2 = new SimpleTuple(Arrays.<Object>asList("Ally", 1.0));
        Tuple tuple3 = new SimpleTuple(Arrays.<Object>asList("Radek", 2.0));
        Tuple tuple4 = new SimpleTuple(Arrays.<Object>asList("Adrian", 3.0));
        Tuple tuple5 = new SimpleTuple(Arrays.<Object>asList("Rob", 4.0));
        MockInputPipe inputData = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                new MetadataWrapper(metadata),
                tuple1, tuple2, tuple3, tuple4, tuple5,
                ControlBlock.LIST_END
        });
View Full Code Here

                BuildClassifierActivity.CLASSIFIER_CLASS_NAME,
                "weka.classifiers.trees.J48");
        activity.configureActivity(properties);

        List<Object> input = buildInputTable();
        MockInputPipe dataInput = new MockInputPipe(input.toArray());
        activity.addInput(BuildClassifierActivity.INPUT_DATA, dataInput);
       
        MockInputPipe classIndexInput = new MockInputPipe(new Object[] {4});
        activity.addInput(BuildClassifierActivity.INPUT_CLASS_INDEX, classIndexInput);
       
        MockInputPipe nominalColumnsInput = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                0, 1, 4,
                ControlBlock.LIST_END
        });
        activity.addInput(BuildClassifierActivity.INPUT_COLUMN_INDICES, nominalColumnsInput);

        MockInputPipe nominalValuesInput = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                ControlBlock.LIST_BEGIN, "sunny", "overcast", "rain", ControlBlock.LIST_END,
                ControlBlock.LIST_BEGIN, "true", "false", ControlBlock.LIST_END,
                ControlBlock.LIST_BEGIN, "yes", "no", ControlBlock.LIST_END,
                ControlBlock.LIST_END
        });
        activity.addInput(BuildClassifierActivity.INPUT_NOMINAL_VALUES, nominalValuesInput);

        MockOutputPipe output = new MockOutputPipe(new Object[] {});
        activity.addOutput(BuildClassifierActivity.CLASSIFIER_OUTPUT, output);
       
        activity.process();
       
        TupleClassifier classifier = (TupleClassifier)output.getActualBlocks().get(0);
//        System.out.println(classifier);
       
        ClassifyActivity classify = new ClassifyActivity();
        MockInputPipe inputClassifier = new MockInputPipe(classifier);
        classify.addInput(ClassifyActivity.INPUT_CLASSIFIER, inputClassifier);
        MockInputPipe inputData = new MockInputPipe(buildInputTable().toArray());
        classify.addInput(ClassifyActivity.INPUT_DATA, inputData);
        MockInputPipe inputResultColumnName = new MockInputPipe("myResult");
        classify.addInput(ClassifyActivity.INPUT_RESULT_COLUMN_NAME, inputResultColumnName);
        MockOutputPipe outputClassify = new MockOutputPipe(new Object[] {});
        classify.addOutput(ClassifyActivity.OUTPUT, outputClassify);
       
        classify.process();
View Full Code Here

                BuildClassifierActivity.CLASSIFIER_CLASS_NAME,
                "weka.classifiers.trees.J48");
        activity.configureActivity(properties);

        List<Object> input = buildInputTable();
        MockInputPipe dataInput = new MockInputPipe(input.toArray());
        activity.addInput(BuildClassifierActivity.INPUT_DATA, dataInput);
       
        MockInputPipe classIndexInput = new MockInputPipe("play");
        activity.addInput(BuildClassifierActivity.INPUT_CLASS_INDEX, classIndexInput);
       
        MockInputPipe nominalColumnsInput = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                "outlook", "windy", "play",
                ControlBlock.LIST_END
        });
        activity.addInput(BuildClassifierActivity.INPUT_COLUMN_INDICES, nominalColumnsInput);

        MockInputPipe nominalValuesInput = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                ControlBlock.LIST_BEGIN, "sunny", "overcast", "rain", ControlBlock.LIST_END,
                ControlBlock.LIST_BEGIN, "true", "false", ControlBlock.LIST_END,
                ControlBlock.LIST_BEGIN, "yes", "no", ControlBlock.LIST_END,
                ControlBlock.LIST_END
        });
        activity.addInput(BuildClassifierActivity.INPUT_NOMINAL_VALUES, nominalValuesInput);

        MockOutputPipe output = new MockOutputPipe(new Object[] {});
        activity.addOutput(BuildClassifierActivity.CLASSIFIER_OUTPUT, output);
       
        activity.process();
       
        TupleClassifier classifier = (TupleClassifier)output.getActualBlocks().get(0);
//        System.out.println(classifier);
       
        ClassifyActivity classify = new ClassifyActivity();
        MockInputPipe inputClassifier = new MockInputPipe(classifier);
        classify.addInput(ClassifyActivity.INPUT_CLASSIFIER, inputClassifier);
        MockInputPipe inputData = new MockInputPipe(buildInputTable().toArray());
        classify.addInput(ClassifyActivity.INPUT_DATA, inputData);
        MockInputPipe inputResultColumnName = new MockInputPipe("myResult");
        classify.addInput(ClassifyActivity.INPUT_RESULT_COLUMN_NAME, inputResultColumnName);
        MockOutputPipe outputClassify = new MockOutputPipe(new Object[] {});
        classify.addOutput(ClassifyActivity.OUTPUT, outputClassify);
       
        classify.process();
View Full Code Here

        properties.put(
                BuildClassifierActivity.CLASSIFIER_CLASS_NAME,
                "weka.classifiers.trees.J48");
        activity.configureActivity(properties);

        MockInputPipe dataInput = new MockInputPipe(table.toArray());
        activity.addInput(BuildClassifierActivity.INPUT_DATA, dataInput);
       
        MockInputPipe classIndexInput = new MockInputPipe(new Object[] {0});
        activity.addInput(BuildClassifierActivity.INPUT_CLASS_INDEX, classIndexInput);

        MockInputPipe nominalColumnsInput = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                0,
                ControlBlock.LIST_END
        });
        activity.addInput(BuildClassifierActivity.INPUT_COLUMN_INDICES, nominalColumnsInput);

        MockInputPipe nominalValuesInput = new MockInputPipe(new Object[] {
                ControlBlock.LIST_BEGIN,
                ControlBlock.LIST_BEGIN, "yes", "no", ControlBlock.LIST_END,
                ControlBlock.LIST_END
        });
        activity.addInput(BuildClassifierActivity.INPUT_NOMINAL_VALUES, nominalValuesInput);

        MockOutputPipe output = new MockOutputPipe(new Object[] {});
        activity.addOutput(BuildClassifierActivity.CLASSIFIER_OUTPUT, output);
       
        activity.process();
       
        TupleClassifier classifier = (TupleClassifier)output.getActualBlocks().get(0);
//        System.out.println(classifier);
       
        ClassifyActivity classify = new ClassifyActivity();
        MockInputPipe inputClassifier = new MockInputPipe(classifier);
        classify.addInput(ClassifyActivity.INPUT_CLASSIFIER, inputClassifier);

        MockInputPipe inputData = new MockInputPipe(table.toArray());
        classify.addInput(ClassifyActivity.INPUT_DATA, inputData);
        MockOutputPipe outputClassify = new MockOutputPipe(new Object[] {});
        classify.addOutput(ClassifyActivity.OUTPUT, outputClassify);
       
        classify.process();
View Full Code Here

TOP

Related Classes of uk.org.ogsadai.activity.MockInputPipe

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.