How to use Rule Engine

Hi All,
If I want to do the following action, what should I input in Rule Engine?

Column A
apple
orange
banana

Column A LIKE “a” => “A”
Column A LIKE “an” => “O”
Column A LIKE “ba” => “C”

However, if I write like above, all result is “A”.
What should I do?

Hi @HKuser

You have to change the order of your rules for this. Since a is also part of of an it will always satisfy the first condition. In general, put the conditions with the most number of characters in front. The single is more like a fallback.

For banana, you again have multiple rules that apply so it’s a matter of setting a priority depending on what your preference is, like moving ba before an in the Rule Engine.

2 Likes

Thanks for your reply! It is useful!

How about if I want to make a like,

Column A
apple
orange
banana

Column A LIKE “a” => “A”
Column A LIKE “an” => “O”
Column A LIKE “ba” => “C”

Result:
Column A Column B
Apple A
orange A
orange O
banana A
banana C

Hi @HKuser

Sure!

Note that you can achieve this in many different ways, some are more efficient that others depending on the complexity of your actual use case and the number of rows involved. Key point for me here is to stay way from loops.

So a way to approach it is via the cross joiner.

I input the words (fruits), set the rules (terms)and apply the cross joiner (default settings). This basically means that every single fruit gets associated with every rule initially. Note that I already used wildcards for later use in the Rule Engine.

Next, I’m checking if the word satisfies any of the rules on a row basis by using the Rule Engine (many alternatives available here, same principle) whereby;

$text$ LIKE $search_term$ => "TRUE" //checking if the text contains the search terms if so it's TRUE
TRUE => "FALSE"  // if not found, it's FALSE

This allows me then to filter out the TRUE values.

Note: I believe there is a small error in the output you mentioned because banana satisfies all rules, not only just “A” and “C”.

See WF:
How to use Rule Engine.knwf (23.7 KB)

Hope this helps!

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.