|
ReteEngine 1.0
A rules engine and builder
|
Represents a join node in a RETE network that combines partial matches from the left input with facts from the right input based on a specified condition. More...
Public Member Functions | |
| JoinNode (IReteNode? left, AlphaMemory? right, string name, Func< Token, object, bool > cond) | |
| A JoinNode combines tokens from the left input with facts from the right input based on a specified condition. When a new token arrives from the left input, it is evaluated against all facts in the right input memory using the provided condition function. If the condition is satisfied, a new token is created that combines the left token and the right fact, and this new token is propagated to all successor nodes. The JoinNode also supports retraction and refresh operations to maintain consistency as facts change. The constructor sets up the necessary connections to the left and right inputs and registers this node as a successor to those inputs as needed. | |
| void | AddSuccessor (IReteNode node) |
| Adds the specified node as a successor to this node in the Rete network. | |
| void | Assert (object fact) |
| The Assert method is responsible for processing new facts or tokens that arrive at this JoinNode. When a new fact is asserted, the method evaluates the join condition against all existing tokens from the left input (if the fact is from the right input) or against all existing facts from the right input (if the fact is from the left input). If the condition is satisfied for any combination of token and fact, a new token is created that combines the left token and the right fact, and this new token is propagated to all successor nodes. This method ensures that the JoinNode correctly evaluates the join condition and maintains the flow of tokens through the Rete network as new facts are introduced. It also handles the case where the left input is a BetaMemory or a CompositeBetaMemory, allowing for proper integration with the rest of the network. | |
| void | Retract (object fact) |
| The Retract method for left activations is responsible for handling the retraction of tokens that arrive from the left input. When a token is retracted, any matches that were previously established based on that token must be invalidated and retracted from successor nodes. This method iterates through all successor nodes and calls their Retract method with the specified token, ensuring that any tokens that were created as a result of the join condition involving the retracted token are also retracted from the network. This helps maintain the integrity of the Rete network as facts change over time. | |
| void | Refresh (object factOrToken, string propertyName) |
| The Refresh method is responsible for re-evaluating existing tokens or facts when a relevant change occurs. If a token or fact that is part of the join condition changes, this method will be called to ensure that all matches are re-evaluated and updated accordingly. For example, if a fact that was previously joined with a token changes, the Refresh method will re-evaluate the join condition for all tokens that were joined with that fact and propagate any necessary updates to successor nodes. This helps maintain the accuracy and consistency of the Rete network as facts and tokens evolve over time. | |
| void | DebugPrint (object fact, int level=0) |
| The DebugPrint method is a utility function that outputs the current state of the JoinNode for debugging purposes. It prints the name of the node and indicates that it has been reached, along with information about checking against the left memory. This method can be used to trace the flow of facts and tokens through the Rete network during development and troubleshooting, providing insight into how the JoinNode is processing incoming data and interacting with its inputs and successors. | |
Represents a join node in a RETE network that combines partial matches from the left input with facts from the right input based on a specified condition.
A JoinNode is a core component of the RETE algorithm, used in rule engines to efficiently match patterns against a set of facts. It receives tokens (partial matches) from its left input and facts from its right input, evaluating a join condition to determine which combinations should be propagated to successor nodes. The JoinNode manages both left and right activations and supports retraction and refresh operations to maintain consistency as facts change. Thread safety is not guaranteed; external synchronization may be required if used concurrently.
| ReteCore.JoinNode.JoinNode | ( | IReteNode? | left, |
| AlphaMemory? | right, | ||
| string | name, | ||
| Func< Token, object, bool > | cond ) |
A JoinNode combines tokens from the left input with facts from the right input based on a specified condition. When a new token arrives from the left input, it is evaluated against all facts in the right input memory using the provided condition function. If the condition is satisfied, a new token is created that combines the left token and the right fact, and this new token is propagated to all successor nodes. The JoinNode also supports retraction and refresh operations to maintain consistency as facts change. The constructor sets up the necessary connections to the left and right inputs and registers this node as a successor to those inputs as needed.
| left | The Beta memory holding the token to evaluate |
| right | The Alpha memory holding the fact |
| name | The name of the token to evaluate |
| cond | The predicate to evaluate which takes a Token and a Fact object and returns a boolean to indicate whether or not the condition succeeds. |
| void ReteCore.JoinNode.AddSuccessor | ( | IReteNode | node | ) |
Adds the specified node as a successor to this node in the Rete network.
| node | The node to add as a successor. Cannot be null. |
| void ReteCore.JoinNode.Assert | ( | object | fact | ) |
The Assert method is responsible for processing new facts or tokens that arrive at this JoinNode. When a new fact is asserted, the method evaluates the join condition against all existing tokens from the left input (if the fact is from the right input) or against all existing facts from the right input (if the fact is from the left input). If the condition is satisfied for any combination of token and fact, a new token is created that combines the left token and the right fact, and this new token is propagated to all successor nodes. This method ensures that the JoinNode correctly evaluates the join condition and maintains the flow of tokens through the Rete network as new facts are introduced. It also handles the case where the left input is a BetaMemory or a CompositeBetaMemory, allowing for proper integration with the rest of the network.
| fact | The fact object to be asserted and passed to successor nodes. Cannot be null. |
Implements ReteCore.IReteNode.
| void ReteCore.JoinNode.DebugPrint | ( | object | fact, |
| int | level = 0 ) |
The DebugPrint method is a utility function that outputs the current state of the JoinNode for debugging purposes. It prints the name of the node and indicates that it has been reached, along with information about checking against the left memory. This method can be used to trace the flow of facts and tokens through the Rete network during development and troubleshooting, providing insight into how the JoinNode is processing incoming data and interacting with its inputs and successors.
| fact | The fact object to include in the debug output. Can be any object; its string representation will be printed. |
| level | The indentation level to apply to the debug message. Each level increases indentation by spaces. Defaults to 0. |
Implements ReteCore.IReteNode.
| void ReteCore.JoinNode.Refresh | ( | object | factOrToken, |
| string | propertyName ) |
The Refresh method is responsible for re-evaluating existing tokens or facts when a relevant change occurs. If a token or fact that is part of the join condition changes, this method will be called to ensure that all matches are re-evaluated and updated accordingly. For example, if a fact that was previously joined with a token changes, the Refresh method will re-evaluate the join condition for all tokens that were joined with that fact and propagate any necessary updates to successor nodes. This helps maintain the accuracy and consistency of the Rete network as facts and tokens evolve over time.
| factOrToken | The fact from the right side or Token from the left to update. |
| propertyName | The name of the property being updated |
Implements ReteCore.IReteNode.
| void ReteCore.JoinNode.Retract | ( | object | fact | ) |
The Retract method for left activations is responsible for handling the retraction of tokens that arrive from the left input. When a token is retracted, any matches that were previously established based on that token must be invalidated and retracted from successor nodes. This method iterates through all successor nodes and calls their Retract method with the specified token, ensuring that any tokens that were created as a result of the join condition involving the retracted token are also retracted from the network. This helps maintain the integrity of the Rete network as facts change over time.
| fact | The fact object to retract. Cannot be null. |
Implements ReteCore.IReteNode.