Syntax Error - Generate Macro

mobmob Member Posts: 37 Contributor II
edited November 2018 in Help
I'm trying to build up a string to use as a file name but I'm having trouble getting the macro to generate correctly
My generate macro expression is
str('Var1') + "_" + str('Var2')  +" _" + str('Var3') +".txt"
where Var1,2,3 are attributes from the exampleset

what I'd like to end up with is a macro value like
Team2_Results_Summer.txt
Team2_Predict_Summer.txt
Team9_Results_Spring.txt

but all I get is a Syntax error even when the function express says the "Expression is syntactically correct" and the process won't continue after the Generate Macro operator
Tagged:

Answers

  • mobmob Member Posts: 37 Contributor II
    If I add an exception handling process and log the exception I get
    com.rapidminer.operator.UserError: Generation exception: 'Syntax error'

    which doesn't really go a long way to helping me debug the problem.

    I'm trying to create a unique filename for each entry in an exampleset so I can write a document (collection of tokens) to disk with 1 file per example set record
  • MartinLiebigMartinLiebig Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 3,485 RM Data Scientist
    Hi mob,

    don't use quotes around the variable names. it is:
    str(att1) + "_" + str(att2)  +" _" + str(att3) +".txt"
    or
    str([att1]) + "_" + str([att2])  +" _" + str([att3]) +".txt"

    ~Martin
    - Sr. Director Data Solutions, Altair RapidMiner -
    Dortmund, Germany
  • mobmob Member Posts: 37 Contributor II
    When I remove the ' or when I replace them with square brackets
    I get the error
    Generation exception: 'Unrecognized symbol "att1"
    Unrecognized symbol "att2"
    Unrecognized symbol "att3"
    '
  • MartinLiebigMartinLiebig Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 3,485 RM Data Scientist
    does att1 exsist in your data?
    - Sr. Director Data Solutions, Altair RapidMiner -
    Dortmund, Germany
  • mobmob Member Posts: 37 Contributor II
    Yes its a polynominal with the label role, the other attributes are a text value and a nominal value. There are no missing values in my dataset
    The values are also listed in the attributes pane of the functions expressions screen of generate macro operator
  • Marco_BoeckMarco_Boeck Administrator, Moderator, Employee, Member, University Professor Posts: 1,993 RM Engineering
    Hi,

    which version of RapidMiner Studio are you using?

    Regards,
    Marco
  • mobmob Member Posts: 37 Contributor II
    Using RapidMiner 5.3 but tried it on Rapidminer 7 today and it doesn't throw an error but also the macro doesn't get populated with a value and the write document operator creates a file names after the macro which gets overwritten (or not if I tick the properties)
  • mobmob Member Posts: 37 Contributor II
    Attached is an example process including sample data where the macro expression function isn't evaluated but is instead output directly. Can anyone help resolve this?
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.3.015">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.3.015" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="generate_data_user_specification" compatibility="5.3.015" expanded="true" height="60" name="Generate Data by User Specification" width="90" x="45" y="90">
            <list key="attribute_values">
              <parameter key="Dept" value="&quot;Name_and_Role&quot;"/>
              <parameter key="Institution" value="&quot;ABC&quot;"/>
              <parameter key="OldKey" value="&quot;abc_1&quot;"/>
            </list>
            <list key="set_additional_roles"/>
          </operator>
          <operator activated="true" class="replace" compatibility="5.3.015" expanded="true" height="76" name="Replace Comma" width="90" x="179" y="75">
            <parameter key="attribute_filter_type" value="single"/>
            <parameter key="attribute" value="Dept"/>
            <parameter key="replace_what" value="','"/>
            <parameter key="replace_by" value="_"/>
          </operator>
          <operator activated="true" class="replace" compatibility="5.3.015" expanded="true" height="76" name="Remove punctation" width="90" x="313" y="120">
            <parameter key="attribute_filter_type" value="single"/>
            <parameter key="attribute" value="Dept"/>
            <parameter key="attributes" value="|Dept"/>
            <parameter key="replace_what" value=" [-!&quot;#$%&amp;'()*+,./:;&lt;=&gt;?@\[\\\]_`{|}~]"/&gt;
          </operator>
          <operator activated="true" class="replace" compatibility="5.3.015" expanded="true" height="76" name="Replace space" width="90" x="447" y="165">
            <parameter key="attribute_filter_type" value="single"/>
            <parameter key="attribute" value="Dept"/>
            <parameter key="attributes" value="|Dept"/>
            <parameter key="replace_what" value=" "/>
            <parameter key="replace_by" value="_"/>
          </operator>
          <operator activated="true" breakpoints="before,after" class="set_macro" compatibility="5.3.015" expanded="true" height="76" name="Set Macro" width="90" x="581" y="165">
            <parameter key="macro" value="macFileName"/>
            <parameter key="value" value="str(Institution) + &quot;_&quot; + str(Dept)  +&quot; _&quot; + str(OldKey) +&quot;.txt&quot;"/>
          </operator>
          <connect from_op="Generate Data by User Specification" from_port="output" to_op="Replace Comma" to_port="example set input"/>
          <connect from_op="Replace Comma" from_port="example set output" to_op="Remove punctation" to_port="example set input"/>
          <connect from_op="Remove punctation" from_port="example set output" to_op="Replace space" to_port="example set input"/>
          <connect from_op="Replace space" from_port="example set output" to_op="Set Macro" to_port="through 1"/>
          <connect from_op="Set Macro" from_port="through 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>
Sign In or Register to comment.