Skip to content

rssdev10/ruby4knime

Repository files navigation

ruby4knime

Join the chat at https://gitter.im/rssdev10/ruby4knime

Intro

Ruby scripting extension for KNIME

This is preliminary support of Ruby scripting language for Knime.

Now realized following node types:

  • Ruby Generator allows to generate any string or numeric data. Or process any external sources using Ruby.
  • Ruby Script allows to process input DataTable into output DataTable.
  • Ruby Script 2x2 allows to process 2 input DataTable into 2 output DataTable.
  • Ruby Snippet allows to process input DataTable into output DataTable by writing code only for one row processing.

It is possible to configure an Output table with any types of columns.

See Ruby wrapper

Ruby4KNIME code tab

Installation

Download binary

See changelog.

Install this archive as KNIME extension.

Sample workflow

Download sample workflow

This is simple workflow for ruby4knime testing only. It includes all realized node types.

Ruby test workflow

Now some details.

Node 1 contains the following code:

0.step(6 * Math::PI, 0.01) do |x|
  $out_data_0 << Cells.new.double(x).
                           double(Math.sin(x)).
                           double(Math.sin(x + Math::PI/3))
end

Node 2 contains the following code:

$outContainer.rowKey = 100000 # generate table keys from this number
0.step(6 * Math::PI, 0.01) do |x|
  $out_data_0 << Cells.new.double(x).
                           double(Math.cos(x)).
                           double(Math.cos(0.3 * x))
end

Node 3 contains the following code:

$in_data_0.each do |row|
  $out_data_0 << (row << Cells.new.double(row.y1.to_f-row.y2.to_f))

  # alternative
  # $outContainer << (row << Cells.new.double(row[1].to_f-row[2].to_f))
end

Node 4 contains the following code:

(0..1).each do |i|
  out = $output_datatable_arr[i]
  $input_datatable_arr[i].each do |row|
    out << row
  end
 end

Node 6 contains the following code:

Cells.new.double(row.y1.to_f).
          double(row.y2.to_f - row.y2_1.to_f)

# alternative
# Cells.new.double(row[1].to_f).
#           double(row[2].to_f - row[4].to_f)

Joiner (Node 5) generates following data:

joiner node 5

We can control results by line plots.

Fragment of Line Plot (Node 10)

line plot 10

Fragment of Line Plot (Node 11)

line plot 11

Fragment of Line Plot (Node 12)

line plot 12

Fragment of Line Plot (Node 13)

line plot 13

You can combine these Ruby nodes in any combination with other KNIME nodes.