Execute Script Operator output

preethypreethy Member Posts: 7 Contributor II
edited November 2018 in Help

I am very new to Rapidminer. I am developing a text classifier. It requires a spell correction module which is not present in my Rapidminer version. I am trying to write a script to do that using Execute Script operator. The input to the script operator is connected from the filter documents operator. My question is, I do not have example sets to work on. I understand that I can use input ports to get the input from . How will I output the data as a document.? Could you please share some thoughts.



  • Options
    Marco_BoeckMarco_Boeck Administrator, Moderator, Employee, Member, University Professor Posts: 1,996 RM Engineering

    have a look at the following:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="6.4.000-SNAPSHOT">
      <operator activated="true" class="process" compatibility="6.4.000-SNAPSHOT" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="text:create_document" compatibility="6.1.000" expanded="true" height="60" name="Create Document" width="90" x="45" y="30">
            <parameter key="text" value="Hello!&#10;Small example for document processing with the &quot;Execute Script&quot; operator!"/>
          <operator activated="true" class="text:tokenize" compatibility="6.1.000" expanded="true" height="60" name="Tokenize" width="90" x="179" y="30"/>
          <operator activated="true" class="execute_script" compatibility="6.4.000-SNAPSHOT" expanded="true" height="76" name="Execute Script" width="90" x="313" y="30">
            <parameter key="script" value="import com.rapidminer.operator.text.Document;&#10;import com.rapidminer.operator.text.Token;&#10;&#10;import java.util.List;&#10;import java.util.LinkedList;&#10;&#10;Document doc = input[0];&#10;&#10;int counter = 0;&#10;List&lt;Token&gt; newTokens = new LinkedList&lt;&gt;();&#10;for (Token token : doc.getTokenSequence()) {&#10;&#9;Token nToken = new Token(counter + &quot;: &quot; + token.getToken(), token);&#10;&#9;newTokens.add(nToken);&#10;&#9;counter++;&#10;}&#10;doc.setTokenSequence(newTokens);&#10;&#10;return doc;"/>
          <connect from_op="Create Document" from_port="output" to_op="Tokenize" to_port="document"/>
          <connect from_op="Tokenize" from_port="document" 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"/>
    working on documents, the IOObject class is com.rapidminer.operator.text.Document instead of ExampleSet.

  • Options
    preethypreethy Member Posts: 7 Contributor II
    Thanks alot Macro. It helped me.
Sign In or Register to comment.