❓ How to build rules with conditional expressions? #1240
-
For example, in Drools we can write rules: rule "Infer Adult"
when
$p : Person(age >= 18)
then
insertLogical(new IsAdult($p))
end
rule "Issue Adult Bus Pass"
when
$p : Person()
IsAdult($p)
then
insertLogical(new AdultBusPass($p));
end
rule "Do Adult Bus Pass"
when
$p : Person()
AdultBusPass($p)
then
doAdultBusPass($p));
end How to do this using ontological modeling in &? Or something similar: const IsAdult = insertLogical(($p : Person, $s: Syn) => {
if($p.age >= 18) {
return $s.a - $s.b >= 3;
}
return $s.a - $s.b >= 3 && $s.c + 4 < 200;
});
IsAdult.watch(({ $p }) => doAdultBusPass($p)); |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Let me start to disappoint you 😉. Ampersand is not a rule engine like Drules, Oracle Policy Automation, or the like. These tools are about knowledge inferencing, which can be very powerful on its own. These rules are known as Ampersand tackles another class of rules: Behavioural rules. The main difference between those rules is that inference rules cannot be violated. In your example, you have a rule that states that any person of age 18 or older is an adult person. According to this rule, a person of age 20 is an adult person. Like it or not. It cannot be violated. Now consider a behavioral rule. This is a rule that can be violated: The shipping address of a person who places an order must be known. If a person Ampersand is about behavioral rules. You can specify rules based on concepts and relations between concepts. Any rule that you specify is either an invariant or a signaling rule. If the above rule would be invariant, Joe just isn't allowed to place an order as long as his shipping address isn't known. However, if that same rule would be a signaling rule, Joe could place an order regardless if his shipping address was known. The system would signal the violation to a worker. That worker could be presented a list of violations, which can be considered as a worklist. Many more details about the background of Ampersand can be found here. Using Ampersand you can build a software system that takes care of some business process, as specified by behavioral rules. |
Beta Was this translation helpful? Give feedback.
-
@hanjoosten In tools such as drools, you can also react to false condition by issuing a message about a rule violation. However, I do not fully understand if in & the rules are enforced on insertion, this means that the rules cannot be violated, i.e. restrictions will never be violated because data violating the restrictions cannot be written. While in drools, we can write any data and check restrictions on it. Or I'm wrong? I am about to build a javascript rules engine and am looking at different solutions. I like drools and it has already been partially recreated in the js runtime. But I think it's done fundamentally wrong, because it considers reactions to rule changes as part of these rules, a much better solution would be to build it on top of an ontology, instead of procedurally setting constraints. In general, setting constraints instead of inferring rules seems more natural. I also noticed that your architecture is very similar to what is done in TGG research and Models@run.time It looks something like this: |
Beta Was this translation helpful? Give feedback.
-
What I said about TGG relates to the interface refactoring, here: https://ampersandtarski.gitbook.io/documentation/plans/refactor-the-front-end |
Beta Was this translation helpful? Give feedback.
Let me start to disappoint you 😉. Ampersand is not a rule engine like Drules, Oracle Policy Automation, or the like. These tools are about knowledge inferencing, which can be very powerful on its own. These rules are known as
inference rules
.Ampersand tackles another class of rules: Behavioural rules.
The main difference between those rules is that inference rules cannot be violated. In your example, you have a rule that states that any person of age 18 or older is an adult person. According to this rule, a person of age 20 is an adult person. Like it or not. It cannot be violated.
Now consider a behavioral rule. This is a rule that can be violated: The shipping address of a person who p…