Create macro with Java - Execute Script Operator

cs_diablocs_diablo MemberPosts:1Contributor I
edited November 2018 inHelp

Hi,

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 withthis 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);

table.addAttribute(nominalAttr);
table.addAttribute(dateAttr);

// 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
table.addDataRow(row);

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

return exampleSet;

I am really thankful for every help from you

Tagged:

Best Answer

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

    Hi,

    sorry for the late reply.

    This should do the trick:

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

    Best regards,

    Philipp

    homburg

Answers

  • KanikaAg15KanikaAg15 MemberPosts:19Contributor I
    @pschlunderthe 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, MemberPosts:245RM Engineering
    Hi Kanika,

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

    <?xml version = " 1.0 " encoding = " utf - 8 " ?> <过程版本sion="9.10.012">                                   

    Greetings,
    Jonas
Sign InorRegisterto comment.