Package games.stendhal.common.grammar
Class Grammar
java.lang.Object
games.stendhal.common.grammar.Grammar
Helper functions for producing and parsing grammatically-correct sentences.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Return type for normalizedRegularVerb(). -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
"a [noun]" or "an [noun]", depending on the first syllable.static String
"A [noun]" or "An [noun]", depending on the first syllable.static String
a_nounCreature(String noun)
"a [noun]" or "an [noun]", depending on the first syllable.static String
article_noun(String noun, boolean definite)
Prefixes a noun with an article.static String
enumerateCollection(Collection<String> collection)
Helper function to nicely formulate an enumeration of a collection.static String
enumerateCollection(Collection<String> collection, String conjunction)
Helper function to nicely formulate an enumeration of a collection.static String
enumerateCollectionPlural(Collection<String> collection)
enumerates a collections using the plural forms.static String
enumerateCollectionWithHash(Collection<String> collection)
Helper function to nicely formulate an enumeration of a collection, with hashes to colour the words.static String
extractNoun(String text)
Extracts noun from a string, that may be prefixed with a plural expression like "piece of", ...static String
Prefix a noun with an expression like "piece of".static String
gerundForm(String word)
Return gerund form, e.g.static Grammar
get()
static String
hashave(int quantity)
"has" or "have", depending on the quantity.static String
HasHave(int quantity)
"Has" or "Have", depending on the quantity.static boolean
isAmbiguousNounVerb(String normalized)
Check for words with ambiguity between noun and verb.static String
isare(int quantity)
"is" or "are", depending on the quantity.static String
IsAre(int quantity)
"Is" or "Are", depending on the quantity.protected static boolean
isConsonant(char c)
Is the character a consonant?static boolean
isDerivedAdjective(String word)
Check the given word for derived adjectives like "magical" or "nomadic".static boolean
Check the given verb for gerund form, e.g.static boolean
isNormalized(String text)
Check if an expression is normalized.protected static boolean
isVowel(char c)
Is the character a vowel?static String
itthem(int quantity)
"it" or "them", depending on the quantity.static String
ItThem(int quantity)
"It" or "Them", depending on the quantity.static String
itthey(int quantity)
"it" or "they", depending on the quantity.static String
ItThey(int quantity)
"It" or "They", depending on the quantity.static String
makeUpperCaseWord(String word)
Modify a word to upper case notation.static Expression
mergeCompoundNoun(Expression word1, Expression word2)
Merge two expressions into a compound noun.static String
normalizeDerivedAdjective(String word)
Normalize the given derived adjective, or return null if not applicable.static Grammar.Verb
normalizeRegularVerb(String word)
Normalize the given regular verb, or return null if not applicable.static Integer
Interprets number texts.static String
numberString(int n)
Converts numbers into their textual representation.static String
ordered(int n)
first, second, third, ...static String
Returns either the plural or singular form of the given noun, depending on the quantity.static String
plnounCreature(int quantity, String noun)
Returns either the plural or singular form of the given noun, depending on the quantity.static String
Returns the plural form of the given noun if not already given in plural form.static String
pluralCreature(String noun)
Returns the plural form of the given noun if not already given in plural form.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.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.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.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.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.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.static String
To let the client display compound words like "#battle axe" in blue, we put the whole item name in quotes.static String
Replace internal item names bye their display name.static String
Returns the singular form of the given noun if not already given in singular form.static String
"[noun]'s" or "[noun]'", depending on the last character.static String
thatthose(int quantity)
"that" or "those", depending on the quantity.static String
ThatThose(int quantity)
"That or "Those", depending on the quantity.static String
thisthese(int quantity)
"this" or "these", depending on the quantity.static String
ThisThese(int quantity)
"This or "These", depending on the quantity.
-
Constructor Details
-
Grammar
public Grammar()
-
-
Method Details
-
get
-
itthem
"it" or "them", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "it" or "them" as appropriate
-
makeUpperCaseWord
Modify a word to upper case notation.- Parameters:
word
-- Returns:
- word with first letter in upper case
-
ItThem
"It" or "Them", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "It" or "Them" as appropriate
-
itthey
"it" or "they", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "it" or "they" as appropriate
-
ItThey
"It" or "They", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "It" or "They" as appropriate
-
isare
"is" or "are", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "is" or "are" as appropriate
-
IsAre
"Is" or "Are", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "Is" or "Are" as appropriate
-
hashave
"has" or "have", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "has" or "have" as appropriate
-
HasHave
"Has" or "Have", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "Has" or "Have" as appropriate
-
thatthose
"that" or "those", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "that" or "those" as appropriate
-
ThatThose
"That or "Those", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "That" or "Those" as appropriate
-
thisthese
"this" or "these", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "this" or "these" as appropriate
-
ThisThese
"This or "These", depending on the quantity.- Parameters:
quantity
- The quantity to examine- Returns:
- Either "This" or "These" as appropriate
-
article_noun
Prefixes a noun with an article.- Parameters:
noun
- noundefinite
- true for "the", false for a/an- Returns:
- noun with article
-
a_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
"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
Prefix a noun with an expression like "piece of".- Parameters:
noun
-- Returns:
- noun with prefix
-
replaceInternalByDisplayNames
Replace internal item names bye their display name.- Parameters:
str
-- Returns:
- fixed string
-
mergeCompoundNoun
Merge two expressions into a compound noun.- Parameters:
word1
-word2
-- Returns:
- resulting expression: word1 or word2
-
extractNoun
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
Check if an expression is normalized. equivalent to: {return extractNoun(text) == text}- Parameters:
text
-- Returns:
- true if the expression is already normalized
-
A_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
"[noun]'s" or "[noun]'", depending on the last character.- Parameters:
noun
- The noun to examine- Returns:
- Either "[noun]'s" or "[noun]'" as appropriate
-
plural
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
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
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
Returns either the plural or singular form of the given noun, depending on the quantity.- Parameters:
quantity
- The quantity to examinenoun
- The noun to examine- Returns:
- Either "[noun]" or plural("[noun]") as appropriate
-
plnounCreature
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 examinenoun
- The noun to examine- Returns:
- Either "[noun]" or plural("[noun]") as appropriate
-
quantityplnoun
Returns either the plural or singular form of the given noun, depending on the quantity; also prefixes the quantity.- Parameters:
quantity
- The quantity to examinenoun
- The noun to examine- Returns:
- Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
-
quantityplnounCreature
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 examinenoun
- The noun to examine- Returns:
- Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
-
quantityplnoun
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 examinenoun
- The noun to examineone
- replacement for "1".- Returns:
- Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
-
quantityplnounWithHash
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 examinenoun
- The noun to examine- Returns:
- Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
-
quantityplnounWithMarker
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 examinenoun
- The noun to examinemarker
- The character use for the markup. '#' or 'ยง'- Returns:
- Either "[quantity] [noun]" or "[quantity]" + plural("[noun]") as appropriate
-
quantityNumberStrNoun
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 examinenoun
- 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
first, second, third, ...- Parameters:
n
- a number- Returns:
- first, second, third, ...
-
enumerateCollection
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
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 enumeratedconjunction
- "and" or "or"- Returns:
- A nice String representation of the collection
-
enumerateCollectionWithHash
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
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
Converts numbers into their textual representation.- Parameters:
n
- a number- Returns:
- one, two, three, ...
-
number
Interprets number texts.- Parameters:
text
- a number- Returns:
- one, two, three, ...
-
normalizeRegularVerb
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
Check the given verb for gerund form, e.g. "doing".- Parameters:
word
-- Returns:
- true if gerund false otherwise
-
gerundForm
Return gerund form, e.g. "making" or "casting".- Parameters:
word
-- Returns:
- gerund form
-
isDerivedAdjective
Check the given word for derived adjectives like "magical" or "nomadic".- Parameters:
word
-- Returns:
- true if ends with "al", "ic" or "ed"
-
normalizeDerivedAdjective
Normalize the given derived adjective, or return null if not applicable.- Parameters:
word
-- Returns:
- normalized string
-
isAmbiguousNounVerb
Check for words with ambiguity between noun and verb.- Parameters:
normalized
- word in normalized form- Returns:
- ambiguity flag
-
enumerateCollectionPlural
enumerates a collections using the plural forms.- Parameters:
collection
- Collection- Returns:
- enumeration using plural forms
-