Package com.yahoo.prelude.semantics.rule
Class Condition
- java.lang.Object
-
- com.yahoo.prelude.semantics.rule.Condition
-
- Direct Known Subclasses:
CompositeCondition
,ConditionReference
,EllipsisCondition
,LiteralCondition
,NotCondition
,SuperCondition
,TermCondition
public abstract class Condition extends Object
Superclass of all kinds of conditions of production rules- Author:
- bratseth
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Condition.Anchor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean
doesMatch(RuleEvaluation e)
Returns whether this condition matches the given evaluation at the current location of the evaluation.Condition.Anchor
getAnchor()
Returns the positional constraint on this anchor.String
getContextName()
Returns the name whatever is matched by this condition can be refered as, or null if it is unreferableString
getLabel()
Sets the label of this.protected String
getLabelString()
protected String
getMatchInfo(RuleEvaluation e)
Override this to return a string describing what this condition has matched in this evaluation.protected String
getMatchInfoString(RuleEvaluation e)
String
getNameSpace()
Returns the name of the namespace of this, or null if default (query)CompositeCondition
getParent()
Returns the condition this is nested within, or null if it is not nestedprotected boolean
hasOpenChoicepoint(RuleEvaluation e)
Returns whether there is an open choice in this or any of its subconditions.protected boolean
isDefaultContextName()
protected boolean
isReferable()
Returns whether this is referable, returns context!=null by defaultprotected boolean
labelMatches(TermItem evaluationTerm, RuleEvaluation e)
protected boolean
labelMatches(RuleEvaluation e)
Whether the label matches the current item, true if there is no current itemvoid
makeReferences(RuleBase rules)
Override if references needs to be set in this condition of its childrenboolean
matches(RuleEvaluation e)
Returns whether this condition matches the given evaluation at the current location of the evaluation.protected boolean
matchesEndAnchor(RuleEvaluation e)
Check start anchor.protected boolean
matchesStartAnchor(RuleEvaluation e)
Check start anchor.protected void
postMatchHook(RuleEvaluation e)
Called just before match returns, on any return condition including exceptions.protected void
preMatchHook(RuleEvaluation e)
Called when match is called, before anything else.void
setAnchor(Condition.Anchor anchor)
Sets a positional constraint on this conditionvoid
setContextName(String contextName)
Sets the name whatever is matched by this condition can be refered as, or null to make it unreferablevoid
setLabel(String label)
Returns the label of this, or null if none (the default)void
setNameSpace(String nameSpace)
Sets the name of the namespace of thisprotected abstract String
toInnerString()
All instances of this produces a parseable string outputString
toString()
protected void
traceResult(boolean matches, RuleEvaluation e)
-
-
-
Method Detail
-
setContextName
public void setContextName(String contextName)
Sets the name whatever is matched by this condition can be refered as, or null to make it unreferable
-
getContextName
public String getContextName()
Returns the name whatever is matched by this condition can be refered as, or null if it is unreferable
-
isReferable
protected boolean isReferable()
Returns whether this is referable, returns context!=null by default
-
getLabel
public String getLabel()
Sets the label of this. Set to null to use the default
-
setLabel
public void setLabel(String label)
Returns the label of this, or null if none (the default)
-
getNameSpace
public String getNameSpace()
Returns the name of the namespace of this, or null if default (query)
-
setNameSpace
public void setNameSpace(String nameSpace)
Sets the name of the namespace of this
-
getParent
public CompositeCondition getParent()
Returns the condition this is nested within, or null if it is not nested
-
setAnchor
public void setAnchor(Condition.Anchor anchor)
Sets a positional constraint on this condition
-
getAnchor
public Condition.Anchor getAnchor()
Returns the positional constraint on this anchor. This is never null
-
matches
public final boolean matches(RuleEvaluation e)
Returns whether this condition matches the given evaluation at the current location of the evaluation. Calls the doesMatch method of each condition subtype.
-
matchesStartAnchor
protected boolean matchesStartAnchor(RuleEvaluation e)
Check start anchor. Trace level 4 if no match
-
matchesEndAnchor
protected boolean matchesEndAnchor(RuleEvaluation e)
Check start anchor. Trace level 4 if no match
-
traceResult
protected void traceResult(boolean matches, RuleEvaluation e)
-
getMatchInfoString
protected String getMatchInfoString(RuleEvaluation e)
-
preMatchHook
protected void preMatchHook(RuleEvaluation e)
Called when match is called, before anything else. Always call super.preMatchHook when overriding.
-
postMatchHook
protected void postMatchHook(RuleEvaluation e)
Called just before match returns, on any return condition including exceptions. Always call super.postMatchHook when overriding
-
getMatchInfo
protected String getMatchInfo(RuleEvaluation e)
Override this to return a string describing what this condition has matched in this evaluation. Will only be called when this condition is actually matched in this condition- Returns:
- info about what is matched, or null if there is no info to return (default)
-
doesMatch
protected abstract boolean doesMatch(RuleEvaluation e)
Returns whether this condition matches the given evaluation at the current location of the evaluation. If there is a match, the evaluation must be advanced to the location beyond the matching item(s) before this method returns.
-
hasOpenChoicepoint
protected boolean hasOpenChoicepoint(RuleEvaluation e)
Returns whether there is an open choice in this or any of its subconditions. Returns false by default, must be overriden by conditions which may generate choices open accross multiple calls to matches, or contain such conditions.
-
makeReferences
public void makeReferences(RuleBase rules)
Override if references needs to be set in this condition of its children
-
getLabelString
protected String getLabelString()
-
labelMatches
protected boolean labelMatches(RuleEvaluation e)
Whether the label matches the current item, true if there is no current item
-
labelMatches
protected boolean labelMatches(TermItem evaluationTerm, RuleEvaluation e)
-
toInnerString
protected abstract String toInnerString()
All instances of this produces a parseable string output
-
isDefaultContextName
protected boolean isDefaultContextName()
-
-