This section describes how to implement the Negation as Failure idiom. In your business logic, you often need to identify the actions to take when certain conditions do not hold. It is natural to write a rule like the following example:
If it is not raining, then walk to work.
Also, negation is often used to express an exception to a condition:
If a visitor buys a product on your Web site and the purchased product is not a coffee maker, then send a promotional e-mail message about the coffee maker.
In the Business Rules Framework, it is relatively easy to support exceptions by using the classical negation operator NOT. Describing the actions to take when certain conditions do not hold is somewhat more complicated, although it can also be expressed by using rule priorities and the classical NOT operator.
Start by writing a single rule that expresses the condition that does not hold and the actions to take when the condition is not true. Suppose that you have the following rules.
Rule 1—Priority 0
IF NOT (SendFormElectronically(Person))
THEN SendFormByMail(Person)
Rule 2—Priority 5
IF Person.HasFaxMachine
THEN SendFormElectronically(Person) = true
Rule 3—Priority 5
IF Person.HasEmailAccount
THEN SendFormElectronically(Person) = true
The first rule captures or expresses the idea without describing what it means to be able to send the form electronically. This is important because it isolates this rule from the mechanisms used to determine if a form can be sent electronically, which may change over time. After the first rule is in place you can add other, higher priority rules that describe the current meaning of SendFormElectronically.
Note Actions in rules with higher priorities are executed first.
Note that the rule engine has no way to reason about entities that are not in working memory. For example, there is no way to express a statement like this: "If an instance of a particular fact is not in the knowledge base, then perform a certain action." However, the Exists predicate can be used against XML documents to check the absence of document content. All facts referenced in rule conditions and actions need to be asserted into working memory to instantiate the rule. Therefore, there is no way to define and execute the following rules.
Rule 1—Priority 2:
IF ItemA.Id == ItemB.Id AND IsPresent(ItemD)
THEN ItemC.IsValid = true
ItemD.Action
Rule 2—Priority 1:
IF ItemA.Id == ItemB.Id AND ItemC.IsValid = False
THEN ItemC.Action
To download updated BizTalk Server 2004 Help from www.microsoft.com, go to
http://go.microsoft.com/fwlink/?linkid=20616.
Copyright © 2004 Microsoft Corporation.
All rights reserved.