## Tutorial: Rule conditions

After having added elements to a rule, the next step is to define conditions. Conditions determine when a rule is triggered for execution. Conditions come in three forms:

• Association: when an Entity instance is associated with another Entity instance.
• Attribution: when an Entity instance has a certain type of Attribute or Descriptor attributed to it.
• Equation: when the comparison of two values and/or operations evaluates to true.

#### Association condition

Association conditions follow the same structure as statements: Subject (noun) relationship (verb) and object (noun). The only difference is that the sentence representing an association condition is written in singular and contains entity instances instead of entity types.

Attribution conditions also follow the same structure as statements: Subject (noun) relationship (verb) and object (noun). Such conditions contain entity instances but only specify the type of attribute or descriptor that is attributed to it.

#### Equation condition

Equation conditions always follow the same structure:

• Left hand side: the first value added to the equation.
• Equation sign: indicating the type of equation to be performed.
• Right hand side: the second value added to the equation.

The values that act as inputs (operands) of equations can be:

• Constant values: added as elements to a rule.
• Attribute values: belonging to entities or descriptors that are added as elements to a rule.
• Calculated/manipulated values: that are the outcomes of operations added to a rule.

The following equation signs can be used: is equal to, is not equal to, is greater than, is greater than or equal to, is less than, and is less or equal to.

### Example app: Grocery store

In our example app we want to write two different rules:

• Rule 1: Calculate shopping cart total price: when a new product is added to the shopping cart, then the price of the product must be added to the total price of the shopping cart.
• Rule 2: Calculate volume discount: when a customer checks out a shopping cart and the total price of the shopping cart exceeds 100 Euro, then the total amount should be reduced with 10%.

#### Rule 1: Calculate shopping cart total price

In order to implement rule 1, we need the following association condition to trigger the execution of this rule:

• When Shopping cart1 contains Product1

#### Rule 2: Calculate volume discount

For the realization of rule 2, we need the following association condition:

• When Customer1 checks out Shopping cart1

And rule 2 should be triggered by the following equation condition:

• And the Amount Shopping cart1 is totalled to is greater than or equal to 100