Running a process from inside NetBeans

Miritar_6Miritar_6 Member Posts: 12 Contributor I
edited November 2018 in Help

Hello ^_^

i'm sorry but i guess i have the typical question , how can i run my process from inside the NetBeans

i know the problem here is in the path because i read a lot about this problem but no answer could really make me understand the solution

my code is

 try {
           
          RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
          RapidMiner.init();
          Process process = new Process (new File("C:\Users\SAR\.RapidMiner\repositories\Local Repository\processes"));//the problem is here and i can't access the repository

          process.run();

        } catch (IOException | XMLException | OperatorException ex) {
          ex.printStackTrace();

what is the exact path should i use here or using the other method

RepositoryLocation loc = new RepositoryLocation("//Local Repository/Users/SAR/.RapidMiner/repositories/Local Repository/processesKNN2.rmp");//i know the path here is not working right too
Process process = new RepositoryProcessLocation(loc).load(null);

process.run()

thank you in advance

 

Tagged:

Best Answer

  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder
    Solution Accepted

    Actually everything works as expected with the process loading.  But now you have a new problem: since you load the process without a repository connection now, you cannot resolve the path to your data (since the process is built from a string it does not know where it lives...).  Replace the data loading in your process with Read XYZ operator reading the data from a file with an absolute path reference and you should be fine...

     

    Again, you might also be able to load from the repository but then you need to let your program know where the repositories are... I unfortunately do not know how this is done but maybe somebody else does...

     

    Cheers,

    Ingo

Answers

  • Miritar_6Miritar_6 Member Posts: 12 Contributor I

    just need to know the exact path to use please to reach my processes

  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder

    I don't know about the path but if the process in a file (as it seems to be) you could use regular Java methods (file reader etc.) to read the XML and then create the Process object based on the XML string...

     

    Hope this helps,

    Ingo

  • Miritar_6Miritar_6 Member Posts: 12 Contributor I

    thanks a lot but i really need to know how to access my repository without using XML files...but is there a detailed code for running process as a xml file?

  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder

    If you save the process in Studio via "File" - "Export Process...", the created .rmp file will have the right XML format.  You then read the whole content of this file via plain Java (see for example here: http://javarevisited.blogspot.com/2015/02/how-to-read-file-in-one-line-java-8.html).  Let's assume the XML string is stored in the variable "xmlOfProcess", the code to create the process object is then simply

     

    Process process = new Process(xmlOfProcess);

     

    Still I do not know how to read a process from a repository.  The path you used looks correct, but maybe your Netbeans installation does not know about where the repositories are stored...

     

    Anyway, hope this helps.  Cheers,

    Ingo

  • Miritar_6Miritar_6 Member Posts: 12 Contributor I

    Thank you so much but the link you providrd didn't open...is there another link please?

  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder
  • Miritar_6Miritar_6 Member Posts: 12 Contributor I

    Sorry to bother again but is this right using the way you mentioned?? cause i don't think i really get it

      try {
               String s = new String (readAllBytes(get("C:\\Users\\SAR\\Desktop\\g.rmp")));
              RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
              RapidMiner.init();
        process.run(s);

            } catch (IOException | XMLException | OperatorException ex) {
              ex.printStackTrace();

  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder

    Aeh, no :-)

     

    Here are three code snippets which should help. First you initialize RapidMiner like you do.  That part is fine.

     

    Then, you read the XML from a file or URL.  As I said, there are dozens of methods to do that.  Here is a code snippet I found online:

     

    private String readFile(String fileName) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(fileName));
    String line = null;
    StringBuilder stringBuilder = new StringBuilder();
    String ls = System.getProperty("line.separator");

    try {
    while((line = reader.readLine()) != null) {
    stringBuilder.append(line);
    stringBuilder.append(ls);
    }

    return stringBuilder.toString();
    } finally {
    reader.close();
    }
    }

     

    Now you create a process:

     

    process = null;
    try {
    process = new Process(processXML);
    } catch (IOException | XMLException e) {
    // do something
    }

     

    Finally, you run the process and collect the results:

     

    IOContainer results;
    try {
    results = process.run();
    } catch (Throwable e) {
    // do something
    }

     

    You can now query the results from the IOContainer, for example with something like this:

     

    ExampleSet data = null;
    try
    {
    data = results.get(ExampleSet.class);
    } catch (MissingIOObjectException e) {
    // do something
    }

     

    This should do the trick.

     

    Cheers,

    Ingo

  • Miritar_6Miritar_6 Member Posts: 12 Contributor I

    Hello
    i put the function "readFile" exactly like you mentioned in the first block of code just added "statsic" so i can call it in the main

    inside the main :

     

     

     

       RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
        RapidMiner.init();
        String s;
       try
       {
           s=readFile("C://Users//SAR//.RapidMiner//repositories//Local Repository//processes//KNN2.rmp");
           Process process = null;
           process = new Process(s);
           IOContainer results;
           results = process.run();
           ExampleSet data = null;
           data = results.get(ExampleSet.class);
           System.out.println(data);
       }
       catch (Exception  ex)
       {
       System.out.println("EXCEPTION");
        ex.printStackTrace();
        System.out.println(ex.toString());
       }

    and it gave the same error :

    com.rapidminer.operator.UserError: Cannot resolve relative repository location '../data/Final DataSet'. Process is not associated with a repository.

    where "Final DataSet" is the set inside my processes...is there a solution??

  • Miritar_6Miritar_6 Member Posts: 12 Contributor I

     from inside the rapidMiner studio i replaced the retrieve ioerator with "read excel" operator the error changed to :

    The operator needs some input of type com.rapidminer.example.ExampleSet which is not provided.

    what can i do now?? thank you very much for your answers

  • Miritar_6Miritar_6 Member Posts: 12 Contributor I

    thanks a lot the process worked fine i just replaced the retrieve operator with "Read Excel" thaaaank you

Sign In or Register to comment.