Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java将Exampleset设置为ExampleSet2SimilarityExampleSet Rapidminer运算符_Java_Machine Learning_Data Mining_Rapidminer - Fatal编程技术网

使用java将Exampleset设置为ExampleSet2SimilarityExampleSet Rapidminer运算符

使用java将Exampleset设置为ExampleSet2SimilarityExampleSet Rapidminer运算符,java,machine-learning,data-mining,rapidminer,Java,Machine Learning,Data Mining,Rapidminer,我创建了一个度量相似性的过程。我使用ExampleSet2SimilarityExampleSetoperator,我想在输入中添加一个在代码中生成的示例集 第一个想法是在本地存储库中编写示例集。然后我将使用retrieve操作符读取示例集,并将操作符retrieve的输出连接到操作符ExampleSet2SimilarityExampleSet的输入 所以我想知道我是否可以避免读/写 public class Test { public static void main(

我创建了一个度量相似性的过程。我使用ExampleSet2SimilarityExampleSetoperator,我想在输入中添加一个在代码中生成的示例集

第一个想法是在本地存储库中编写示例集。然后我将使用retrieve操作符读取示例集,并将操作符retrieve的输出连接到操作符ExampleSet2SimilarityExampleSet的输入

所以我想知道我是否可以避免读/写

  public class Test {

        public static void main(String[] args) throws OperatorCreationException, OperatorException{
            Test t = new Test();        
            t.createprocess();
        }
          public void createprocess() throws OperatorCreationException, OperatorException{
                RapidMiner.init();
                ExampleSet exampleset = getExampleset();

                Operator silimarityOperator = OperatorService.createOperator(ExampleSet2SimilarityExampleSet.class);
        //        silimarityOperator.setParameter("measure_type", "NumericalMeasures");
        //        silimarityOperator.setParameter("numerical_measure", "CosineSimilarity");

                Process process = new Process();
                process.getRootOperator().getSubprocess(0).addOperator(silimarityOperator);
                process.getRootOperator().getSubprocess(0).getInnerSources().getPortByIndex(0).connectTo( silimarityOperator.getInputPorts().getPortByName("input"));

                // run the process with new IOContainer using the created exampleSet
                IOContainer run = process.run(new IOContainer(exampleset));
                System.out.println(run.toString());




            }

            public ExampleSet getExampleset() {
        // construct attribute set
                Attribute[] attributes = new Attribute[3];
                attributes[0] = AttributeFactory.createAttribute("Topic1", Ontology.STRING);
                attributes[1] = AttributeFactory.createAttribute("Topic2", Ontology.STRING);
                attributes[2] = AttributeFactory.createAttribute("Topic3", Ontology.STRING);

                MemoryExampleTable table = new MemoryExampleTable(attributes);
                DataRowFactory ROW_FACTORY = new DataRowFactory(0);

                Double[] strings = new Double[3];

                double a = 0;
                for (int i = 0; i < 3; i++) {
                    a++;
                    strings[i] = a;
                    // make and add row
                    DataRow row = ROW_FACTORY.create(strings, attributes);

                    table.addDataRow(row);
                }

                ExampleSet exampleSet = table.createExampleSet();
                return exampleSet;
            }
    }

我找到了解决办法。我在接线员的连接上有错误。它不存在端口输入,因此我得到端口0

 process.getRootOperator().getSubprocess(0).getInnerSources().getPortByIndex(0).connectTo(  
          silimarityOperator.getInputPorts().getPortByIndex(0));

     silimarityOperator.getOutputPorts().getPortByIndex(0).connectTo(
          process.getRootOperator().getSubprocess(0).getInnerSinks().getPortByIndex(0));