|
1 | 1 | = Ruby4Knime |
2 | 2 |
|
3 | | -Ruby4Knime is a realization of special node types for http://knime.org that allow to use Ruby scripts for interactive data analytic. |
| 3 | +Ruby4Knime is a realization of special node types for |
| 4 | +http://knime.org that allow to use Ruby scripts for |
| 5 | +interactive data analytic. |
| 6 | + |
4 | 7 | The main aims of this project are: |
5 | 8 | * provide possibility to use Ruby language for interactive data analysis; |
6 | 9 | * make the analysis more effective using clear and laconic Ruby style. |
7 | 10 |
|
8 | | -knime.rb is the simple mediator that allows to use KNIME`s classes written in Java in the Ruby programming style and also use all Java classes without any changes. |
| 11 | +knime.rb is the simple mediator that allows to use KNIME`s classes |
| 12 | +written in Java in the Ruby programming style and also use all |
| 13 | +Java classes without any changes. |
9 | 14 |
|
10 | 15 | = Simple examples |
11 | | -These samples illustrate how to generate output data from input data of the node. |
| 16 | +These samples illustrate how to generate output data from input |
| 17 | +data of the node. |
12 | 18 |
|
13 | 19 | == Copy existing rows |
14 | 20 |
|
15 | | - $inData0.each do |row| |
16 | | - $outContainer << row |
| 21 | + $in_data_0.each do |row| |
| 22 | + $out_data_0 << row |
17 | 23 | end |
18 | 24 |
|
19 | 25 | == Add new two columns with String and Int types |
20 | 26 | This example also illustrates the progress state updating. |
21 | 27 |
|
22 | | - count = $inData0.length |
23 | | - $inData0.each_with_index do |row, i| |
24 | | - $outContainer << (row << Cells.new.string('Hi!').int(row.getCell(0).to_s.length)) |
| 28 | + table = $input_datatable_arr[0] |
| 29 | + count = table.length |
| 30 | + table.each_with_index do |row, i| |
| 31 | + $out_data_0 << (row << Cells.new.string('Hi!'). |
| 32 | + int(row[0].to_s.length)) |
| 33 | + |
25 | 34 | setProgress "#{i*100/count}%" if i%100 != 0 |
26 | 35 | end |
27 | 36 |
|
28 | 37 | == Create new rows |
29 | | -In this example new rows creates with new uniq rowkeys. Therefore it is possible to create output table with any number of rows. |
30 | | - $inData0.each do |row| |
31 | | - $outContainer << Cells.new.string(row.getCell(0).to_s.length.to_s) |
| 38 | +In this example new rows creates with new uniq rowkeys. |
| 39 | +Therefore it is possible to create output table with any number of rows. |
| 40 | + $in_data_0.each do |row| |
| 41 | + $out_data_0 << Cells.new.string( row.getCell(0).to_s.length.to_s ) |
32 | 42 | end |
33 | 43 |
|
34 | | -In this example cell 0 copies without changes and adds difference between cells with indexes 1 and 2. Index in Ruby style. |
35 | | - $inData0.each do |row| |
36 | | - $outContainer << Cells.new.int(row[0].to_i).double(row[1].to_f - row[2].to_f) |
| 44 | +In this example cell 0 copies without changes and adds difference between |
| 45 | +cells with indexes 1 and 2. Index in Ruby style. |
| 46 | + |
| 47 | + $in_data_0.each do |row| |
| 48 | + $out_data_0 << Cells.new.int(row[0].to_i). |
| 49 | + double(row[1].to_f - row[2].to_f) |
37 | 50 | end |
38 | 51 |
|
39 | 52 |
|
40 | 53 | == Ruby Snippet examples |
41 | | -Ruby snippet realizes as the body of a lambda-function in the following template: |
| 54 | +Ruby snippet realizes as the body of a lambda-function |
| 55 | +in the following template: |
| 56 | + |
42 | 57 | func = ->(row) do |
43 | 58 | <<SNIPPET CODE>> |
44 | 59 | end |
45 | | - snippetRunner &func |
| 60 | + snippet_runner &func |
46 | 61 |
|
47 | 62 | === Simple snippet examples |
48 | 63 | Copy all rows without changes. Code may contains only row-variable. |
@@ -70,25 +85,26 @@ BlobSupportDataRow class. Following code fragments are available: |
70 | 85 |
|
71 | 86 | and |
72 | 87 |
|
73 | | - $inData0.each do |row| |
74 | | - $outContainer << Cells.new.string(row.x.to_s) |
| 88 | + $in_data_0.each do |row| |
| 89 | + $out_data_0 << Cells.new.string(row.x.to_s) |
75 | 90 | end |
76 | 91 |
|
77 | 92 | == Other experiments |
78 | 93 | Samples that add new cells in functional style. |
79 | | - count = $inData0.length |
80 | | - $inData0.each_with_index do |row,i| |
81 | | - $outContainer << row.string('Hi!').int(row.getCell(0).to_s.length).append |
| 94 | + count = $in_data_0.length |
| 95 | + $in_data_0.each_with_index do |row,i| |
| 96 | + $out_data_0 << row.string('Hi!').int(row.getCell(0).to_s.length).append |
82 | 97 | setProgress "#{i*100/count}%" if i%100 != 0 |
83 | 98 | end |
84 | | - |
85 | | - $inData0.each do |row| |
86 | | - $outContainer << $outContainer.createRowKey.stringCell(row.getCell(0).to_s.length.to_s).new_row |
| 99 | +- |
| 100 | + $in_data_0.each do |row| |
| 101 | + $out_data_0 << $out_data_0.createRowKey. |
| 102 | + stringCell(row.getCell(0).to_s.length.to_s).new_row |
87 | 103 | end |
88 | 104 |
|
89 | 105 | = Other notes |
90 | 106 |
|
91 | 107 | Now it is possible to use any types of KNIME in the DataOutput table. |
92 | 108 | Simply input a full qualified Java class name in the configuration dialog of |
93 | | -the Ruby node. E.g. org.knime.core.data.def.ComplexNumberCell or |
94 | | -org.knime.ext.textprocessing.data.DocumentCell. |
| 109 | +the Ruby node. E.g. org.knime.core.data.def.ComplexNumberCell or |
| 110 | +org.knime.ext.textprocessing.data.DocumentCell. |
0 commit comments