"[SOLVED] How to set macros via Java code?"

sixofonesixofone Member Posts: 9 Contributor II
edited June 2019 in Help
Hi, I have a small Java app that runs a RapidMiner 5.3 process and it is working pretty well.  

Recently, we added the ability to set macro values via the RapidMiner command line and now I need to add support for setting the macro values to my Java code and can't seem to find how to do that. I would think this should be relatively simple to do. Does any example code snippets exist?

Following is a snippet of my current RapidMiner related code:

RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE);
RapidMiner.init();
Process rm5 = new Process(new File("/home/petes/Documents/NewRmRepository/FindObjectsStep3Clusters.rmp"));
rm5.run();
Thanks for any guidance or suggestions.
Pete

Answers

  • SkirzynskiSkirzynski Member Posts: 164 Maven

    Pair<String, String> macro = new Pair<String, String>("macro", "value")
    rm5.getContext().addMacro(macro);
    By the way, when you start RapidMiner from the command line you are already able to set the macros with the -Mname=value switch.
  • sixofonesixofone Member Posts: 9 Contributor II
    thanks for the quick reply and sample!

    yes, I know we can set the macros from the command and we use that a lot now.  You could consider my app a wrapper of sorts around the command line executions for several RapidMiner processes that should be executed in a specific order and we run them via cron daily.  A gross oversimplification but some context for what I am doing here.

    thanks again
  • SkirzynskiSkirzynski Member Posts: 164 Maven
    It seems that RapidAnalytics can do this for you as well, so this could be an alternative? Nevertheless, if you are integrating RapidMiner in your program don't forget to choose the proper license or contact our sales team.  ;)

    Happy hacking!
      Marcin
  • sixofonesixofone Member Posts: 9 Contributor II
    Marcin,
    We have heard RapidAnalytics does most of what I really want to do and I have that on my task list to trial in the near future.  I do understand the licensing considerations and in our current state, researching practical uses for our analytics, this is used internally by my team. Depending on our results and our trial of RapidAnalytics, this code my never see broad use but is a great learning experience for me in any case.  ::)

    In followup to your suggestion, please excuse my Java / RapidMiner ignorance, but when I added the following code:

    import com.rapidminer.tools.container.Pair;

    Pair<String, String> macro = Pair<String, String> ("query_type", "0");
    rm5.getContext().addMacro(macro);
    The following errors are reported via eclipse:
    On the Pair to the right of =  error > Pair cannot be resolved to a variable

    On "query_type"  error > The left-hand side of an assignment must be a variable

    I suspect am missing something basic but any guidance would be appreciated.
    thanks again
    Pete
  • SkirzynskiSkirzynski Member Posts: 164 Maven
    Sorry, this was my fault. Of course you have to create the pair object. The "new" keyword is missing.

    Pair<String, String> macro = new Pair<String, String>("query_type", "0");
    rm5.getContext().addMacro(macro);
  • sixofonesixofone Member Posts: 9 Contributor II
    well a big DOH to me - I should have caught that !  :o

    thanks again...

    works as expected!!!  ;D
Sign In or Register to comment.