Groovy scripts

RapidMiner comes with Groovy already installed. This is a scripting language that is extremely close to Java in syntax and a process can run Groovy scripts by using the Execute Script operator. Groovy is very powerful and there are times when nothing else would do. Groovy can be used to output detailed information about anything in the RapidMiner Studio environment and this can be very useful when debugging.

Outputting macros example

The following Groovy script outputs the values of all the macros defined in the process to the console. This is extremely valuable for debugging. A recent release of RapidMiner Studio provide a neat GUI interface that provides the same information; however, it may still be valuable to have a more permanent record for detailed diagnosis. The following code shows the Groovy script that would be used with the Execute Script operator:

Outputting macros example

The line containing getDefinedMacroNames finds all the macros; the name-value pairs are accessed in turn and are output to the operator console.

If this script runs and encounters a macro called M1 with the value M1Value, the Log view would contain the following text:

Execute Script: Macro name | value: M1 | M1Value

The process that does this is groovyExample.xml, which is provided with this book.

Console logging with Groovy

Sometimes debugging Groovy is a problem and code instrumentation is the only way out. The following fragment of Groovy prints the output to the console:

operator.logNote ("Macro name | value: " + macroName + " | " + macroValue);

This is invaluable when getting Groovy scripts working in the RapidMiner Studio environment. Note that this was shown in the example Groovy script in the previous screenshot.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset