Possibility to integrate flow variables

Dear Knime Community,

I am still quite new and have implemented my first own workflow after my training and would appreciate a little help.

The first is related to a string manipulation:

The string appears several times in both columns alongside other values.
And spaces within the string should be removed in both columns.
Example:

abc / efg → “abc/efg”

I have solved it this at the moment by two string manipulation nodes. One for every column and wonder if there is also the possibility to solve it with a flow variable - but I can’t get it to work. I was thinking about using the “String Manipulation Variable” node, but I’m still at a bit of a loss as to where to put it and how to configure it.

Table:
Column 1 | Column 2
String 1| String 1
String 2| String 1

Workflow String Manipulation

The second part:

We also have the following rule engines one after the other. They check whether the value in a previously considered evaluation is true or false. In the case of true, values are to be overwritten in various columns. Almost all columns are strings and behave as follows (one column per rule engine):
If TRUE => use value from column 2
Otherwise => use value from column 1

Is there a way to adjust this as well?

Many thanks and kind regards,
Anne

Hello @Eisfee,

and welcome to KNIME Community!

You should be able to use String Manipulation (Multi Column) node to replace multiple String Manipulation nodes with same expression. (Hope you have found and using removeChars() function for removing spaces.)

Regarding second part unfortunately there is no Rule Engine (Multi Column) node. However if all columns are string you can try with String Manipulation (Multi Column) node again and regexReplace() function. Might work. Alternatively you can use Column Expressions node to have it all in one node as you can write multiple expressions in it. Lastly approach I often use if Unpivot → apply Logic → Pivot. See here more about it:

Hope this helps!

Br,
Ivan

2 Likes

Hi @Eisfee ,

This is kind of off-topic from your original question, but… :wink:

Following from @ipazin 's suggestions, the String Manipulation node can in fact do everything that the Rule Engine can do (and much more), provided you know the “hidden” syntax.

Suppose you have the following table:
image

And you wanted to modify column1, column2 and column3 such that if the TestResult is True, they retain their current values, but if the test result is False, they should be set to the value of Default.

You could achieve this with 3 rule engine nodes as follows:

image

with each of the Rule Engines configured to handle one of the columns

e.g.

This would of course soon get tiresome, especially with more than 3 columns. Yes it would be nice to have some form of multi-column Rule Engine, but you can instead use the String Manipulation (Multi-Column) to replicate the above in a single node:

$TestResult$ == true ? $$CURRENTCOLUMN$$ 
: $Default$

This says “if testresult = True then use current column value, otherwise use default”

You can also provide a series of rules by “nesting”

$TestResult$ == true ? $$CURRENTCOLUMN$$ 
: $TestResult$ == false && $Default$.equals("AAAA") ? "1234"
  : $Default$

which would mean “if testresult = true then currentcolumn, otherwise if testresult is false and default is “AAA” then use “1234”, otherwise use the value of Default”
The ? means “then” and is equivalent of => in Rule Engine
The : means “else”

It is the equivalent of the following in Rule Engine:

$TestResult$ => $column1$
NOT $TestResult$ AND $Default$ = "AAAA" => "1234"
TRUE => $Default$

The “special” things you need to know in translating from Rule Engine to this is as follows:

  • numerics are compared using == and != representing “equals” and “not equals”

  • strings are compared using .equals("") rather than ==

  • NOT EQUALS for strings is performed using ! as follows:
    !($Default$.equals("AAAA") )

  • AND is performed by using &&

  • OR is performed by using ||


It’s not necessarily something you would want to do every day, and if you are still quite new to KNIME may be something for “another time”, but it’s worth knowing about and it can save a lot of effort when you need it :slight_smile:

Multi Column Rule Engine equivalent.knwf (13.5 KB)

1 Like

@Eisfee going back to your question of the possibility of using flow variables, I need to understand better exactly how you envisage their use. Can you upload a small sample workflow showing the kind of thing you have at the moment. It is possible to dynamically set the entire expression in String Manipulation and Rule Engine, and they could be used in a loop.

You would probably use a String Manipulation (variable) node to create the whole “expression” that you would then assign to the Expression parameter in the String Manipulation node

You do have to put a dummy but legal expression in the String Manipulation node even if you are going to overwrite it with a flow variable. e.g. you could just set it to
string(" ")

If you don’t do that, you get the error in red that is shown in my above screenshot.

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