Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
3.3. Advanced Concepts and Theory
3.3.1. Logical Assertions Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
After a standard object insertion, you have to retract facts explicitly. With logical assertions, the fact that was asserted will be automatically retracted when the conditions that asserted it in the first place are no longer true. It will be retracted only if there isn't any single condition that supports the logical assertion.
3.3.2. Stated Insertions Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
Normal insertions are said to be stated, as in "stating a fact". Using a
HashMap
and a counter, you can track how many times a particular equality is stated. This means you can count how many different instances are equal.
3.3.3. Justified Insertions Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
When an object is logically inserted, it is said to be justified. It is considered to be justified by the firing rule. For each logical insertion there can only be one equal object, and each subsequent equal logical insertion increases the justification counter for this logical assertion. A justification is removed when the creating rule's LHS becomes untrue, and the counter is decreased accordingly. As soon as there are no more justifications, the logical object is automatically retracted.
3.3.4. The WM_BEHAVIOR_PRESERVE Setting Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
If you try to logically insert an object when there is an equal stated object, this will fail and return null. If you state an object that has an existing equal object that is justified, you will override the Fact. How this override works depends on the configuration setting
WM_BEHAVIOR_PRESERVE
. When the property is set to discard
, you can use the existing handle and replace the existing instance with the new Object, which is the default behavior. Otherwise you should override it to stated but create an new FactHandle
.
3.3.5. Stated Insertion Flowchart Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
3.3.6. Logical Insertion Flowchart Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
3.3.7. The Truth Maintenance System Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
The JBoss Rules Truth Maintenance System (TMS) is a method of representing beliefs and their related dependencies/justifications in a knowledge base.
Important
For Truth Maintenance (and logical assertions) to work, the Fact objects must override equals and hashCode methods correctly. As the truth maintenance system needs to know when two different physical objects are equal in value, both equals and hashCode must be overridden correctly, as per the Java standard.
Two objects are equal only if their equals methods return true for each other and if their hashCode methods return the same values. You must override both equals and hashCode.
3.3.8. The insertLogical Fact Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
The
insertLogical
fact is part of the JBoss Rules TMS. It "inserts logic" so that rules behave and are modified according to the situation. For example, the insertLogical
fact can be added to a set of rules so that when a rule becomes false, the fact is automatically retracted.
3.3.9. Using Inference and TMS Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
Procedure 3.7. Task
- In this example we will use a bus pass issuing system. See the code snippet below:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Insert the
insertLogical
property to provide inference:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Re-enter the code to issue the passes. These two configurations can also be logically inserted, as the TMS supports chaining of logical insertions for a cascading set of retracts:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Now when the person changes from being 15 to 16, both theIsChild
fact and the person'sChildBusPass
fact are automatically retracted. - Optionally, insert the
not
conditional element to handle notifications. (In this example, a request for the returning of the pass.) When the TMS automatically retracts theChildBusPass
object, this rule triggers and sends a request to the person:Copy to Clipboard Copied! Toggle word wrap Toggle overflow