Package com.saxonica.ee.trans
Class PatternOptimizer
java.lang.Object
com.saxonica.ee.trans.PatternOptimizer
- Direct Known Subclasses:
AncestorPatternOptimizer
,ContainsTokenPatternOptimizer
,EqualityPatternOptimizer
,GeneralPatternOptimizer
,IntEqualityPatternOptimizer
A PatternOptimizer is an agent responsible for optimizing a particular class
of patterns. It has two parts: a meta-pattern which determines which kinds of
pattern it recognizes, and an action part which extracts characteristics and
preconditions whose evaluation can be shared by all the rules in a rule chain
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addPrecondition
(RuleEE rule, Map<Precondition, List<RuleEE>> preconditions, Precondition p) protected Characteristic
allocateCharacteristic
(Map<Characteristic, Characteristic> characteristics, Characteristic newChic) Allocate a new characteristic, that is, a property of nodes or other items that may potentially be used in evaluating the preconditions of more than one pattern.abstract boolean
Ask whether this pattern optimizer is applicable to a particular patternabstract void
process
(RuleEE rule, Pattern pattern, Map<Precondition, List<RuleEE>> preconditions, Map<Characteristic, Characteristic> characteristics) Process a particular pattern, potentially adding to the list of preconditions and characteristics maintained when processing a set of rules
-
Constructor Details
-
PatternOptimizer
public PatternOptimizer()
-
-
Method Details
-
appliesTo
Ask whether this pattern optimizer is applicable to a particular pattern- Parameters:
pattern
- the pattern in question- Returns:
- true if this pattern optimizer is applicable to this pattern
-
process
public abstract void process(RuleEE rule, Pattern pattern, Map<Precondition, List<RuleEE>> preconditions, Map<Characteristic, Characteristic> characteristics) Process a particular pattern, potentially adding to the list of preconditions and characteristics maintained when processing a set of rules- Parameters:
rule
- the rule to be processedpattern
- the pattern used by this rulepreconditions
- a collection of preconditions maintained for a set of rulescharacteristics
- a collection of characteristics maintained for a set of rules. This is maintained as a map from characteristics to characteristics in which the key and the value are always the same; the reason for this curious structure is that when an equivalent characteristic is already present in the map, we want to return the existing characteristic to replace the new one; a JavaSet
does not have any (efficient) operation to "find the existing value in the set that is equal to X".
-
allocateCharacteristic
protected Characteristic allocateCharacteristic(Map<Characteristic, Characteristic> characteristics, Characteristic newChic) Allocate a new characteristic, that is, a property of nodes or other items that may potentially be used in evaluating the preconditions of more than one pattern.- Parameters:
characteristics
- The set of characteristics to be added to. This maintained as a map from characteristics to characteristics for reasons explained atprocess(RuleEE, Pattern, Map, Map)
.newChic
- a new characteristic to be added to the set.- Returns:
- the supplied characteristic unless there was already an equivalent characteristic in the set, in which case an equivalent characteristic that should be used in place of the new one.
-
addPrecondition
protected void addPrecondition(RuleEE rule, Map<Precondition, List<RuleEE>> preconditions, Precondition p)
-