"Load singleMacroDefinition into groovy"

CleoCleo Member Posts: 44 Maven
edited June 2019 in Help
Hello,

I have two operators which gives input to groovy.
ExampleSet exampleSet = operator.getInput(ExampleSet.class,1);
ExampleSet exampleSet2 = operator.getInput(ExampleSet.class,0);

One exampleSet1 is data from a database query, while exampleSet2 is from an excel file.  What I would like to do, is change the input from a database query and excel file, to a database query, and 3 SingleMacroDefinition operators.

Thanks
Cleo
Tagged:

Answers

  • CleoCleo Member Posts: 44 Maven
    Hello,

    I have tried several different setups in an attempt to load the macro values into an Execute Script.

    I have an Execute Script Operator, with a Set Macros, and a Set Macro Operator attached to it.

    Within the Execute Script Operator I print the results of the following statements.

    operator.hasInput(DataMacroDefinitionOperator.class);
    operator.hasInput(Macro2Log.class);
    operator.hasInput(MacroConstructionOperator.class);
    operator.hasInput(MacroDefinitionOperator.class);
    operator.hasInput(SingleMacroDefinitionOperator.class);

    Each time I get false.

    In a different setup I attach the Set Macro Operator to a Log Operator, which writes the value of the macro to a file, then attach it to an Execute Script Operator.  Within the Execute Script Operator, I have not been able to access the information within the Log Operator. 

    operator.getLog().toString();

    I can attach the Set Macro Operator to a Log Operator, write the macro information to a file then read the file from the execute script operator but I think there should be a better way to do this.

    Any suggestions,

    Thanks,
    Cleo
  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531 Unicorn
    Hi,
    Macros aren't delivered over input ports like usual IOObjects. Instead they are set globally in the process. The macro operators doesn't need input and output, but they provide ports forwarding the inputs for giving the user a possibility to define the execution order in an easy way.

    So all you have to do is to ensure that the set macro operators has been executed before the scripting operator is started. Then you could access all macros using this code:
    		MacroHandler handler = getProcess().getMacroHandler();
    Iterator<String> iterator = handler.getDefinedMacroNames();
    while (iterator.hasNext()) {
    System.out.println(handler.getMacro(iterator.next()));
    }
    Greetings,
      Sebastian
  • CleoCleo Member Posts: 44 Maven
    Thanks for the reply.

    FYI: I am using RM 5 RC. 5.0.1

    I tried the above code and got the following error.

    Message: The scripting engine Groovy reported an error in the script: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script1.groovy: 12: unable to resolve class MacroHandler
    @ line 12, column 14.Script1.groovy: 13: unable to resolve class MacroHandler
    @ line 13, column 29.Script1.groovy: 15: unable to resolve class MacroHandler
    @ line 15, column 23.
    3 errors


    So I added the line:
    inculde com.rapidminer.MacroHandler;

    It then gave me the error

    Message: The scripting engine Groovy reported an error in the script: groovy.lang.MissingMethodException: No signature of method: Script1.getProcess() is applicable for argument types: () values: [].

    I then added the line:
    import com.rapidminer.Process;

    and nothing happened.



    To ensure the set macro operator has been executed before the script operator has started I have:
    Verified that the set macro operator is above the script operator within the tree view.
    Included an additional Script operator with the following code:

    synchronized(this) {
    wait(2000);
    }


    in between the set macro operator, and the Script operator trying to access the macro information.



    Questions:
    1) Any suggests to debug this problem?
    2) I could not find documentation on the function getProcess() could you please point me to it.  Is there a list of global functions and variables available to the Script operator?
    3) The "this" in the function synchronized(this).  What object type is it?
    4) Unrelated question, but can I write the macro to dynamically write sql queries for the Read Database Operator?

    Thanks,
    Cleo
  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531 Unicorn
    Hi,
    I guess you have to and an
    import com.rapidminer.MacroHandler;
    It seems to me, it's the only combination you didn't try :)

    Greetings,
      Sebastian
  • CleoCleo Member Posts: 44 Maven
    Hi Sebastian,

    I did try  :)
    import com.rapidminer.MacroHandler;

    This code removed the first set of errors.  The global function "getProcess()"
    seems to be the source of the second set of errors.

    I tried to add the code
    import com.rapidminer.Process;
    in an attempt to eliminate this problem but it did not work.

    I could not find any documentation on the function getProcess().

    Now that the RM 5 RC source code is released on sourceforge I may try to debug the problem from that.

    Thanks,
    Cleo

  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531 Unicorn
    Hi,
    I took a look in that matter and found that "this" is defined inside the script to be the script itself. The current operator might be reached over the predefined variable "operator". Take a look at this code:
    import com.rapidminer.operator.Operator;
    import com.rapidminer.Process;

    Operator learnOp = operator.getProcess().getOperator("Learn");
    if (learnOp != null)
    learnOp.setEnabled(false);
    I will note this in the whitepaper for extending RapidMiner...


    Greetings,
      Sebastian
  • CleoCleo Member Posts: 44 Maven
    Thanks again Sebastian.

    This works perfectly now. :)

    Cheers,
    Cleo
Sign In or Register to comment.