[Solved] How to create new tables, attributes and examples with a script?

qwertz
New Altair Community Member
Dear all,
initially I thought that this question would go along with my last post but after spending some hours trying, I thought that it might better fit in a new topic.
Thanks to Marco I found a way to manipulate example sets / tables with the script operator
(http://rapid-i.com/rapidforum/index.php/topic,8342.0.html)
But a short time after I ended up with the questions
-How to create a new table / example set with scripting?
-How to add new attributes and examples to the input example set?
-How to provide newly created and input example set together to the scripting output?
As mentioned in the linked post, I found a kind of documentation but probably I do something wrong with the syntax. Struggling for hours now
Please help
Cheers
Sachs
initially I thought that this question would go along with my last post but after spending some hours trying, I thought that it might better fit in a new topic.
Thanks to Marco I found a way to manipulate example sets / tables with the script operator
(http://rapid-i.com/rapidforum/index.php/topic,8342.0.html)
But a short time after I ended up with the questions
-How to create a new table / example set with scripting?
-How to add new attributes and examples to the input example set?
-How to provide newly created and input example set together to the scripting output?
As mentioned in the linked post, I found a kind of documentation but probably I do something wrong with the syntax. Struggling for hours now

Please help

Cheers
Sachs
Tagged:
0
Answers
-
Hi,
let me just start with a warning: Using "Execute Script" on a RapidMiner Server will result in problems, mainly eating up memory and never ever releasing it again unless the whole Server is restarted. Which is one of the reasons why we don't use this operator to solve customer problems.
Now that we got the warning out of the way, here you go
Regards,
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="6.1.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="6.1.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="retrieve" compatibility="6.1.000" expanded="true" height="60" name="Retrieve Iris" width="90" x="45" y="30">
<parameter key="repository_entry" value="//Samples/data/Iris"/>
</operator>
<operator activated="true" class="execute_script" compatibility="6.1.000" expanded="true" height="94" name="Execute Script" width="90" x="179" y="30">
<parameter key="script" value="import java.util.LinkedList; import java.util.List; import com.rapidminer.example.Attribute; import com.rapidminer.example.ExampleSet; import com.rapidminer.example.table.AttributeFactory; import com.rapidminer.example.table.DoubleArrayDataRow; import com.rapidminer.example.table.MemoryExampleTable; import com.rapidminer.tools.Ontology; List<Attribute> listOfAtts = new LinkedList<>(); // you can create any attribute type here, see Ontology class for more information Attribute newNumericAtt = AttributeFactory.createAttribute("Numerical Att", Ontology.ATTRIBUTE_VALUE_TYPE.NUMERICAL); listOfAtts.add(newNumericAtt); Attribute newNominalAtt = AttributeFactory.createAttribute("Nominal Att", Ontology.ATTRIBUTE_VALUE_TYPE.POLYNOMINAL); listOfAtts.add(newNominalAtt); MemoryExampleTable table = new MemoryExampleTable(listOfAtts); // every row is a double array internally double[] doubleArray = new double[listOfAtts.size()]; doubleArray[0] = 42; doubleArray[1] = newNominalAtt.getMapping().mapString("hello"); table.addDataRow(new DoubleArrayDataRow(doubleArray)); ExampleSet exSet = table.createExampleSet(); // return multiple outputs via List List<IOObject> returnList = new LinkedList<>(); returnList.add(input[0]); returnList.add(exSet); return returnList;"/>
</operator>
<connect from_op="Retrieve Iris" from_port="output" to_op="Execute Script" to_port="input 1"/>
<connect from_op="Execute Script" from_port="output 1" to_port="result 1"/>
<connect from_op="Execute Script" from_port="output 2" to_port="result 2"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
<portSpacing port="sink_result 3" spacing="0"/>
</process>
</operator>
</process>
Marco0 -
Thanks a lot! It's so helpful to have a piece of example code in order to understand the basics!
For all other users that work on the same topic I would like to reference to two similar yet slighly different posts:
http://rapid-i.com/rapidforum/index.php?topic=2214.0
http://rapidminernotes.blogspot.de/2013/06/using-groovy-to-make-arbitrary-example.html
Best regards
Sachs0 -
I just came across the manual "How to extend Rapidminer" which is linked in the documentation overview http://rapidminer.com/documentation/
This is definitely worth reading for everyone who wants to start with scripts!0