How to copy attribute columns into new example set with the script operator

qwertz2qwertz2 Member Posts: 49 Guru
edited November 2018 in Help


Dear community,

As a part of a larger script I am trying to copy selected attribute columns to a new example set.

Source example set:
label  att1   att2
1      a      1x
2      b      1y
3      c      1z

Target shall look like this (att2 copied from source):
att2
1x
1y
1z

My script looks currently like this:

import com.rapidminer.tools.Ontology;
exampleSet sourceTable = input[ 0 ];
exampleSet targetSet = new ExampleSet();
targetSet.addAttribute(sourceTable.getAttribute("att2"));
return targetSet;


Looking forward to any feedback...


PS: There are likely various ways to get from the original example set to the target one. But context of my whole script I am looking especially for a way to copy an attribute column.

 

PPS: By the way, is there any chance to access the values of macros in a script?


Best regards
Sachs

 

 

<?xml version="1.0" encoding="UTF-8"?><process version="7.5.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="7.5.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="generate_data" compatibility="7.5.000" expanded="true" height="68" name="Generate Data" width="90" x="45" y="34"/>
<operator activated="true" class="execute_script" compatibility="7.5.000" expanded="true" height="82" name="Execute Script" width="90" x="179" y="34">
<parameter key="script" value="import com.rapidminer.tools.Ontology;&#10;exampleSet sourceTable = input[ 0 ];&#10;exampleSet targetSet = new ExampleSet();&#10;targetSet.addAttribute(sourceTable.getAttribute(&quot;att2&quot;));&#10;return targetSet;"/>
</operator>
<connect from_op="Generate Data" from_port="output" to_op="Execute Script" to_port="input 1"/>
<connect from_op="Execute Script" from_port="output 1" 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"/>
</process>
</operator>
</process>

Answers

  • binsetyawanbinsetyawan Member Posts: 46 Guru

    you can use select attribute operator and change the attribute type with regular expression and fill the regular expression with the name of your attribute that you want

  • qwertz2qwertz2 Member Posts: 49 Guru

     

    Hi binsetyawan,

     

    Thank you for contributing. The point is that this is only a small excerpt from the whole script and I would like to handle this part within the script, too.

     

    Kind regards

    Sachs

Sign In or Register to comment.