Change string variable depending on its content

Hi @pipetman , the difficulty I think that many people face with the syntax is that there isn’t a common syntax across all the “script” style nodes, so basically you have to learn each one. Some nodes have a java or javascript-style syntax, others (like Rule Engine) have a syntax all their own.

The free ebook “Beginner’s Luck” (updated for KNIME 5.2) does have some examples and explanation of some syntax in it:

But much of the detailed learning for KNIME comes from taking a look at the example workflows such as

and taking a look at courses,(both free self-paced, and instructor-led) at

One day I might actually complete one of those courses myself, and who knows maybe actually do an exam to see if I understand any of this stuff! :wink:

The Rule Engine syntax that you mention here is basically a statement, with each line representing a condition and a simple outcome. (I say “simple” because the outcome of Rule Engine cannot be anything “fancy”, like string conversions, or concatenations. The outcome is always a literal value, or a single column or variable value.)

It can be thought of as this:

IF ... THEN ...
ELSE IF  ...  THEN...
ELSE IF  ...  THEN...
ELSE IF  ...  THEN...

so

$${SPlateFormat}$$ ="96w" => "# PlateFormat\t 8\t 12"
$${SPlateFormat}$$ ="384w" => "# PlateFormat\t 16\t 24"
$${SPlateFormat}$$ ="1536w" => "# PlateFormat\t 32\t 48"
TRUE => $${SPlateFormat}$$

reads as:
IF $${SPlateFormat}$$ ="96w" THEN "# PlateFormat\t 8\t 12"

ELSE IF $${SPlateFormat}$$ ="384w" THEN"# PlateFormat\t 16\t 24"

ELSE IF $${SPlateFormat}$$ ="1536w" THEN "# PlateFormat\t 32\t 48"

ELSE IF TRUE THEN $${SPlateFormat}$$

What the rule engine actually does is evaluate the conditional statement that is to the left of each => in turn, and the first one that equates to TRUE is used to determine the outcome as being the value to the right of that =>

So, if none of the conditions prior to the last statement is TRUE, then the condition TRUE on the final line is inspected and of course this equates to TRUE and so it returns the value found in $${SPlateFormat}$$ unchanged.

Had that final TRUE line not been present, then if the Rule Engine got to the end of the set of rules with no line equating to TRUE it would have no value to return and so it would return “missing value”.

This can trip people up, but can also be a useful feature to make use of. Suppose you wanted to replace the value 0 in a column with “missing value” (also known as null)…

Here is an example doing exactly that:

1 Like