This page (revision-59) was last changed on 13-Jun-2014 18:25 by Albrecht Striffler

This page was created on 26-Oct-2012 10:15 by Joachim Baumeister

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
59 13-Jun-2014 18:25 7 KB Albrecht Striffler to previous
58 13-Jun-2014 18:25 7 KB Albrecht Striffler to previous | to last
57 13-Jun-2014 18:24 7 KB Albrecht Striffler to previous | to last
56 13-Jun-2014 18:23 7 KB Albrecht Striffler to previous | to last
55 13-Jun-2014 18:22 6 KB Albrecht Striffler to previous | to last
54 13-Jun-2014 18:21 6 KB Albrecht Striffler to previous | to last
53 13-Jun-2014 18:20 6 KB Albrecht Striffler to previous | to last
52 13-Jun-2014 18:20 6 KB Albrecht Striffler to previous | to last
51 13-Jun-2014 18:17 6 KB Albrecht Striffler to previous | to last
50 13-Jun-2014 18:11 5 KB Albrecht Striffler to previous | to last
49 13-Jun-2014 18:11 5 KB Albrecht Striffler to previous | to last
48 13-Jun-2014 18:10 5 KB Albrecht Striffler to previous | to last
47 13-Jun-2014 17:56 4 KB Albrecht Striffler to previous | to last
46 13-Jun-2014 17:48 4 KB Albrecht Striffler to previous | to last
45 13-Jun-2014 17:48 4 KB Albrecht Striffler to previous | to last
44 13-Jun-2014 17:40 4 KB Albrecht Striffler to previous | to last
43 13-Jun-2014 17:39 4 KB Albrecht Striffler to previous | to last
42 13-Jun-2014 17:26 4 KB Albrecht Striffler to previous | to last
41 13-Jun-2014 17:24 4 KB Albrecht Striffler to previous | to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 1 added 6 lines
%%Todo
Improve this page... more examples, more complete (eval(...) an such)
@user Tim Baier-Loewenstein
%
At line 12 changed 11 lines
!!!Syntax
In this section we describe the way rules are defined in d3web KnowWE.
!! Basics
Rules are defined by the ''Rule'' tag in KnowWE. The basic syntax is as follows:
{{{
%%Rule
IF (rule condition)
!!!Syntax - Basics
Rules are defined by the ''Rule'' tag in KnowWE. The basic syntax is as follows (rc = rule condition):
{{{%%Rule
IF (rc)
At line 24 changed 2 lines
%
}}}
%}}}
At line 27 changed one line
!Conditions
Since the Leeloo release it is possible to define more than one action to be executed for a rule. Different rule actions are separated by a semicolon in the THEN clause.
{{{%%Rule
IF (rc)
THEN (action1; action2; action3)
%}}}
At line 29 changed 19 lines
A condition can look like ''"temperature > 38"'' or ''"weather = rain'"'. Such simple conditions can be combined to more complex ones, using the following syntax:
* __NOT__(rule condition) --- true, if rule condition does not apply
* (rule condition 1) __AND__ (rule condition 2) --- true, only if both condition 1 and condition 2 apply at the same time
* (rule condition 1) __OR__ (rule condition 2) --- true, if at least one of condition 1 and condition 2 does apply
For more information about conditions and other condition types, see [Doc Conditions].\\
!Actions
In a rule action we can set other questions or variables. Examples could be ''"Show warning = Yes"'' or ''"umbrella = Yes"''\\
It is also possible to set more complex values and values depending on other variables. For more information, go to [Extended Expressions: Conditions and actions | Doc Expressions], but be aware, that this extension is non-LGPL-licensed for commercial use.
!!Multiple Actions
It is possible to define more than one action to be executed for a rule. Just add more THEN clauses.
Furthermore it is possible to add an exception condition to the rule, like in the following example:
At line 49 changed 12 lines
IF (rule condition)
THEN (rule action 1)
THEN (rule action 2)
THEN (rule action 3)
}}}
!!EXCEPT Conditions
Furthermore, it is possible to add an exception condition to the rule, like in the following example:
{{{
IF (rule condition 1)
IF (rc)
At line 62 changed one line
EXCEPT (rule condition 2)
EXCEPT (rc2)
At line 65 changed one line
Of course it is also possible to define the ''EXCEPT(...)'' statement as ''AND NOT'' within the ''IF'' clause. The difference is, that ''EXCEPT(...)'' doesn't need to be evaluated, i.e. the rule will also fire even if the ''EXCEPT'' clause is unknown.
It is also possible to define the ''EXCEPT(...)'' statement as ''AND NOT'' wihtin the ''IF'' clause. But ''EXCEPT(...)'' doesn't need to be evaluated, i.e. the rule will also fire even if the ''EXCEPT'' clause is not fulfilled.
At line 67 changed one line
!!ELSE Actions
The following operators can be used to build more complex expressions from simple rule conditions:
* __NOT__( rc ) --- true, if rc does not apply
* (rc) __AND__ (rc2) --- true, only if both rc and rc2 apply at the same time
* (rc1) __OR__ (rc2) --- true, if at least one of rc and rc2 does apply
\\
At line 69 removed 52 lines
Using such rules, we often not only want something to happen if the condition is true (e.g. ''temperature <= 0''), but also when the condition is false. We can of course always do this, by writing a second rule, using the negated condition of the first rule (e.g. ''temperature > 0''). With d3web/KnowWE, we provide the possibility, to just use the keyword ELSE, similar to how it is known and done in software engineering.
{{{
IF temperature < 0
THEN icy roads = Yes
ELSE icy roads = No
}}}
!!UNKNOWN Actions
In d3web/KnowWE, every question can, besides their normal values, also have the value ''Unknown''. This means, that the value of the question is currently actually unknown or unknowable (which is different from not answering the question).\\
If a rule uses a question which currently has the value ''Unknown'' will result in the rule not being evaluated and therefor the action will not fire.
__Example:__ Lets assume, the temperature is currently unknown, because the sensor is broken. In this case, we really do not know whether the roads are icy or not. So to expand on the example above, we can do the following:
{{{
IF temperature < 0
THEN icy roads = Yes
ELSE icy roads = No
UNKNOWN icy roads = No
}}}This way, if the ''temperature'' is ''Unknown'', we also set the variable/question ''icy roads'' to ''Unknown'', without having the write rules for each of the actions.
Be aware that, if you just use THEN and ELSE __without__ an action for UNKNOWN, the action of ELSE will also fire if ''temperature'' is ''Unknown''.
!!ELSE and UNKNOWN in combination with EXCEPT
It is also possible to use an EXCEPT condition together with ELSE and UNKNOWN. If the EXCEPT condition is true, the ELSE action will fire. The UNKNOWN action only fires if the original IF condition is ''Unknown''. For clarification, check out the following truth tables:
\\
__Rule with THEN and ELSE action only__:
|| IF Condition || EXCEPT Condition || THEN Action || ELSE Action
| %%(color:green)true%% | %%(color:green)true%% |   | %%(color:green)fire%%
| %%(color:red)false%% | %%(color:green)true%% |   | %%(color:green)fire%%
| %%(color:grey)unknown%% | %%(color:green)true%% |   | %%(color:green)fire%%
| %%(color:green)true%% | %%(color:red)false%% | %%(color:green)fire%% |  
| %%(color:red)false%% | %%(color:red)false%% |   | %%(color:green)fire%%
| %%(color:grey)unknown%% | %%(color:red)false%% |   | %%(color:green)fire%%
| %%(color:green)true%% | %%(color:grey)unknown%% | %%(color:green)fire%% |  
| %%(color:red)false%% | %%(color:grey)unknown%% |   | %%(color:green)fire%%
| %%(color:grey)unknown%% | %%(color:grey)unknown%% |   | %%(color:green)fire%%
__Rule with THEN and ELSE and UNKNOWN action__:
|| IF Condition || EXCEPT Condition || THEN Action || ELSE Action || UNKNOWN Action
| %%(color:green)true%% | %%(color:green)true%% |   | %%(color:green)fire%% |  
| %%(color:red)false%% | %%(color:green)true%% |   | %%(color:green)fire%% |  
| %%(color:grey)unknown%% | %%(color:green)true%% |   | %%(color:green)fire%% |  
| %%(color:green)true%% | %%(color:red)false%% | %%(color:green)fire%% |   |  
| %%(color:red)false%% | %%(color:red)false%% |   | %%(color:green)fire%% |  
| %%(color:grey)unknown%% | %%(color:red)false%% |   |   | %%(color:green)fire%%
| %%(color:green)true%% | %%(color:grey)unknown%% | %%(color:green)fire%% |   |  
| %%(color:red)false%% | %%(color:grey)unknown%% |   | %%(color:green)fire%% |  
| %%(color:grey)unknown%% | %%(color:grey)unknown%% |   |   | %%(color:green)fire%%
At line 122 changed one line
''eval(...)'' expressions can also be used as rule condition if more than one question or complex formulas shall be used. To see all available expressions and functions, see [Doc Expressions] and [Doc Functions|Doc Expressions#Function Reference]
''eval(...)'' expressions can also be used as rule condition if more than one question or complex formulas shall be used:
At line 124 changed one line
IF eval(question A = question B)
IF eval(questionA = questionB)
At line 130 changed one line
IF eval(question A = 2 * x + b)
IF eval(questionA = 2*x+b)
At line 138 changed one line
THEN questionB = eval(max(question C, question D))
THEN eval(questionB = max(questionC, questionD))
At line 143 changed 2 lines
IF question A = UNKNOWN
THEN question B = 2
IF questionA = UNKNOWN
THEN questionB = 2
At line 147 removed one line
At line 161 removed one line
At line 166 removed 19 lines