Package games.stendhal.common.parser
Class Expression
java.lang.Object
games.stendhal.common.parser.Expression
An Expression is part of a Sentence. It encapsulates the original, white space trimmed text, the
expression type, a normalized lower case text string and the integer amount.
- Author:
- Martin Fuchs
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ExpressionInstance of an empty Expression.static final StringJOKER is a joker String used in pattern matches. -
Constructor Summary
ConstructorsConstructorDescriptionExpression(String word, String typeString) Create an Expression from a single word and a type string. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck for equality of two Expression objects.intlongbooleanReturn matcher used for matching this expression.Return the normalized form of the Expression.Return the normalized Expression with type.getType()booleaninthashCode()Returns a hash code for this Expression object.booleanDetermine if the Expression contains a dynamically defined word.booleanisIgnore()Determine Expressions to ignore.booleanDetermine if the Expression is negated.booleanDetermine if the Expression consists of numeral words.booleanisObject()Determine if the Expression is an object.booleanDetermine if the Expression consists of prepositions.booleanDetermine if the Expression consists of question words.booleanDetermine if the Expression represents a person.booleanisVerb()Determine if the Expression consists of verbs.booleanmatches(Expression other) Check if two Expressions match exactly.static booleanmatchesJokerString(String str, String matchString) Match the given String against a pattern String containing JOKER characters.booleanmatchesNormalized(Expression other) Check if two Expressions match each other.booleanCheck if the Expression is similar to another Expression.voidmergeLeft(Expression prec, boolean mergeNormalized) Merge the given preceding Expression into this Expression, while leaving mainWord unchanged.voidmergeName(Expression next, ExpressionType newType) Merge the given following name component into this Expression.voidmergeRight(Expression other, boolean mergeNormalized) Merge the given following Expression into this Expression, while leaving mainWord unchanged.voidmergeSimple(Expression other) Merge the given preceding Expression into this Expression while leaving mainWord unchanged.The members normalized and original are only touched when negating the expression.voidmergeType(ExpressionType otherType) Merge Expression type with another one while handling null values.voidnegate()Negate the expression.voidparseAmount(String str, ErrorDrain errors) Parse the given numeric expression and assign the value to 'amount'.voidSet item count.voidSet the break flag to define sentence part borders.voidsetMatcher(ExpressionMatcher matcher) Set Expression matcher.voidsetNormalized(String normalized) Set the normalized form of the expression.voidsetType(ExpressionType type) Set Expression type.toString()Return a simple string representation of the Expression.
-
Field Details
-
EMPTY_EXPRESSION
Instance of an empty Expression. -
JOKER
JOKER is a joker String used in pattern matches.- See Also:
-
-
Constructor Details
-
Expression
Create an Expression from a single word and a type string.- Parameters:
word-typeString-
-
-
Method Details
-
parseAmount
Parse the given numeric expression and assign the value to 'amount'. TODO mf - We may switch from Integer to Long if we extend the column type in table 'words'- Parameters:
str-errors-
-
mergeSimple
Merge the given preceding Expression into this Expression while leaving mainWord unchanged.The members normalized and original are only touched when negating the expression.- Parameters:
other-
-
mergeLeft
Merge the given preceding Expression into this Expression, while leaving mainWord unchanged.- Parameters:
prec-mergeNormalized-
-
mergeRight
Merge the given following Expression into this Expression, while leaving mainWord unchanged.- Parameters:
other-mergeNormalized-
-
mergeName
Merge the given following name component into this Expression.- Parameters:
next-newType-
-
setAmount
Set item count.- Parameters:
amount-
-
getAmount
public int getAmount()- Returns:
- amount as integer value, default to 1.
-
hasAmount
public boolean hasAmount()- Returns:
- true if there is an explicit amount.
-
getAmountLong
public long getAmountLong()- Returns:
- amount as long integer value, default to 1.
-
setBreakFlag
public void setBreakFlag()Set the break flag to define sentence part borders. -
setMatcher
Set Expression matcher.- Parameters:
matcher-
-
getMatcher
Return matcher used for matching this expression.- Returns:
- matcher
-
getOriginal
- Returns:
- the original, un-normalized string expression.
-
setNormalized
Set the normalized form of the expression.- Parameters:
normalized-
-
getNormalized
Return the normalized form of the Expression.- Returns:
- normalized form
-
getMainWord
- Returns:
- the main word of the expression.
-
getBreakFlag
public boolean getBreakFlag()- Returns:
- the break flag to check for sentence part borders.
-
setType
Set Expression type.- Parameters:
type-
-
getType
- Returns:
- Expression type.
-
getTypeString
- Returns:
- string representation of Expression type
-
isVerb
public boolean isVerb()Determine if the Expression consists of verbs.- Returns:
- false if not a verb or null, true otherwise
-
isObject
public boolean isObject()Determine if the Expression is an object. (a thing, not a person)- Returns:
- false if not an object or null, true otherwise
-
isSubject
public boolean isSubject()Determine if the Expression represents a person.- Returns:
- false if not a subject or null, true otherwise
-
isNegated
public boolean isNegated()Determine if the Expression is negated.- Returns:
- false if not negated or null, true otherwise
-
isIgnore
public boolean isIgnore()Determine Expressions to ignore.- Returns:
- false if not ignored or null, true otherwise
-
isQuestion
public boolean isQuestion()Determine if the Expression consists of question words.- Returns:
- false if not a question or null, true otherwise
-
isPreposition
public boolean isPreposition()Determine if the Expression consists of prepositions.- Returns:
- false if not a preposition or null, true otherwise
-
isNumeral
public boolean isNumeral()Determine if the Expression consists of numeral words.- Returns:
- false if not a numeral or null, true otherwise
-
isDynamic
public boolean isDynamic()Determine if the Expression contains a dynamically defined word.- Returns:
- true dynamically created
-
mergeType
Merge Expression type with another one while handling null values.- Parameters:
otherType-
-
getNormalizedWithTypeString
Return the normalized Expression with type.- Returns:
- string in the format NORMALIZED/TYPE.
-
matches
Check if two Expressions match exactly.- Parameters:
other- Expression- Returns:
- true if two expression match, false otherwise
-
matchesNormalized
Check if two Expressions match each other.- Parameters:
other- Expression- Returns:
- true if two expression match, false otherwise
-
matchesNormalizedSimilar
Check if the Expression is similar to another Expression.- Parameters:
other- Expression- Returns:
- true if two expression match, false otherwise
-
matchesJokerString
Match the given String against a pattern String containing JOKER characters.- Parameters:
str-matchString-- Returns:
- true if two expression match, false otherwise
-
negate
public void negate()Negate the expression. This is used in SentenceImplementation to normalize sentences containing "don't" expressions. -
equals
Check for equality of two Expression objects. -
hashCode
public int hashCode()Returns a hash code for this Expression object. -
toString
Return a simple string representation of the Expression.
-