Help with Rule Engine

I am new to KNIME and I was wondering if you can help with me writing a few rule engines.

Please see factor below:

If Column Text has “PAM_” at the beginning of the text then put “Auto” in the ‘Auto/Manual’ column (which is currently blank)
Else put “Manual” in the ‘Auto Manual’ column

But I also wanted to be able to refresh the the output file. Therefore, if I put the output file back in by joining it with the source data. If there is a value in the ‘Auto/Manual’ column already I want to leave it before adding the above rule engines. Not sure if I would use a missing node for this or not?

Please let me know the best way to write these if/then rules and missing rules.

You can use logic on multiple columns using Column Expression node. See example below.

1 Like

If I understand correctly, then there are 3 slightly different ways you could do this…

  1. Rule Engine on it’s own, with a rule as follows, to replae the ‘Auto/Manual’ column directly:

    NOT MISSING $Category$ => $Category$
    //Generate new 'Auto' categories
    $Text$ MATCHES "PAM_.*" => "Auto"
    //Otherwise 'Manual' category
    TRUE => "Manual"```
  2. You could generate a new category column with a simpler rule like this, and follow it with a Column Merger node, with the primary column as your existing auto/manual column, secondary column as the new auto/manual column, and the ‘replace both columns’ option selected:

    $Test Column$ MATCHES "PAM_.*" => "Auto"
    TRUE => "Manual"```
  3. Use a Row Splitter node to separate those rows with an existing auto/manual from those without, and use the same rule as above to replace the auto/manual column for those rows missing the categorisation, and then use a Concatenate to put it all back together.

The attached simple workflow shows the 3 methods (with a Foo/NOT categorisation!)

categorisation.knwf (13.7 KB)