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
Modifier and TypeFieldDescriptionstatic Expression
Instance of an empty Expression.static String
JOKER is a joker String used in pattern matches. -
Constructor Summary
ConstructorDescriptionExpression(String word, String typeString)
Create an Expression from a single word and a type string. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Check for equality of two Expression objects.int
long
boolean
Return matcher used for matching this expression.Return the normalized form of the Expression.Return the normalized Expression with type.getType()
boolean
int
hashCode()
Returns a hash code for this Expression object.boolean
Determine if the Expression contains a dynamically defined word.boolean
isIgnore()
Determine Expressions to ignore.boolean
Determine if the Expression is negated.boolean
Determine if the Expression consists of numeral words.boolean
isObject()
Determine if the Expression is an object.boolean
Determine if the Expression consists of prepositions.boolean
Determine if the Expression consists of question words.boolean
Determine if the Expression represents a person.boolean
isVerb()
Determine if the Expression consists of verbs.boolean
matches(Expression other)
Check if two Expressions match exactly.static boolean
matchesJokerString(String str, String matchString)
Match the given String against a pattern String containing JOKER characters.boolean
matchesNormalized(Expression other)
Check if two Expressions match each other.boolean
matchesNormalizedSimilar(Expression other)
Check if the Expression is similar to another Expression.void
mergeLeft(Expression prec, boolean mergeNormalized)
Merge the given preceding Expression into this Expression, while leaving mainWord unchanged.void
mergeName(Expression next, ExpressionType newType)
Merge the given following name component into this Expression.void
mergeRight(Expression other, boolean mergeNormalized)
Merge the given following Expression into this Expression, while leaving mainWord unchanged.void
mergeSimple(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.void
mergeType(ExpressionType otherType)
Merge Expression type with another one while handling null values.void
negate()
Negate the expression.void
parseAmount(String str, ErrorDrain errors)
Parse the given numeric expression and assign the value to 'amount'.void
Set item count.void
Set the break flag to define sentence part borders.void
setMatcher(ExpressionMatcher matcher)
Set Expression matcher.void
setNormalized(String normalized)
Set the normalized form of the expression.void
setType(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:
- Constant Field Values
-
-
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.
-