Categories

Versions

You are viewing the RapidMiner Studio documentation for version 9.7 -Check here for latest version

Macros

宏是什么?

A macro is a key–value pair that is only available during the process execution. Predefined macros contain context related information like the current iteration of a loop or the process name. Macros can be defined during runtime with theSet Macros,Generate MacrosorExtract Macrooperator, and used in nearly every operator parameter field. It is also possible to define static macros in theContext Panel(View➟Show Panel➟Context).

Debugging Macros

User defined macros can be watched with theMacros Panel(View➟Show Panel➟Macros). In this panel the current values of the macros are displayed. Use breakpoints before and after you set the macro to see the change.

List of predefined Macros

Process Macros

Macro Value Description
%{process_name} 02_LinearRegression current process name
%{process_file} 02_LinearRegression.rmp
02_LinearRegression
process file name (opened as file)
process name (opened from repository)
%{process_path} C:\02_LinearRegression.rmp
//Repo/02_LinearRegression
file path (opened as file)
repository path (opened from repository)
%{process_start} 2017_12_24-PM_00_01_25 process start date and time
%{t} 2017_12_24-PM_00_01_30 current date and time

For higher accuracy requirements use thedate_now()function instead of%{t}.

③ator Macros

Macro Value Description
%{execution_count}
%{a}
1 number of times the current operator is executed
%{b} 2 execution_count + 1
%{operator_name}
%{n}
Generate Data (user given) name of the current operator
%{c} com.rapidminer.GenerateData package and class of the current operator

③ators likeLoop, orHandle Exceptionprovide additional macros.

Macros and functions

Parsing Numbers

We've seen before that%{b}returns execution_count + 1, but what if we need execution_count - 1?
This can be achieved with the function expressionparse(%{execution_count})-1for theGenerate Macrooperator.

Parsing Dates

To parse a date macro into a date we can usedate_parse_custom(%{process_start},"yyyy_MM_dd-a_KK_mm_ss"). A table of all pattern letters can be found underSimpleDateFormat.

Evaluating Macros

It is possible to store an expression as an nominal value with theSet Macrosoperator and execute it afterwards with theeval(%{macro})function. Please be aware that theevalfunction, like all other functions, is only available for selected operators. To use the evaluated macro value in every field, use theGenerate Macrooperator beforehand and store the result of the evaluation in a new macro.