How to use Rows in Java Snippet dynamically

Hi,

How can I use Rows in Java Snippet dynamicaly?

As example:

/* Please note that as of KNIME 2.0

  • you must use the “return” keyword
  • to specify the return value.
    */
    double result=0;
    String strTest="";
    for ( int i = 1; i <= $$ROWCOUNT$$; i ++ ) {

/* change Row dynamically=>How? */
strTest=“Row”+i;
result= $strTest$+$Row1$;

}

return result;

Regards,

Schlirgg

Hi Schlirgg,
The Java Snippet node operates row-wise. You only have access to the values in the current row (and some constants and variables), and you can only return a value for one column in the current row.
If you need to traverse the entire table, you could use one of the JPython Script nodes, or program your own node extension.
Regards,

  • Peter.

Hi Peter,

Thanks for your answer.

Would something like this work?

  1. Row1
    1
    2
    3
    => Transpose node =>
  2. Now as column
    1 2 3

Could i now use the rows dynamically? How do I return a value for one column in the current row?

Regards,

Schlirgg

Hi Schlirgg,
When using the Java Snippet node, you can iterate the columns by creating a collection of cells. Have a look to the Create Collection Column and Split Collection Column nodes. Within the Java Snippet node you can access this collection of cells, such as:

String[] strs = $AggregatedValues$;
String r = “”;
for (int i = 0; i < strs.length; i++) {
r += strs[i];
}
return r;

Note, the return value itself can again a collection (Java array), therefore the “Array Return” checkbox need to be selected. Hope this helps.
Best, Thomas

Hi Thomas,

Thanks for your answer.

This solutions works fine.

Regards,

Schlirgg

Hi Gabriel, i've tried your method but I have a error:

$AggravatedValues$ cannot ve resolved to a variable.

Any idea?

M.

Hi,

plz anybody  send me a workflow for FHSAR algorithm for hiding sensitive association rules.
 

Regards,

Krishna

Hi,

Can anybody send me a super market data related to open data.

 

Regards,

Krishna
 

HI,

I want sesnsitive knowledge from the open data how can i work with knime to get sisitive knowledge from the open data.

Workflow:

How it is done in knime?

Regards,

Krishna

Plz reply me anybody or contact via mail.

regards,

krishna

Hello krishna,

Please respect the topic of a forum thread.
You can always open your own thread with a fitting title and you will get an answer.

Anyways, to get some super market data you can get inspired by the Workflow 007003_AssoziationRules in the group "007_ModularDataGeneration" on the KNIME Example server.

Best,
Ferry

Dear Krishna,

could you please open new threads for your questions?

Thank you, Iris