2014-10-19 1 views
0

나는 유사성을 측정하는 프로세스를 생성한다. ExampleSet2SimilarityExampleSetoperator를 사용하고 입력으로 내 코드에서 생성 된 예제 세트를 추가하고 싶습니다.세트 Exampleet to ExampleSet2SimilarityExampleSet 자바가있는 Rapidminer 연산자

첫 번째 아이디어는 예제 저장소를 로컬 저장소에 작성하는 것입니다. 그런 다음 retrieve 연산자를 사용하여 예제 세트를 읽고 연산자 추출의 출력을 ExampleSet2SimilarityExample 연산자의 입력에 연결합니다.

그래서 내가 읽기/쓰기를 피할 수 있는지 궁금합니다.

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

해결책을 찾았습니다. 교환 원과 연결시 오류가 있습니다. 포트 입력이 존재하지 않으므로 포트 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));