If then statement

diellasinghdiellasingh Member Posts: 7 Contributor II
edited December 2018 in Help

Hello,

I am trying to write an "if then" statement to generate an attribute. I would like to replace the ".0" in the attribute "partNOconcat" with "" (Nothing).

 

For example: partNOconcat : AA10000.0AA

i would like to replace it to give me in my new attribute the following; newGenAtt: AA10000AA

 

I currently have the following as my expresion:

 

if(partNOConcat contains(partNoConcat,".0"),replace(partNoConcat,".0",""))

 

This gives me the following error: "Syntax Error (implicit mulitplication not enabled)"

 

Please could someone provide me with some guidence to where I am going wrong.

 

Thank you,

 

Diella

Tagged:

Best Answer

  • diellasinghdiellasingh Member Posts: 7 Contributor II
    Solution Accepted

     

    Hi Thomas,

     

    Thank you for your fast response time. I didn’t know that was possible to autopopulate a process from XML.

     

    About the syntax provided. I am not retrieving the desired output. I’m struggle to construct the third argument. Whereby I would like the value of the generated attribute (dot_zero) to have the attribute value of the [temp] for that particulate example if ".0" is not found within the [temp] attribute value.

     

    Syntax: if(contains(".0",partNoConcat),replace(".0",partNoConcat,""),partNoConcat)

     

    Please could you tell if this is even possible with the If function expression in RM.

    Thanks,

    Diella

     

Answers

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,761 Unicorn

    Your syntax is a bit off. Here's an example.

     

    <?xml version="1.0" encoding="UTF-8"?><process version="7.5.001">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="7.5.001" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="text:create_document" compatibility="7.4.001" expanded="true" height="68" name="Create Document" width="90" x="45" y="34">
    <parameter key="text" value="partNOconcat : AA10000.0AA"/>
    </operator>
    <operator activated="true" class="text:documents_to_data" compatibility="7.4.001" expanded="true" height="82" name="Documents to Data" width="90" x="179" y="34">
    <parameter key="text_attribute" value="temp"/>
    </operator>
    <operator activated="true" class="text_to_nominal" compatibility="7.5.001" expanded="true" height="82" name="Text to Nominal" width="90" x="313" y="34"/>
    <operator activated="true" class="generate_attributes" compatibility="7.5.001" expanded="true" height="82" name="Generate Attributes" width="90" x="447" y="34">
    <list key="function_descriptions">
    <parameter key="NewATT" value="if(contains(&quot;.0&quot;,[temp]),replace(&quot;.0&quot;,[temp],&quot;&quot;),&quot;RapidMiner&quot;)"/>
    </list>
    </operator>
    <connect from_op="Create Document" from_port="output" to_op="Documents to Data" to_port="documents 1"/>
    <connect from_op="Documents to Data" from_port="example set" to_op="Text to Nominal" to_port="example set input"/>
    <connect from_op="Text to Nominal" from_port="example set output" to_op="Generate Attributes" to_port="example set input"/>
    <connect from_op="Generate Attributes" from_port="example set output" 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>
  • diellasinghdiellasingh Member Posts: 7 Contributor II

    Hi Thomas,

     

    My coding level is fairly low, therefore I dont really understand the XML. So would you be able to show me the functional expression type out rather than in XML.

     

    Thanks,

     

    Diella

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,761 Unicorn

    The XML is the process I built to illustrate how to do it. You can paste it into the XML view and the process will autopopulate, it's a handy way to share processes in RapidMiner.

     

    If you juste need the syntax here it is: if(contains(".0",[temp]),replace(".0",[temp],""),"RapidMiner")

     

  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder

    Hi,

     

    And for future reference, here is a link describing how you can import this XML code into RapidMiner to get your visual process: http://community.rapidminer.com/t5/RapidMiner-Studio-Knowledge-Base/How-can-I-share-processes-without-RapidMiner-Server/ta-p/37047

     

    Cheers,

    Ingo

Sign In or Register to comment.