Class ReteBuilder
- java.lang.Object
-
- jadex.rules.rulesystem.rete.builder.ReteBuilder
-
public class ReteBuilder extends java.lang.Object
The rete builder class has the purpose to generate a rete network for a condition.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
indexing
Flag to turn on/off indexing.protected boolean
nodesharing
Flag to turn on/off nodesharing.protected boolean
notjoin
Flag to turn on/off placing join constraints in a not node (otherwise separate beta nodes will be created and not nodes will have no constraints).protected BuildReport
report
The build report.static boolean
REPORTING
The flag for turning on/off reporting.
-
Constructor Summary
Constructors Constructor Description ReteBuilder()
Create a new rete builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addAlphaNode(IConstraintEvaluator[] evas, BuildContext context)
Add a new alpha node.protected void
addBetaNode(IConstraintEvaluator[] evas, ConstraintIndexer[] ids, BuildContext context)
Add a new beta node.protected void
addCollectNode(IConstraintEvaluator[] evas, int tuplecnt, BuildContext context)
Add a new collect node.protected void
addInitialFactNode(BuildContext context)
Add an initial fact node.protected void
addNotNode(IConstraintEvaluator[] evas, ConstraintIndexer[] ids, int tuplecnt, BuildContext context)
Add a new not node.ReteNode
addRule(ReteNode root, IRule rule)
Add a new rule to the network.protected void
addSplitNode(OAVAttributeType attr, java.lang.String[] binds, BuildContext context)
Add a new split node.protected void
addTerminalNode(IRule rule, BuildContext context)
Add a new terminal node.protected void
addTestNode(IConstraintEvaluator eva, BuildContext context)
Add a new test node.protected void
addTypeNode(OAVObjectType type, BuildContext context)
Add a new type node.void
buildAndCondition(AndCondition curcond, BuildContext context)
Build an and condition.void
buildCollectCondition(CollectCondition curcond, BuildContext context)
Build a collect condition.void
buildCondition(ICondition curcond, BuildContext context)
Build any kind condition.protected java.util.List
buildConstraintEvaluator(ICondition cond, IConstraint c, BuildContext context)
Generate constraint evaluator for a constraint.protected java.util.List
buildConstraintIndexer(ObjectCondition cond, IConstraint c, BuildContext context)
Generate a constraint indexer for a top-level equal join.IValueExtractor
buildFunctionExtractor(int tupleindex, FunctionCall fc, int subindex, BuildContext context)
Build a function extractor for a function call.void
buildNotCondition(NotCondition curcond, BuildContext context)
Build a not condition.void
buildObjectCondition(ObjectCondition curcond, BuildContext context)
Build an object condition.void
buildOrCondition(OrCondition curcond, BuildContext context)
Build an or condition.void
buildTestCondition(TestCondition curcond, BuildContext context)
Build a test condition.protected IValueExtractor
buildVariableExtractor(Variable var, BuildContext context)
Build a variable extractor for an alpha or beta context.protected void
connectLeft(INode source, INode consumer, BuildContext context)
Connect two nodes by attaching the source to the left (tuple) input of the consumer.protected void
connectRight(INode source, INode consumer, BuildContext context)
Connect two nodes by attaching the source to the right (object) input of the consumer.IValueExtractor
createArrayExtractor(int tupleindex, ArraySelector as, BuildContext context, boolean prefix)
Build an array extractor for an array selector.IValueExtractor
createMethodExtractor(int tupleindex, MethodCall mc, BuildContext context, boolean prefix)
Build a method extractor for a method call.protected IValueExtractor
createObjectExtractor(OAVAttributeType attr, java.lang.Object key)
Create an object extractor for the given (OAV or Java) attribute.protected IValueExtractor
createPrefixExtractor(OAVAttributeType attr, java.lang.Object key)
Create a prefix extractor for the given (OAV or Java) attribute.protected IValueExtractor
createTupleExtractor(int tupleindex, OAVAttributeType attr, java.lang.Object key)
Create a tuple extractor for the given (OAV or Java) attribute.IValueExtractor
createValueExtractor(int tupleindex, java.lang.Object valuesource, int subindex, BuildContext context, boolean prefix)
Creates an appropriate extractor for the given parameters.BuildReport
getBuildReport()
Get the build report.protected int
getChildCount(INode node)
Count the number of children.protected IValueExtractor
getLeftVariableExtractor(BuildContext context, Variable var)
Get the evaluator for the first occurrence of the given variable (when needed as left input).protected IValueExtractor
getRightVariableExtractor(BuildContext context, Variable var)
Get the evaluator for the first occurrence of the given variable (when needed as right input).protected boolean
isAlphaExecutable(ICondition cond, IConstraint c)
Test if all needed variables are available from the condition directly.protected void
removeNodeUsage(INode node)
Remove a node usage.void
removeRule(ReteNode root, IRule rule)
Remove a rule from a rete network.
-
-
-
Field Detail
-
REPORTING
public static final boolean REPORTING
The flag for turning on/off reporting.- See Also:
- Constant Field Values
-
indexing
protected boolean indexing
Flag to turn on/off indexing.
-
nodesharing
protected boolean nodesharing
Flag to turn on/off nodesharing.
-
notjoin
protected boolean notjoin
Flag to turn on/off placing join constraints in a not node (otherwise separate beta nodes will be created and not nodes will have no constraints).
-
report
protected BuildReport report
The build report.
-
-
Method Detail
-
addRule
public ReteNode addRule(ReteNode root, IRule rule)
Add a new rule to the network.- Parameters:
root
- The root node (when null a new network will be created).rule
- The rule to add.
-
removeRule
public void removeRule(ReteNode root, IRule rule)
Remove a rule from a rete network.- Parameters:
root
- The root node.rule
- The rule to remove.
-
getBuildReport
public BuildReport getBuildReport()
Get the build report.- Returns:
- The build report.
-
buildCondition
public void buildCondition(ICondition curcond, BuildContext context)
Build any kind condition.
-
buildAndCondition
public void buildAndCondition(AndCondition curcond, BuildContext context)
Build an and condition.
-
buildOrCondition
public void buildOrCondition(OrCondition curcond, BuildContext context)
Build an or condition.
-
buildNotCondition
public void buildNotCondition(NotCondition curcond, BuildContext context)
Build a not condition.
-
buildObjectCondition
public void buildObjectCondition(ObjectCondition curcond, BuildContext context)
Build an object condition.- Parameters:
curcond
- the object condition.context
- The build context.
-
buildTestCondition
public void buildTestCondition(TestCondition curcond, BuildContext context)
Build a test condition.
-
buildCollectCondition
public void buildCollectCondition(CollectCondition curcond, BuildContext context)
Build a collect condition.
-
removeNodeUsage
protected void removeNodeUsage(INode node)
Remove a node usage.- Parameters:
node
- The node usage to remove.
-
getChildCount
protected int getChildCount(INode node)
Count the number of children.- Parameters:
node
- The node.- Returns:
- The number of children.
-
connectLeft
protected void connectLeft(INode source, INode consumer, BuildContext context)
Connect two nodes by attaching the source to the left (tuple) input of the consumer.- Parameters:
source
- The source node.consumer
- The consumer node.
-
connectRight
protected void connectRight(INode source, INode consumer, BuildContext context)
Connect two nodes by attaching the source to the right (object) input of the consumer.- Parameters:
source
- The source node.consumer
- The consumer node.
-
buildConstraintIndexer
protected java.util.List buildConstraintIndexer(ObjectCondition cond, IConstraint c, BuildContext context)
Generate a constraint indexer for a top-level equal join.
-
buildConstraintEvaluator
protected java.util.List buildConstraintEvaluator(ICondition cond, IConstraint c, BuildContext context)
Generate constraint evaluator for a constraint.- Parameters:
cond
- The object condition.c
- The constraint.context
- The build context.- Returns:
- The constraint evaluator.
-
buildFunctionExtractor
public IValueExtractor buildFunctionExtractor(int tupleindex, FunctionCall fc, int subindex, BuildContext context)
Build a function extractor for a function call.- Parameters:
fc
- The function call.- Returns:
- The function call.
-
buildVariableExtractor
protected IValueExtractor buildVariableExtractor(Variable var, BuildContext context)
Build a variable extractor for an alpha or beta context. If it is a beta context the function determines if the variable value is available from the left or from the right.- Parameters:
var
- The variable.context
- The build context.alpha
- Is the extractor for alpha or beta context.
-
isAlphaExecutable
protected boolean isAlphaExecutable(ICondition cond, IConstraint c)
Test if all needed variables are available from the condition directly. All variables must be declared as BoundConstraints with equal operator in this object condition.- Returns:
- True, if can be evaluated in alpha network.
-
addTypeNode
protected void addTypeNode(OAVObjectType type, BuildContext context)
Add a new type node.- Parameters:
type
- The type node.context
- the build context.
-
addAlphaNode
protected void addAlphaNode(IConstraintEvaluator[] evas, BuildContext context)
Add a new alpha node.- Parameters:
eva
- The constraint evaluator.context
- The build context.
-
addSplitNode
protected void addSplitNode(OAVAttributeType attr, java.lang.String[] binds, BuildContext context)
Add a new split node.- Parameters:
attr
- The attribute.binds
- The binding variable codes.context
- The build context.
-
addBetaNode
protected void addBetaNode(IConstraintEvaluator[] evas, ConstraintIndexer[] ids, BuildContext context)
Add a new beta node.- Parameters:
evas
- The constraint evaluators.ids
- The constraint indexers.context
- The build context.
-
addNotNode
protected void addNotNode(IConstraintEvaluator[] evas, ConstraintIndexer[] ids, int tuplecnt, BuildContext context)
Add a new not node.- Parameters:
evas
- The constraint evaluators.ids
- The constraint indexers.context
- The build context.
-
addInitialFactNode
protected void addInitialFactNode(BuildContext context)
Add an initial fact node.- Parameters:
context
- The build context.
-
addTestNode
protected void addTestNode(IConstraintEvaluator eva, BuildContext context)
Add a new test node.- Parameters:
eva
- The constraint evaluator.context
- The build context.
-
addCollectNode
protected void addCollectNode(IConstraintEvaluator[] evas, int tuplecnt, BuildContext context)
Add a new collect node.- Parameters:
eva
- The constraint evaluator.context
- The build context.
-
addTerminalNode
protected void addTerminalNode(IRule rule, BuildContext context)
Add a new terminal node.- Parameters:
rule
- The rule.context
- The build context.
-
getRightVariableExtractor
protected IValueExtractor getRightVariableExtractor(BuildContext context, Variable var)
Get the evaluator for the first occurrence of the given variable (when needed as right input).- Parameters:
var
- The variable.- Returns:
- The extractor for the first occurrence.
-
getLeftVariableExtractor
protected IValueExtractor getLeftVariableExtractor(BuildContext context, Variable var)
Get the evaluator for the first occurrence of the given variable (when needed as left input).- Parameters:
var
- The variable.- Returns:
- The extractor for the first occurrence.
-
createValueExtractor
public IValueExtractor createValueExtractor(int tupleindex, java.lang.Object valuesource, int subindex, BuildContext context, boolean prefix)
Creates an appropriate extractor for the given parameters.- Parameters:
tupleindex
- The tuple index (-1 for none).attr
- The attribute.subindex
- The subindex when multisplit (-1 for none).- Returns:
- The value extractor.
-
createMethodExtractor
public IValueExtractor createMethodExtractor(int tupleindex, MethodCall mc, BuildContext context, boolean prefix)
Build a method extractor for a method call.- Parameters:
mc
- The method call.- Returns:
- The method call.
-
createArrayExtractor
public IValueExtractor createArrayExtractor(int tupleindex, ArraySelector as, BuildContext context, boolean prefix)
Build an array extractor for an array selector.- Parameters:
as
- The array selector.- Returns:
- The value extractor.
-
createObjectExtractor
protected IValueExtractor createObjectExtractor(OAVAttributeType attr, java.lang.Object key)
Create an object extractor for the given (OAV or Java) attribute.- Parameters:
attr
- The attribute.- Returns:
- The extractor.
-
createTupleExtractor
protected IValueExtractor createTupleExtractor(int tupleindex, OAVAttributeType attr, java.lang.Object key)
Create a tuple extractor for the given (OAV or Java) attribute.- Parameters:
attr
- The attribute.- Returns:
- The extractor.
-
createPrefixExtractor
protected IValueExtractor createPrefixExtractor(OAVAttributeType attr, java.lang.Object key)
Create a prefix extractor for the given (OAV or Java) attribute.- Parameters:
attr
- The attribute.- Returns:
- The extractor.
-
-