Syntax Error - Generate Macro

mob
mob New Altair Community Member
edited November 2024 in Community Q&A
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

Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

  • mob
    mob New Altair Community Member
    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
  • MartinLiebig
    MartinLiebig
    Altair Employee
    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
  • mob
    mob New Altair Community Member
    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"
    '
  • MartinLiebig
    MartinLiebig
    Altair Employee
    does att1 exsist in your data?
  • mob
    mob New Altair Community Member
    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_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    which version of RapidMiner Studio are you using?

    Regards,
    Marco
  • mob
    mob New Altair Community Member
    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)
  • mob
    mob New Altair Community Member
    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>

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.