Create macro with Java - Execute Script Operator

cs_diablocs_diablo Member Posts: 1 Contributor I
edited November 2018 in Help



I wish to create macro starting from an object in java in Execute Script operator. In my example, I recover the date of a file and I wish to use it thereafter as macro in my RapidMiner process. I don't know how to exit this object of the Execute Script operator in the form of macro.


LastDate = Files.getLastModifiedTime(Paths.get("%{Way}")) ;

// and after ?

If not I had found an alternative by creating a table and while inserting the date inside. But I did not succeed in inserting this date in table.

(I am to help with this post)


LastDate = Files.getLastModifiedTime(Paths.get("%{Way}")) 

// create a table
MemoryExampleTable table = new MemoryExampleTable();

// create and add attributes
nominalAttr = AttributeFactory.createAttribute("File", Ontology.NOMINAL);
dateAttr = AttributeFactory.createAttribute("Last_Modify",Ontology.DATE_TIME);


// create a data row
DataRow row = new DoubleSparseArrayDataRow();

row.set(nominalAttr, nominalAttr.getMapping().mapString("%{file_name}"));
row.set(dateAttr, LastDate);

// add the row to the table

// create an ExampleSet from the underlying table
ExampleSet exampleSet = table.createExampleSet();

return exampleSet;


I am really thankful for every help from you


Best Answer

  • pschlunderpschlunder Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, RMResearcher, Member Posts: 96 RM Research
    Solution Accepted


    sorry for the late reply.


    This should do the trick:

    operator.getProcess().getMacroHandler().addMacro("Key", "Value");


    Best regards,




  • KanikaAg15KanikaAg15 Member Posts: 14 Contributor I
    @pschlunder the function you have specified is failing in the static scope of a script in java. Do we need to import any library or change the data type of the function. 
  • jwpfaujwpfau Employee, Member Posts: 180 RM Engineering
    Hi Kanika,

    here is a full example process which is using the Code Snippet:

    <?xml version="1.0" encoding="UTF-8"?><process version="9.10.012">
      <operator activated="true" class="process" compatibility="9.10.012" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="SYSTEM"/>
        <process expanded="true">
          <operator activated="true" class="retrieve" compatibility="9.10.012" expanded="true" height="68" name="Retrieve Deals" width="90" x="45" y="34">
            <parameter key="repository_entry" value="//Samples/data/Deals"/>
          <operator activated="true" class="execute_script" compatibility="9.10.012" expanded="true" height="82" name="Execute Script" width="90" x="179" y="34">
            <parameter key="script" value="/* &#10; * You can use both Java and Groovy syntax in this script.&#10; * &#10; * Note that you have access to the following two predefined variables:&#10; * 1) input (an array of all input data)&#10; * 2) operator (the operator instance which is running this script)&#10; */&#10;&#10;// Take first input data and treat it as generic IOObject&#10;// Alternatively, you could treat it as an ExampleSet if it is one:&#10;// ExampleSet inputData = input[0];&#10;IOObject inputData = input[0];&#10;&#10;// You can add any code here&#10;operator.getProcess().getMacroHandler().addMacro(&quot;Macro&quot;, &quot;Lazy Example&quot;);&#10;&#10;&#10;// This line returns the first input as the first output&#10;return inputData;"/>
            <parameter key="standard_imports" value="true"/>
          <operator activated="true" class="generate_attributes" compatibility="9.10.012" expanded="true" height="82" name="Generate Attributes" width="90" x="313" y="34">
            <list key="function_descriptions">
              <parameter key="Macro" value="%{Macro}"/>
            <parameter key="keep_all" value="true"/>
          <connect from_op="Retrieve Deals" from_port="output" to_op="Execute Script" to_port="input 1"/>
          <connect from_op="Execute Script" from_port="output 1" to_op="Generate Attributes" to_port="example set input"/>
          <connect from_op="Generate Attributes" from_port="example set output" to_port="result 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>

Sign In or Register to comment.