The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

Regular expresion

jmphillipsjmphillips Member Posts: 18 Contributor II
I want to recognize some regular expresion, for example "my cat", and then obtain the next´s word until a point followed or a separate point. the object is to obtain definitions from a text. for example:

hammer is a tool that consists of a heavy piece of metal at the end of a handle. It is used, for example, to hit nails into a piece of wood or a wall, or to break things into pieces. He used a hammer and chisel to chip away at the wall.  

the idea si: set hammer as my regular expresion that i want to identify and then obtain as result "is a tool that consists of a heavy piece of metal at the end of a handle."

How can I do this????

Best Answer

Answers

  • sgenzersgenzer Administrator, Moderator, Employee-RapidMiner, RapidMiner Certified Analyst, Community Manager, Member, University Professor, PM Moderator Posts: 2,959 Community Manager
    hi @jmphillips perhaps this is what you are looking for?

    <?xml version="1.0" encoding="UTF-8"?><process version="9.2.001">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.2.001" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="UTF-8"/>
        <process expanded="true">
          <operator activated="true" class="utility:create_exampleset" compatibility="9.2.001" expanded="true" height="68" name="Create ExampleSet" width="90" x="45" y="34">
            <parameter key="generator_type" value="comma separated text"/>
            <parameter key="number_of_examples" value="100"/>
            <parameter key="use_stepsize" value="false"/>
            <list key="function_descriptions"/>
            <parameter key="add_id_attribute" value="false"/>
            <list key="numeric_series_configuration"/>
            <list key="date_series_configuration"/>
            <list key="date_series_configuration (interval)"/>
            <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/>
            <parameter key="time_zone" value="SYSTEM"/>
            <parameter key="input_csv_text" value="Text&#10;&quot;A hammer is a tool that consists of a heavy piece of metal at the end of a handle. It is used to hit nails into a piece of wood or a wall. He used a hammer and chisel to chip away at the wall.&quot;"/>
            <parameter key="column_separator" value=","/>
            <parameter key="parse_all_as_nominal" value="false"/>
            <parameter key="decimal_point_character" value="."/>
            <parameter key="trim_attribute_names" value="true"/>
          </operator>
          <operator activated="true" class="replace" compatibility="9.2.001" expanded="true" height="82" name="Replace" width="90" x="179" y="34">
            <parameter key="attribute_filter_type" value="all"/>
            <parameter key="attribute" value=""/>
            <parameter key="attributes" value=""/>
            <parameter key="use_except_expression" value="false"/>
            <parameter key="value_type" value="nominal"/>
            <parameter key="use_value_type_exception" value="false"/>
            <parameter key="except_value_type" value="file_path"/>
            <parameter key="block_type" value="single_value"/>
            <parameter key="use_block_type_exception" value="false"/>
            <parameter key="except_block_type" value="single_value"/>
            <parameter key="invert_selection" value="false"/>
            <parameter key="include_special_attributes" value="false"/>
            <parameter key="replace_what" value=".*?hammer(.*?)\..*"/>
            <parameter key="replace_by" value="$1"/>
          </operator>
          <connect from_op="Create ExampleSet" from_port="output" to_op="Replace" to_port="example set input"/>
          <connect from_op="Replace" 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>
    


  • kaymankayman Member Posts: 662 Unicorn
    If you want to extend the rage a bit to include also other separators as comma's and so, I'd use the following :

    hammer([\w ]+)
    So basically this means you have your word, followed by any word character (a to z, 0 to 9 and _) or space.
    This will end your result on any punctuation, but you can extend the list of 'good ones' at will
  • jmphillipsjmphillips Member Posts: 18 Contributor II
    edited March 2023
    Hello Kayman, long time ago......
    I have a question: how can I extend until to punctuation????, including colon (,)

    like:    " the big hammer is in the forrest, and you know it."

    and return to me: "
    the big hammer is in the forrest, and you know it." 
    not returning: "the big hammer is in the forrest"
  • BalazsBaranyBalazsBarany Administrator, Moderator, Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert Posts: 955 Unicorn
    Hi!

    In the [] context you can always list the characters you want to include. \w is a shortcut for word characters. If you want "word characters, space and comma", the regular expression would be: 
    hammer([\w ,]+)
    Regards,
    Balázs

Sign In or Register to comment.