Confused with code in rule engine

Hello!
I got confused in the code for combining product categories in the rule engine node. Could you help me anybody?
I try to realise the follow scheme:
If product category = Apparel, then Union_category = Apparel
If product category = Office, then Union_category = Office
If product category = Drinkware, then Union_category =Drinkware
If product category = Lifestyle, then Union_category= Lifestyle
If product category = Bags, then Union_category= Bags
If product category = Headgearl, then Union_category = Apparel
If product category = Notebooks & Journals, then Union_category = Office
Of product category = Waze, then Union_category = Waze
If product category = Bottles, then Union_category =Drinkware
If product category = Acсessories, then Union_category =Acсessories
If product category = Fun, then Union_category =Acсessories
If product category = Gift cards, then Union_category =Gift cards
If product category = Housewares, then Union_category= Lifestyle
If product category = Google, then Union_category =Drinkware
If product category = Backpacks, then Union_category= Bags
Product_category current, Đ° Union_category new

Hello @Vira_Maykova
The operator = works for comparing numeric types. If comparing strings you can use the operator LIKE

Settings:
Append Column: Union_category

$product category$ LIKE "Apparel" => "Apparel"
...

BR

3 Likes

Hi,

The = operator also works with string types, however, it will then test for exact matches. LIKE allows the use of wildcards and therefore yields fuzzy matches. In terms of performance, it is recommended to go for exact matches rather than fuzzy matches but if your table is not too large (e.g. less than a few hundreds of thousands of lines), this little detail won’t matter.

Another point to consider with Rule Engine is that the order of the rules is important. Anything that matches a preceding rule is out of the selection for the next rule and can’t be changed anymore. If your rules are formulated in such a manner that they are mutually exclusive, the order won’t matter.

Finally, if you want to generate an ELSE rule, the following rule formulation will work as a final statement in your sequence of rules:

TRUE => "Anything else"

Kind regards,
Geo

4 Likes

Thank you I done correct!

1 Like

how do you think, why this scheme don’t work with row “Accessories” I have missing values after all.


Hello @Vira_Maykova
I cannot see the whole picture from captures, but there could be few reasons behind.

In example: your code runs for exact match for the quoted text. If there are leading or trailing white spaces or non-printable unicode… this expression won´t find an exact match; then we start to talk about wildcard matching… you can use LIKE "*Accessories*" aiming to get the match.

However you will have to start caring about the rule order, if this word is included in other logical rules:

If you can share a sample of your data, we would take a look into it.

BR

1 Like

Sure, you can see this data set on this link knime_correct1.csv - Google Drive.

Hello @Vira_Maykova
I’ve tested the data and I cannot reproduce the error (missed items). Original data summary:

The following expression works fine for me:
Replace Column: Union_category

// 
$Product_Category$ LIKE "Accessories" => "Accessories"
TRUE => "Other"

BR

3 Likes

Thank you very much, I’ve tried diff ways to solve the problem, and in the end I replace missing values to avrg means.

1 Like