Hub
  • Software
  • Blog
  • Forum
  • Events
  • Documentation
  • About KNIME
  • KNIME Hub
  • Nodes
  • Rule Engine
NodeNode / Predictor

Rule Engine

Manipulation Row Other Streamable
Drag & drop
Like
Copy short link

This node takes a list of user-defined rules and tries to match them to each row in the input table. If a rule matches, its outcome value is added into a new column. The first matching rule in order of definition determines the outcome.

Each rule is represented by a line. To add comments, start a line with // (comments can not be placed in the same line as a rule). Anything after // will not be interpreted as a rule. Rules consist of a condition part (antecedent), which must evaluate to true or false , and an outcome (consequent, after the => symbol) which is put into the new column if the rule matches.

The outcome of a rule may be any of the following: a string (between " or / ), a number, a boolean constant, a reference to another column or the value of a flow variable value. The type of the outcome column is the common super type of all possible outcomes (including the rules that can never match). If no rule matches, the outcome is a missing value.

Columns are given by their name surrounded by $, numbers are given in the usual decimal representation. Note that strings must not contain (double-)quotes. Flow variables are represented by $${ TypeCharacterAndFlowVarName }$$ . The TypeCharacter should be 'D' for double (real) values, 'I' for integer values and 'S' for strings. You can insert column names or flow variables by hand or by clicking in the respective lists in the dialog.

The logical expressions can be grouped with parentheses. The precedence rules for them are the following: NOT binds most, AND , XOR and finally OR the least. Comparison operators always take precedence over logical connectives. All operators (and their names) are case-sensitive.

The ROWID represents the row key string, the ROWINDEX is a the index of the row (first row has 0 value), while ROWCOUNT stands for the number of rows in the table.

Some example rules (each should be in one line):

// This is a comment
$Col0$ > 0 => "Positive"
When the values in Col0 are greater than 0, we assign Positive to the result column value (if no previous rule matched).
$Col0$ = "Active" AND $Col1$ <= 5 => "Outlier"
You can combine conditions.
$Col0$ LIKE "Market Street*" AND 
    ($Col1$ IN ("married", "divorced") 
        OR $Col2$ > 40) => "Strange"
$Col0$ MATCHES $${SFlowVar0}$$ OR $$ROWINDEX$$ < $${IFlowVar1}$$ =>
    $Col0$
With parentheses you can combine multiple conditions. The result in the second case comes from one of the columns.
$Col0$ > 5 => $${SCol1}$$
The result can also come from a flow variable.

You can use either Ctrl+Space to insert predefined parts, or select them from the upper controls.

The following comparisons result true (other values are neither less, nor greater or equal to missing and NaN values):

  • ? =,<=,>= ?
  • NaN =,<=,>= NaN

Node details

Input ports
  1. Type: Table
    Table
    Any datatable
Output ports
  1. Type: Table
    Classified values
    The input table with an additional column containing the outcome of the matching rule for each row.

Extension

The Rule Engine node is part of this extension:

  1. Go to item

Related workflows & nodes

  1. Go to item
    30052-if-statement
    kowisoft > Public > 30052-if-statement
  2. Go to item
    ラベルを付ける Rule Engine
    Japanese 日本語 Makkynm
    +4
    Rule Engineの紹介用Workflowです。 InputファイルはInputフォルダからダウンロードしてください。 ラベルを付けたいときはRule Engine This…
    makkynm > Public > Intermediate > I116_RuleEngine
  3. Go to item
    Comparison charts - Histogram and Bar chart
    Bar graph Bar plot Data visualization
    +7
    This workflow illustrates how to compare data by using histogram and bar chart visualizat…
    barbora > Courses > L4-DV Codeless Data Exploration and Visualization_06.2021 > L4-DV Codeless Data Exploration and Visualization - Demos > Demos empty > Session_02a_charts_demo 1_histobar_empty
  4. Go to item
    Rule engine with dates
    mwiegand > Public > Knime Forum Support > Rule engine with dates
  5. Go to item
    4
    lina3 > Public > Lab 3 > 4
  6. Go to item
    Example Rule Engine
    kathrin > Forum Questions > Example Rule Engine
  7. Go to item
    Rule Engine Example
    data_coach > KNIME Foundations > 5 - Calculations and Aggregating Data > 4 - Rule Engine > Rule Engine Example
  8. Go to item
    04 Data Transformation
    Rule engine String manipulation Math formula
    +1
    Exercise for transforming data. Perform data transformations with the Rule Engine, Math F…
    satteree > IT4015 Satteree Projects > Lab3 > Exercises with data provided > Exercises > 04 Data Transformation
  9. Go to item
    04 Data Transformation
    Rule engine String manipulation Math formula
    +1
    Exercise for transforming data. Perform data transformations with the Rule Engine, Math F…
    edwardscott > FinalProject > FinalProject > Solutions > DataManipulation01
  10. Go to item
    03 - rule engine
    kowisoft > Public > Continental XLS Formatter Tutorial > 03 - rule engine
  1. Go to item
  2. Go to item
  3. Go to item
  4. Go to item
  5. Go to item
  6. Go to item

KNIME
Open for Innovation

KNIME AG
Hardturmstrasse 66
8005 Zurich, Switzerland
  • Software
  • Getting started
  • Documentation
  • E-Learning course
  • Solutions
  • KNIME Hub
  • KNIME Forum
  • Blog
  • Events
  • Partner
  • Developers
  • KNIME Home
  • KNIME Open Source Story
  • Careers
  • Contact us
Download KNIME Analytics Platform Read more on KNIME Server
© 2022 KNIME AG. All rights reserved.
  • Trademarks
  • Imprint
  • Privacy
  • Terms & Conditions
  • Credits