Execute Script
Synopsis
This operator executes Java code and/or Groovy scripts. This basically means that users can write their own operators directly within the process by specifying Java code and/or a Groovy script which will be interpreted and executed during the process runtime.
Description
This is a very powerful operator because it allows you to write your own script. This operator should be used if the task you want to perform through your script cannot be performed by existing RapidMiner operators because writing scripts can be time-consuming and error-prone.
Groovy is an agile and dynamic language for the Java Virtual Machine. It builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk. Groovy integrates well with all existing Java classes and libraries because it compiles straight to Java bytecode so you can use it anywhere you can use Java. For a complete reference of Groovy scripts please refer tourl = " http://groovy.codehaus.or <参考g/">http://groovy.codehaus.org/
.
In addition to the usual scripting code elements from Groovy, the RapidMiner scripting operator defines some special scripting elements:
If thestandard importsparameter is set to true, all important types like Example, ExampleSet, Attribute, Operator etc as well as the most important Java types like collections etc are automatically imported and can directly be used within the script. Hence, there is no need for importing them in your script. However, you can import any other class you want and use it in your script.
The current operator (the scripting operator for which you define the script) is referenced byoperator.
Example:operator.log("text")
All operator methods likelog(see above) that access the input or the complete process can directly be used by writing a precedingoperator.
Example:operator.getProcess()
Input of the operator can be retrieved via the input methodgetInput(Class)of the surroundingoperator.
Example:ExampleSet exampleSet = operator.getInput(ExampleSet.class)
You can iterate over examples with the following construct:
for (Example example : exampleSet) { ... }
You can retrieve example values with the shortcut:
In case of non-numeric values:String value = example["attribute_name"];
In case of numeric values:double value = example["attribute_name"];
You can set example values with the shortcut:
In case of non-numeric values:example["attribute_name"]= "value";
In case of numeric values:example["attribute_name"]= 5.7;
Please study the attached Example Processes for better understanding. Please note that Scripts written for this operator may access Java code. Scripts may hence become incompatible in future releases of RapidMiner.
Input
input
The Script operator can have multiple inputs. When one input is connected, anotherinputport becomes available which is ready to accept another input (if any).
Output
output
The Script operator can have multiple outputs. When one output is connected, anotheroutputport becomes available which is ready to deliver another output (if any).
Parameters
Script
The script to be executed is specified through this parameter.
Standard imports
If thestandard importsparameter is set to true, all important types like Example, ExampleSet, Attribute, Operator etc as well as the most important Java types like collections etc are automatically imported and can directly be used within the script. Hence, there is no need for importing them in your script. However, you can import any other class you want and use it in your script.