Patrick Bangert
Patrick Bangert

Reputation: 83

Data structure for user input of complex nested if-then rules

My application requires the processing of measurement data in part via logical rules that are unknown while coding and will be input manually by the user. An example of such a rule is

IF ( Column_3 < 4.5 ) AND ( ( Column_5 > 3.2 ) OR ( Column_7 <= 0 ) ) THEN Result = 2

where the number of elementary comparisons and the bracketing is, a priori, unknown.

This leads to a design question: What is the most efficient way to allow the user to enter this information in a GUI and how can I represent this information in my program in the best way in order to actually compute the whole IF clause? Actually, I would like to represent the rule in an SQL database and so I need a specific data structure.

Thank you all for your kind help!

Upvotes: 1

Views: 383

Answers (1)

gadir
gadir

Reputation: 11

Regarding GUI, I feel comfortable with entering the data in text-area box. Unless your common condition are more than 2-3 lines long it should be ok.

The data structure can be something similar to the below design:

Base_Conditions table

  • ID
  • Left_operand
  • Operator_code (> = <)
  • Right_operand

Logical_conditions table

  • ID
  • Left_condition_id
  • Left_condition_type ("1" for base condition or "2" for another logical condition)
  • Operator_code (and/or)
  • Right_condition_id
  • Right_condition_type

Rules table

  • ID
  • Condition_id
  • Result_action

To store the condition in a relational DB, the data structure would be something similar to this:

Base_Conditions

  • [1, Column_3, <, 4.5]
  • [2, Column_5, >, 3.2]
  • [3, Column_7, <=, 0]

Logical_conditions

  • [1, 2, 1, OR, 3, 1]
  • [2, 1, 1, AND, 1, 2]

Rules

  • [1, 2, "Result = 2"]

Upvotes: 1

Related Questions