"[SOLVED] How to filter string"

CharlieFirpoCharlieFirpo Member Posts: 48 Contributor II
edited June 2019 in Help
Dear all!

I have a table with one column that has string values like string1string2string3.... I want filter out only the rows that contains specific string like string2.
Can you help me to solve this? The string1string2... can contain special characters like " , : ...
In SQL, I can use a query like this: SELECT * FROM <table name> WHERE <column name> LIKE '%<specific string>%'

Thank you!!!
Tagged:

Answers

  • awchisholmawchisholm RapidMiner Certified Expert, Member Posts: 458 Unicorn
    Hello

    One way is to generate a new attribute that is set to true or false depending on whether it matches. From there filter out the false values and for completeness remove the new attribute.

    Here's an example
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.3.008">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.3.008" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="generate_data_user_specification" compatibility="5.3.008" expanded="true" height="60" name="Generate Data by User Specification" width="90" x="45" y="75">
            <list key="attribute_values">
              <parameter key="string" value="&quot;string1string2string3&quot;"/>
            </list>
            <list key="set_additional_roles"/>
          </operator>
          <operator activated="true" class="generate_data_user_specification" compatibility="5.3.008" expanded="true" height="60" name="Generate Data by User Specification (2)" width="90" x="45" y="165">
            <list key="attribute_values">
              <parameter key="string" value="&quot;string1string4string3&quot;"/>
            </list>
            <list key="set_additional_roles"/>
          </operator>
          <operator activated="true" class="generate_data_user_specification" compatibility="5.3.008" expanded="true" height="60" name="Generate Data by User Specification (3)" width="90" x="45" y="255">
            <list key="attribute_values">
              <parameter key="string" value="&quot;string2&quot;"/>
            </list>
            <list key="set_additional_roles"/>
          </operator>
          <operator activated="true" class="append" compatibility="5.3.008" expanded="true" height="112" name="Append" width="90" x="246" y="75"/>
          <operator activated="true" class="generate_attributes" compatibility="5.3.008" expanded="true" height="76" name="Generate Attributes" width="90" x="380" y="75">
            <list key="function_descriptions">
              <parameter key="match" value="matches(string,&quot;.*string2.*&quot;)"/>
            </list>
          </operator>
          <operator activated="true" class="filter_examples" compatibility="5.3.008" expanded="true" height="76" name="Filter Examples" width="90" x="514" y="75">
            <parameter key="condition_class" value="attribute_value_filter"/>
            <parameter key="parameter_string" value="match=true"/>
          </operator>
          <operator activated="true" class="select_attributes" compatibility="5.3.008" expanded="true" height="76" name="Select Attributes" width="90" x="648" y="75">
            <parameter key="attribute_filter_type" value="subset"/>
            <parameter key="attributes" value="|match"/>
            <parameter key="invert_selection" value="true"/>
          </operator>
          <connect from_op="Generate Data by User Specification" from_port="output" to_op="Append" to_port="example set 1"/>
          <connect from_op="Generate Data by User Specification (2)" from_port="output" to_op="Append" to_port="example set 2"/>
          <connect from_op="Generate Data by User Specification (3)" from_port="output" to_op="Append" to_port="example set 3"/>
          <connect from_op="Append" from_port="merged set" to_op="Generate Attributes" to_port="example set input"/>
          <connect from_op="Generate Attributes" from_port="example set output" to_op="Filter Examples" to_port="example set input"/>
          <connect from_op="Filter Examples" from_port="example set output" to_op="Select Attributes" to_port="example set input"/>
          <connect from_op="Select 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>
    Andrew
  • RWingerterRWingerter Member Posts: 38 Contributor II
    CharlieFirpo wrote:

    In SQL, I can use a query like this: SELECT * FROM <table name> WHERE <column name> LIKE '%<specific string>%'
    Once you have set up a database connection (Tools > Manage Database Connections) you can use the "Read Database" operator and its query property to write an SQL query.

    Roland

  • CharlieFirpoCharlieFirpo Member Posts: 48 Contributor II
    Retegniw wrote:

    Once you have set up a database connection (Tools > Manage Database Connections) you can use the "Read Database" operator and its query property to write an SQL query.

    Roland
    Thank you very much! It's very simple and works well! (I was lost at FilterExamples and SelectAttributes and didn't find the solution here...)
  • RWingerterRWingerter Member Posts: 38 Contributor II
    Glad to help.

    Roland
Sign In or Register to comment.