Class Grammar

java.lang.Object
games.stendhal.common.grammar.Grammar

public class Grammar extends Object
Helper functions for producing and parsing grammatically-correct sentences.
  • Constructor Details

    • Grammar

      public Grammar()
  • Method Details

    • get

      public static Grammar get()
    • itthem

      public static String itthem(int quantity)
      "it" or "them", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "it" or "them" as appropriate
    • makeUpperCaseWord

      public static String makeUpperCaseWord(String word)
      Modify a word to upper case notation.
      Parameters:
      word -
      Returns:
      word with first letter in upper case
    • ItThem

      public static String ItThem(int quantity)
      "It" or "Them", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "It" or "Them" as appropriate
    • itthey

      public static String itthey(int quantity)
      "it" or "they", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "it" or "they" as appropriate
    • ItThey

      public static String ItThey(int quantity)
      "It" or "They", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "It" or "They" as appropriate
    • isare

      public static String isare(int quantity)
      "is" or "are", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "is" or "are" as appropriate
    • IsAre

      public static String IsAre(int quantity)
      "Is" or "Are", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "Is" or "Are" as appropriate
    • hashave

      public static String hashave(int quantity)
      "has" or "have", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "has" or "have" as appropriate
    • HasHave

      public static String HasHave(int quantity)
      "Has" or "Have", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "Has" or "Have" as appropriate
    • thatthose

      public static String thatthose(int quantity)
      "that" or "those", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "that" or "those" as appropriate
    • ThatThose

      public static String ThatThose(int quantity)
      "That or "Those", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "That" or "Those" as appropriate
    • thisthese

      public static String thisthese(int quantity)
      "this" or "these", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "this" or "these" as appropriate
    • ThisThese

      public static String ThisThese(int quantity)
      "This or "These", depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      Returns:
      Either "This" or "These" as appropriate
    • article_noun

      public static String article_noun(String noun, boolean definite)
      Prefixes a noun with an article.
      Parameters:
      noun - noun
      definite - true for "the", false for a/an
      Returns:
      noun with article
    • a_noun

      public static String a_noun(String noun)
      "a [noun]" or "an [noun]", depending on the first syllable.
      Parameters:
      noun - The noun to examine
      Returns:
      Either "a [noun]" or "an [noun]" as appropriate
    • a_nounCreature

      public static String a_nounCreature(String noun)
      "a [noun]" or "an [noun]", depending on the first syllable. Method to prevent collision of items and creatures.
      Parameters:
      noun - The noun to examine
      Returns:
      Either "a [noun]" or "an [noun]" as appropriate
    • fullForm

      public static String fullForm(String noun)
      Prefix a noun with an expression like "piece of".
      Parameters:
      noun -
      Returns:
      noun with prefix
    • replaceInternalByDisplayNames

      public static String replaceInternalByDisplayNames(String str)
      Replace internal item names bye their display name.
      Parameters:
      str -
      Returns:
      fixed string
    • mergeCompoundNoun

      public static Expression mergeCompoundNoun(Expression word1, Expression word2)
      Merge two expressions into a compound noun.
      Parameters:
      word1 -
      word2 -
      Returns:
      resulting expression: word1 or word2
    • extractNoun

      public static String extractNoun(String text)
      Extracts noun from a string, that may be prefixed with a plural expression like "piece of", ... So this function is just the counter part to fullForm().
      Parameters:
      text -
      Returns:
      the extracted noun
    • isNormalized

      public static boolean isNormalized(String text)
      Check if an expression is normalized. equivalent to: {return extractNoun(text) == text}
      Parameters:
      text -
      Returns:
      true if the expression is already normalized
    • A_noun

      public static String A_noun(String noun)
      "A [noun]" or "An [noun]", depending on the first syllable.
      Parameters:
      noun - The noun to examine
      Returns:
      Either "A [noun]" or "An [noun]" as appropriate
    • suffix_s

      public static String suffix_s(String noun)
      "[noun]'s" or "[noun]'", depending on the last character.
      Parameters:
      noun - The noun to examine
      Returns:
      Either "[noun]'s" or "[noun]'" as appropriate
    • plural

      public static String plural(String noun)
      Returns the plural form of the given noun if not already given in plural form.
      Parameters:
      noun - The noun to examine
      Returns:
      An appropriate plural form
    • pluralCreature

      public static String pluralCreature(String noun)
      Returns the plural form of the given noun if not already given in plural form. Method to prevent collision of items and creatures.
      Parameters:
      noun - The noun to examine
      Returns:
      An appropriate plural form
    • singular

      public static String singular(String enoun)
      Returns the singular form of the given noun if not already given in singular form.
      Parameters:
      enoun - The noun to examine
      Returns:
      An appropriate singular form
    • plnoun

      public static String plnoun(int quantity, String noun)
      Returns either the plural or singular form of the given noun, depending on the quantity.
      Parameters:
      quantity - The quantity to examine
      noun - The noun to examine
      Returns:
      Either "[noun]" or plural("[noun]") as appropriate
    • plnounCreature

      public static String plnounCreature(int quantity, String noun)
      Returns either the plural or singular form of the given noun, depending on the quantity. Method to prevent collision of items and creatures.
      Parameters:
      quantity - The quantity to examine
      noun - The noun to examine
      Returns:
      Either "[noun]" or plural("[noun]") as appropriate
    • quantityplnoun

      public static String quantityplnoun(int quantity, String noun)
      Returns either the plural or singular form of the given noun, depending on the quantity; also prefixes the quantity.
      Parameters:
      quantity - The quantity to examine
      noun - The noun to examine
      Returns:
      Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
    • quantityplnounCreature

      public static String quantityplnounCreature(int quantity, String noun)
      Returns either the plural or singular form of the given noun, depending on the quantity; also prefixes the quantity. Method to prevent collision of items and creatures
      Parameters:
      quantity - The quantity to examine
      noun - The noun to examine
      Returns:
      Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
    • quantityplnoun

      public static String quantityplnoun(int quantity, String noun, String one)
      Returns either the plural or singular form of the given noun, depending on the quantity; also prefixes the quantity. In case the quantity is exactly 1, the specified prefix is used. Note: There is some additional magic to convert "a" and "A" to "an" and "An" in case that is required by the noun.
      Parameters:
      quantity - The quantity to examine
      noun - The noun to examine
      one - replacement for "1".
      Returns:
      Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
    • quantityplnounWithHash

      public static String quantityplnounWithHash(int quantity, String noun)
      Returns either the plural or singular form of the given noun, depending on the quantity; also prefixes the quantity and prints the noun with a hash prefix.
      Parameters:
      quantity - The quantity to examine
      noun - The noun to examine
      Returns:
      Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
    • quantityplnounWithMarker

      public static String quantityplnounWithMarker(int quantity, String noun, char marker)
      Returns either the plural or singular form of the given noun, depending on the quantity; also prefixes the quantity and prints the noun with a specifier prefix.
      Parameters:
      quantity - The quantity to examine
      noun - The noun to examine
      marker - The character use for the markup. '#' or 'ยง'
      Returns:
      Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
    • quantityNumberStrNoun

      public static String quantityNumberStrNoun(int quantity, String noun)
      Returns either the plural or singular form of the given noun, depending on the quantity; also prefixes the quantity as number string, if appropriate.
      Parameters:
      quantity - The quantity to examine
      noun - The noun to examine
      Returns:
      Either "[quantity string] [noun]" or "[quantity string]" + plural("[noun]") as appropriate
    • isVowel

      protected static boolean isVowel(char c)
      Is the character a vowel?
      Parameters:
      c - The character to examine
      Returns:
      true if c is a vowel, false otherwise
    • isConsonant

      protected static boolean isConsonant(char c)
      Is the character a consonant?
      Parameters:
      c - The character to examine
      Returns:
      true if c is a consonant, false otherwise
    • ordered

      public static String ordered(int n)
      first, second, third, ...
      Parameters:
      n - a number
      Returns:
      first, second, third, ...
    • enumerateCollection

      public static String enumerateCollection(Collection<String> collection)
      Helper function to nicely formulate an enumeration of a collection.

      For example, for a collection containing the 3 elements x, y, z, returns the string "x, y, and z".

      Parameters:
      collection - The collection whose elements should be enumerated
      Returns:
      A nice String representation of the collection
    • enumerateCollection

      public static String enumerateCollection(Collection<String> collection, String conjunction)
      Helper function to nicely formulate an enumeration of a collection.

      For example, for a collection containing the 3 elements x, y, z, returns the string "x, y, and z".

      Parameters:
      collection - The collection whose elements should be enumerated
      conjunction - "and" or "or"
      Returns:
      A nice String representation of the collection
    • enumerateCollectionWithHash

      public static String enumerateCollectionWithHash(Collection<String> collection)
      Helper function to nicely formulate an enumeration of a collection, with hashes to colour the words.

      For example, for a collection containing the 3 elements x, y, z, returns the string "#x, #y, and #z".

      Parameters:
      collection - The collection whose elements should be enumerated
      Returns:
      A nice String representation of the collection with hashes
    • quoteHash

      public static String quoteHash(String str)
      To let the client display compound words like "#battle axe" in blue, we put the whole item name in quotes.
      Parameters:
      str -
      Returns:
      the hashed word
    • numberString

      public static String numberString(int n)
      Converts numbers into their textual representation.
      Parameters:
      n - a number
      Returns:
      one, two, three, ...
    • number

      public static Integer number(String text)
      Interprets number texts.
      Parameters:
      text - a number
      Returns:
      one, two, three, ...
    • normalizeRegularVerb

      public static Grammar.Verb normalizeRegularVerb(String word)
      Normalize the given regular verb, or return null if not applicable. Note: Some words like "close" are returned without the trailing "e" character. This is handled in WordList.normalizeVerb().
      Parameters:
      word -
      Returns:
      normalized string
    • isGerund

      public static boolean isGerund(String word)
      Check the given verb for gerund form, e.g. "doing".
      Parameters:
      word -
      Returns:
      true if gerund false otherwise
    • gerundForm

      public static String gerundForm(String word)
      Return gerund form, e.g. "making" or "casting".
      Parameters:
      word -
      Returns:
      gerund form
    • isDerivedAdjective

      public static boolean isDerivedAdjective(String word)
      Check the given word for derived adjectives like "magical" or "nomadic".
      Parameters:
      word -
      Returns:
      true if ends with "al", "ic" or "ed"
    • normalizeDerivedAdjective

      public static String normalizeDerivedAdjective(String word)
      Normalize the given derived adjective, or return null if not applicable.
      Parameters:
      word -
      Returns:
      normalized string
    • isAmbiguousNounVerb

      public static boolean isAmbiguousNounVerb(String normalized)
      Check for words with ambiguity between noun and verb.
      Parameters:
      normalized - word in normalized form
      Returns:
      ambiguity flag
    • enumerateCollectionPlural

      public static String enumerateCollectionPlural(Collection<String> collection)
      enumerates a collections using the plural forms.
      Parameters:
      collection - Collection
      Returns:
      enumeration using plural forms