Using Java Snippet in a loop

Hi all,

I am trying to combine loops and Java Snippets to perform an iterative task.

I have a Table (called Source) with a single Column (called DATA).
I also have another table (called Replacement_Text) with two columns (1st called FROM and 2nd TO)

I am interested in using a Java Snippet within a KNIME LOOP where the Java Snippet for each iteration in the loop it takes 1 row at a time from table “Replacement_Text” table and then replaces the text in the SOURCE table. Once it goes through 2 iterations (2 being the # of rows in the Replacement_Text table) the result to look like the LOOP Result below.

Table SOURCE
Row DATA
1 1A1A
2 2B1A
3 1111

Table Replacement_Text
Row FROM TO
1 2 4
2 A ΑA

LOOP RESULT
Row DATA
1 1AA1AA
2 4B1AA
3 1111

I know there are alternative KNIME nodes that simplyfy this, however I am interested in using Java Snippet and Loops because a number of the things I would like to perform are more complicated.

Can you help? Much appreciated

This workflow should get you started

I used a String Manipulation node to do the replacement, but you can replace it with a Java Snippet.

2 Likes