Class Expression

java.lang.Object
games.stendhal.common.parser.Expression

public final class Expression extends Object
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 Details

    • EMPTY_EXPRESSION

      public static final Expression EMPTY_EXPRESSION
      Instance of an empty Expression.
    • JOKER

      public static final String JOKER
      JOKER is a joker String used in pattern matches.
      See Also:
      Constant Field Values
  • Constructor Details

    • Expression

      public Expression(String word, String typeString)
      Create an Expression from a single word and a type string.
      Parameters:
      word -
      typeString -
  • Method Details

    • parseAmount

      public void parseAmount(String str, ErrorDrain errors)
      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

      public 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.
      Parameters:
      other -
    • mergeLeft

      public void mergeLeft(Expression prec, boolean mergeNormalized)
      Merge the given preceding Expression into this Expression, while leaving mainWord unchanged.
      Parameters:
      prec -
      mergeNormalized -
    • mergeRight

      public void mergeRight(Expression other, boolean mergeNormalized)
      Merge the given following Expression into this Expression, while leaving mainWord unchanged.
      Parameters:
      other -
      mergeNormalized -
    • mergeName

      public void mergeName(Expression next, ExpressionType newType)
      Merge the given following name component into this Expression.
      Parameters:
      next -
      newType -
    • setAmount

      public void setAmount(Integer amount)
      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

      public void setMatcher(ExpressionMatcher matcher)
      Set Expression matcher.
      Parameters:
      matcher -
    • getMatcher

      public ExpressionMatcher getMatcher()
      Return matcher used for matching this expression.
      Returns:
      matcher
    • getOriginal

      public String getOriginal()
      Returns:
      the original, un-normalized string expression.
    • setNormalized

      public void setNormalized(String normalized)
      Set the normalized form of the expression.
      Parameters:
      normalized -
    • getNormalized

      public String getNormalized()
      Return the normalized form of the Expression.
      Returns:
      normalized form
    • getMainWord

      public String getMainWord()
      Returns:
      the main word of the expression.
    • getBreakFlag

      public boolean getBreakFlag()
      Returns:
      the break flag to check for sentence part borders.
    • setType

      public void setType(ExpressionType type)
      Set Expression type.
      Parameters:
      type -
    • getType

      public ExpressionType getType()
      Returns:
      Expression type.
    • getTypeString

      public String 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

      public void mergeType(ExpressionType otherType)
      Merge Expression type with another one while handling null values.
      Parameters:
      otherType -
    • getNormalizedWithTypeString

      public String getNormalizedWithTypeString()
      Return the normalized Expression with type.
      Returns:
      string in the format NORMALIZED/TYPE.
    • matches

      public boolean matches(Expression other)
      Check if two Expressions match exactly.
      Parameters:
      other - Expression
      Returns:
      true if two expression match, false otherwise
    • matchesNormalized

      public boolean matchesNormalized(Expression other)
      Check if two Expressions match each other.
      Parameters:
      other - Expression
      Returns:
      true if two expression match, false otherwise
    • matchesNormalizedSimilar

      public boolean matchesNormalizedSimilar(Expression other)
      Check if the Expression is similar to another Expression.
      Parameters:
      other - Expression
      Returns:
      true if two expression match, false otherwise
    • matchesJokerString

      public static boolean matchesJokerString(String str, String matchString)
      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

      public boolean equals(Object other)
      Check for equality of two Expression objects.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns a hash code for this Expression object.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Return a simple string representation of the Expression.
      Overrides:
      toString in class Object