public class RuleEvaluation extends Object
Modifier and Type | Field and Description |
---|---|
private Stack<Choicepoint> |
choicepoints
The choice points saved in this evaluation
|
private String |
currentContext
The current context of this evaluation, or null we're currently not in an interesting context
|
private String |
currentLabel
A label we should use to match candidate terms for.
|
private Evaluation |
evaluation
The evaluation owning this
|
private boolean |
inNegation
True when we are evaluating inside a condition which inverts the truth value
|
private List<FlattenedItem> |
items
The items to match in this evaluation
|
private Set<String> |
matchReferences
The references to matched contexts to be made in this evaluation
|
private List<Match> |
nonreferencedMatches |
private int |
position
The current position into the list of items
|
private List<ReferencedMatches> |
referencedMatchesList
A list of referencedMatches
|
private int |
startPosition
The start position into the item list
|
private Object |
value |
Constructor and Description |
---|
RuleEvaluation(Evaluation owner) |
Modifier and Type | Method and Description |
---|---|
void |
addItem(Item item,
TermType termType)
Adds an item to the query being evaluated in a way consistent with the query type
|
void |
addMatch(FlattenedItem item,
String replaceString)
Adds a match
|
(package private) int |
calculateMatchDigest(ProductionRule rule)
Calculates an id which is unique for each match (the totality of the matched terms)
to a high probability.
|
FlattenedItem |
currentItem()
Returns the current term item to look at,
or null if there are no more elements
|
int |
currentPosition()
Returns the position of the current item
|
void |
entering(String context) |
Choicepoint |
getChoicepoint(Condition condition,
boolean create)
Add a choice point to this evaluation
|
String |
getCurrentLabel() |
Evaluation |
getEvaluation()
Returns the evaluation this belongs to
|
Match |
getNonreferencedMatch(int index) |
int |
getNonreferencedMatchCount() |
int |
getPosition()
Returns the current position into the terms this evaluates over
|
int |
getReferencedMatchCount() |
ReferencedMatches |
getReferencedMatches(String name)
Returns the referenced matches for a context name, or null if none
|
int |
getTraceLevel() |
Object |
getValue()
Returns the last value returned by a condition in this evaluation, or null
|
void |
indentTrace() |
void |
initialize(List<FlattenedItem> list,
int startPosition) |
void |
insertItem(Item item,
CompositeItem parent,
int index,
TermType termType)
Inserts an item to the query being evaluated in a way consistent with the query type
|
boolean |
isInNegation()
Returns whether we are evaluating inside a condition which inverts the truth value
|
int |
itemCount()
Returns the total number of items to match in this evaluation
|
List<FlattenedItem> |
items()
Returns a read-only view of the items of this
|
void |
leaving(String context) |
private Choicepoint |
lookupChoicepoint(Condition condition) |
FlattenedItem |
next()
Advances currentItem to the next term item and returns thatItem.
|
(package private) List<Match> |
nonreferencedMatches() |
FlattenedItem |
previousItem() |
(package private) List<ReferencedMatches> |
referencedMatches() |
(package private) void |
reinitialize() |
void |
removeItem(int position,
Item item)
Removes an item, prefers the one at/close to the given position if there are multiple ones
|
void |
removeItem(Item item) |
void |
removeItemByIdentity(Item item) |
void |
removeMatches(ReferencedMatches matches)
Remove all the terms recognized by this match
|
String |
setCurrentLabel(String currentLabel)
Sets a new current label and returns the previous one
|
void |
setInNegation(boolean inNegation)
sets whether we are evaluating inside a condition which inverts the truth value
|
void |
setMatchReferences(Set<String> matchReferences) |
void |
setPosition(int position)
Sets the current position
|
void |
setValue(Object value)
Sets the last value returned by a condition in this evaluatiino, or null
|
void |
trace(int level,
String string) |
void |
unindentTrace() |
private List<FlattenedItem> items
private int position
private int startPosition
private Set<String> matchReferences
private String currentContext
private List<ReferencedMatches> referencedMatchesList
private Evaluation evaluation
private Stack<Choicepoint> choicepoints
private Object value
private boolean inNegation
private String currentLabel
public RuleEvaluation(Evaluation owner)
public void initialize(List<FlattenedItem> list, int startPosition)
void reinitialize()
int calculateMatchDigest(ProductionRule rule)
Calculates an id which is unique for each match (the totality of the matched terms) to a high probability. Why can we not simply look at the position of terms? Because rules are allowed to modify the query tree in ways that makes positions change.
This digest is also problematic, because it's really the matching condition who should calculate a match digest for that term which incorporates the semantics of that kind of match (maybe not the word and index, but something else). This is a todo for when we add other kinds of conditions.
public FlattenedItem currentItem()
public FlattenedItem previousItem()
public int currentPosition()
public void setPosition(int position)
public int itemCount()
public Object getValue()
public void setValue(Object value)
public boolean isInNegation()
public void setInNegation(boolean inNegation)
public int getPosition()
public String setCurrentLabel(String currentLabel)
public String getCurrentLabel()
public FlattenedItem next()
public void entering(String context)
public void leaving(String context)
public void addMatch(FlattenedItem item, String replaceString)
item
- the match to addreplaceString
- the string to replace this match by, usually the item.getIndexedValue()public ReferencedMatches getReferencedMatches(String name)
public int getReferencedMatchCount()
public int getNonreferencedMatchCount()
public Evaluation getEvaluation()
public void addItem(Item item, TermType termType)
public void removeItem(Item item)
public void removeItemByIdentity(Item item)
public void removeItem(int position, Item item)
public void insertItem(Item item, CompositeItem parent, int index, TermType termType)
item
- the item to insertparent
- the parent of this item, or null to set the rootindex
- the index at which to insert this into the parenttermType
- the kind of item to index, this decides the resulting structurepublic List<FlattenedItem> items()
public Match getNonreferencedMatch(int index)
public void trace(int level, String string)
public int getTraceLevel()
public void indentTrace()
public void unindentTrace()
public Choicepoint getChoicepoint(Condition condition, boolean create)
condition
- the creating conditioncreate
- true to create this choicepoint if it is missingprivate Choicepoint lookupChoicepoint(Condition condition)
List<ReferencedMatches> referencedMatches()
public void removeMatches(ReferencedMatches matches)
Copyright © 2018. All rights reserved.