'How to build expressions' guide needed

Hello KNIMErs,

The following expression prepared by @HansS
image
inspired me to search for some guidelines and best practices on how to biuld efficient expressions in KNIME. Expressions that could be used for example in ‘Rule Engine’ or ‘String Manipulation’ nodes.
So far, I have found nothing really comprehensive starting with very basic things like operators or logic in building expressions up to more advanced topics (like nested functions).
@AlexanderFillbrunn @ScottF @DanielBog would you suggest any guide for this?

@HansS Why the following expression
$Strings$ = “3/4” => $Strings$ = “MEDIUM - 3/4”
is incorrect?

Happy KNIMEing,
Kaz

1 Like

Hello @Kazimierz ,

this is incorrect:

because you don’t have to specify the column “String” inside the expression (bold bart above), but here:

You can either create a new column (append) or replace an existing one.

For the first part, maybe a general Javascript course could help (that’s what I did, I use column expressions a lot).

Have a nice day,
Raffaello
LinkedIn

5 Likes

Hello @lelloba

Thank you for mentioning general Javascript course.

As far as the expression is concerned, I’ve got your explanation. But I still don’t understand why there are two lines in the original expression while the line
$Strings$ = “3/4” => “MEDIUM - 3/4”
seems to generate expected outcome.

Best regards,
Kaz

@Kazimierz you mean this line?

TRUE => $String$

Remember that a rule engine evaluates one rule at a time, from the top one to the last one; it means that it works like this:

If this is true => Then do this
Else if this is true =>Then do this other thing
Else if this is true =>Then do this thing
...

Going back to your example, what happens if $String$ = “1/2”? Your first condition is not met, so the rule engine evaluates the second rule, which is always true, and will give as a result the current value of $String$ in that cell.

Raffaello

5 Likes

Hi @Kazimierz

If you read the hints in the rule engine you will see that this line is explained and is used to give the default value:

If you are using a rule that only affects/fixes some rows in the table, then the remaining rows need to have a default value otherwise they would be missing in the output table.

Hope that explains it :slight_smile:
Heather

6 Likes

@lelloba
Thank you very much for providing some more explanations.
BR,
Kaz

1 Like

Hi @HeatherPikairos
Thank you for pointing out the basics.
BR,
Kaz

1 Like

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