Skip to content

Commit e94b877

Browse files
committed
Updated global variables. Part 2.
1 parent b739b06 commit e94b877

6 files changed

Lines changed: 56 additions & 48 deletions

File tree

RubyScript/src/org/knime/ext/jruby/RubyScriptNodeFactory.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
*
1111
* @author
1212
*/
13+
/**
14+
* @author rss
15+
*
16+
*/
1317
public class RubyScriptNodeFactory extends NodeFactory<RubyScriptNodeModel> {
1418

1519
private RubyScriptNodeModel m_model;
@@ -44,14 +48,14 @@ public final int getNrNodeViews() {
4448
return 1;
4549
}
4650

47-
/**
48-
* {@inheritDoc}
49-
*/
50-
@Override
51-
public final NodeView<RubyScriptNodeModel> createNodeView(final int viewIndex,
52-
final RubyScriptNodeModel nodeModel) {
53-
return new RubyScriptNodeView(nodeModel);
54-
}
51+
// /**
52+
// * {@inheritDoc}
53+
// */
54+
// @Override
55+
// public final NodeView<RubyScriptNodeModel> createNodeView(final int viewIndex,
56+
// final RubyScriptNodeModel nodeModel) {
57+
// return new RubyScriptNodeView(nodeModel);
58+
// }
5559

5660
/**
5761
* {@inheritDoc}

RubyScript/src/org/knime/ext/jruby/RubyScriptNodeFactory.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@
2222
</tab>
2323

2424
<tab name="Script">
25-
<option name="$inData0">The input DataTable containing all available input from input port 0.</option>
26-
<option name="$outContainer">Output container housing the outgoing DataTable for output port 0. This must be populated with rows by the script or else there will be no output from the node.</option>
25+
<option name="$in_data_0">The input DataTable containing all available input from input port 0.</option>
26+
<option name="$out_data_0">Output container housing the outgoing DataTable for output port 0. This must be populated with rows by the script or else there will be no output from the node.</option>
2727

2828
<option name="Example use to copy all input row of DataTable:"><pre>
29-
$inData0.each do |row|
30-
$outContainer &lt;&lt; row
29+
$in_data_0.each do |row|
30+
$out_data_0 &lt;&lt; row
3131
end
3232
</pre></option>
3333
<option name="Example use to extend input rows by new columns:"><pre>
34-
count = $inData0.length
35-
$inData0.each_with_index do |row, i|
36-
$outContainer &lt;&lt; (row &lt;&lt; Cells.new.string('Hi!').int(row.getCell(0).to_s.length))
34+
count = $in_data_0.length
35+
$in_data_0.each_with_index do |row, i|
36+
$out_data_0 &lt;&lt; (row &lt;&lt; Cells.new.string('Hi!').int(row.getCell(0).to_s.length))
3737
setProgress "#{i*100/count}%" if i%100 != 0
3838
end
3939
</pre></option>
4040

4141
<option name="Example use to create new DataTable from custom data:"><pre>
42-
$inData0.each do |row|
43-
$outContainer &lt;&lt; Cells.new.string(row[0].to_s.length.to_s)
42+
$in_data_0.each do |row|
43+
$out_data_0 &lt;&lt; Cells.new.string(row[0].to_s.length.to_s)
4444
end
4545
</pre></option>
4646
</tab>

RubyScript/src/org/knime/ext/jruby/RubyScriptNodeFactory01.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
</tab>
2424

2525
<tab name="Script">
26-
<option name="$outContainer">Output container housing the outgoing DataTable for output port 0. This must be populated with rows by the script or else there will be no output from the node.</option>
26+
<option name="$out_data_0">Output container housing the outgoing DataTable for output port 0. This must be populated with rows by the script or else there will be no output from the node.</option>
2727

2828
<option name="Example use create DataTable with two columns:"><pre>
2929
count = 10000
3030
count.times do |i|
31-
$outContainer &lt;&lt; Cells.new.string('Hi!').int(rand i))
31+
$out_data_0 &lt;&lt; Cells.new.string('Hi!').int(rand i))
3232
setProgress "#{i*100/count}%" if i%100 != 0
3333
end
3434
</pre></option>

RubyScript/src/org/knime/ext/jruby/RubyScriptNodeFactory22.xml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,35 @@
2222
</tab>
2323

2424
<tab name="Script">
25-
<option name="$inData0">The input DataTable containing all available input from input port 0.</option>
26-
<option name="$inData1">The input DataTable containing all available input from input port 1.</option>
27-
<option name="$outContainer">Output container housing the outgoing DataTable for output port 0. This must be populated with rows by the script or else there will be no output from the node.</option>
28-
<option name="$outContainer0">Output container housing the outgoing DataTable for output port 0. The same as $outContainer.</option>
29-
<option name="$outContainer1">Output container housing the outgoing DataTable for output port 1.</option>
25+
<option name="$input_datatable_arr">Array of input data tables.</option>
26+
<option name="$num_inputs">Number of input data tables.</option>
27+
<option name="$in_data_0">The input DataTable containing all available input from input port 0.</option>
28+
<option name="$in_data_1">The input DataTable containing all available input from input port 1.</option>
29+
<option name="$output_datatable_arr">Array of output containers.</option>
30+
<option name="$num_outputs">Number of outputs.</option>
31+
<option name="$out_data_0">Output container housing the outgoing DataTable for output port 0. The same as $outContainer.</option>
32+
<option name="$out_data_1">Output container housing the outgoing DataTable for output port 1.</option>
3033

3134
<option name="Example use to copy all input row of DataTable:"><pre>
32-
$inData0.each do |row|
33-
$outContainer &lt;&lt; row
35+
(0..1).each do |i|
36+
out = $output_datatable_arr[i]
37+
$input_datatable_arr[i].each do |row|
38+
out &lt;&lt; row
3439
end
40+
end
41+
3542
</pre></option>
3643
<option name="Example use to extend input rows by new columns:"><pre>
37-
count = $inData0.length
38-
$inData0.each_with_index do |row, i|
39-
$outContainer &lt;&lt; (row &lt;&lt; Cells.new.string('Hi!').int(row.getCell(0).to_s.length))
44+
count = $in_data_0.length
45+
$in_data_0.each_with_index do |row, i|
46+
$out_data_0 &lt;&lt; (row &lt;&lt; Cells.new.string('Hi!').int(row.getCell(0).to_s.length))
4047
setProgress "#{i*100/count}%" if i%100 != 0
4148
end
4249
</pre></option>
4350

4451
<option name="Example use to create new DataTable from custom data:"><pre>
45-
$inData0.each do |row|
46-
$outContainer0 &lt;&lt; Cells.new.string(row[0].to_s.length.to_s)
52+
$in_data_0.each do |row|
53+
$out_data_0 &lt;&lt; Cells.new.string(row[0].to_s.length.to_s)
4754
end
4855
</pre></option>
4956
</tab>

RubyScript/src/org/knime/ext/jruby/RubyScriptNodeModel.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,25 @@ protected RubyScriptNodeModel(int inNumInputs, int inNumOutputs, boolean snippet
161161
buffer.append("# Example starter script. "
162162
+ "Add values for new two columns with String and Int types:\n"
163163
+ "#\n"
164-
+ "# count = $inData0.length\n"
165-
+ "# $inData0.each_with_index do |row, i|\n"
166-
+ "# $outContainer << "
164+
+ "# count = $in_data_0.length\n"
165+
+ "# $in_data_0.each_with_index do |row, i|\n"
166+
+ "# $out_data_0 << "
167167
+ "row << (Cells.new.string('Hi!').int(row.getCell(0).to_s.length))\n"
168168
+ "# setProgress \"#{i*100/count}%\" if i%100 != 0\n"
169169
+ "# end\n" + "#\n");
170170
buffer.append("# Default script:\n");
171171
buffer.append("#\n\n");
172172

173-
buffer.append("$inData0.each do |row|\n");
174-
buffer.append(" $outContainer << row\n");
173+
buffer.append("$in_data_0.each do |row|\n");
174+
buffer.append(" $out_data_0 << row\n");
175175
buffer.append("end");
176176
} else {
177177
buffer.append("# Example starter script. " +
178178
"Add values for new two columns with String and Int types:\n");
179179
buffer.append("#\n");
180180
buffer.append("# count = 100000\n");
181181
buffer.append("# count.times do |i|\n");
182-
buffer.append("# $outContainer << Cells.new.string('Hi!').int(rand i))\n");
182+
buffer.append("# $out_data_0 << Cells.new.string('Hi!').int(rand i))\n");
183183
buffer.append("# setProgress \"#{i*100/count}%\" if i%100 != 0\n");
184184
buffer.append("# end\n");
185185
buffer.append("#\n");
@@ -206,16 +206,11 @@ protected final BufferedDataTable[] execute(final BufferedDataTable[] inData,
206206
Exception {
207207

208208
int i;
209-
BufferedDataTable[] in = (numInputs > 0 ? new BufferedDataTable[numInputs]
210-
: null);
211-
212-
for (i = 0; i < numInputs; i++) {
213-
in[i] = inData[i];
214-
}
215209

216210
// construct the output data table specs and the output containers
217-
DataTableSpec[] outSpecs = configure(in != null ? new DataTableSpec[] { in[0]
218-
.getDataTableSpec() } : null);
211+
DataTableSpec[] outSpecs = configure(numInputs > 0 ?
212+
new DataTableSpec[] { inData[0].getDataTableSpec() } :
213+
null);
219214

220215
DataContainer[] outContainer = new DataContainer[numOutputs];
221216
for (i = 0; i < numOutputs; i++) {
@@ -296,11 +291,14 @@ protected final BufferedDataTable[] execute(final BufferedDataTable[] inData,
296291
container.put("$input_datatable_arr", inData);
297292

298293
for (i = 0; i < numInputs; i++) {
299-
container.put(String.format("$inData%d", i), in[i]);
294+
container.put(String.format("$inData%d", i), inData[i]);
295+
container.put(String.format("$in_data_%d", i), inData[i]);
300296
}
301297

298+
container.put("$output_datatable_arr", outContainer);
302299
for (i = 0; i < numOutputs; i++) {
303300
container.put(String.format("$outContainer%d", i), outContainer[i]);
301+
container.put(String.format("$out_data_%d", i), outContainer[i]);
304302
}
305303
container.put("$outContainer", outContainer[0]);
306304

RubyScript/src/org/knime/ext/jruby/RubySnippetNodeFactory.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
</tab>
2323

2424
<tab name="Script">
25-
<option name="$inData0">The input DataTable containing all available input from input port 0.</option>
26-
<option name="$outContainer">Output container housing the outgoing DataTable for output port 0. This must be populated with rows by the script or else there will be no output from the node.</option>
25+
<option name="$out_data_0">Output container housing the outgoing DataTable for output port 0. This must be populated with rows by the script or else there will be no output from the node.</option>
2726

2827
<option name="row">Current row of input DataTable.</option>
2928

0 commit comments

Comments
 (0)