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
Nested ClassesModifier and TypeClassDescriptionstatic classReturn type for normalizedRegularVerb(). -
Constructor Summary
Constructors -
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 Stringa_nounCreature(String noun) "a [noun]" or "an [noun]", depending on the first syllable.static Stringarticle_noun(String noun, boolean definite) Prefixes a noun with an article.static StringenumerateCollection(Collection<String> collection) Helper function to nicely formulate an enumeration of a collection.static StringenumerateCollection(Collection<String> collection, String conjunction) Helper function to nicely formulate an enumeration of a collection.static StringenumerateCollectionPlural(Collection<String> collection) enumerates a collections using the plural forms.static StringenumerateCollectionWithHash(Collection<String> collection) Helper function to nicely formulate an enumeration of a collection, with hashes to colour the words.static StringextractNoun(String text) Extracts noun from a string, that may be prefixed with a plural expression like "piece of", ...static StringPrefix a noun with an expression like "piece of".static StringgerundForm(String word) Return gerund form, e.g.static Grammarget()static Stringhashave(int quantity) "has" or "have", depending on the quantity.static StringHasHave(int quantity) "Has" or "Have", depending on the quantity.static booleanisAmbiguousNounVerb(String normalized) Check for words with ambiguity between noun and verb.static Stringisare(int quantity) "is" or "are", depending on the quantity.static StringIsAre(int quantity) "Is" or "Are", depending on the quantity.protected static booleanisConsonant(char c) Is the character a consonant?static booleanisDerivedAdjective(String word) Check the given word for derived adjectives like "magical" or "nomadic".static booleanCheck the given verb for gerund form, e.g.static booleanisNormalized(String text) Check if an expression is normalized.protected static booleanisVowel(char c) Is the character a vowel?static Stringitthem(int quantity) "it" or "them", depending on the quantity.static StringItThem(int quantity) "It" or "Them", depending on the quantity.static Stringitthey(int quantity) "it" or "they", depending on the quantity.static StringItThey(int quantity) "It" or "They", depending on the quantity.static StringmakeUpperCaseWord(String word) Modify a word to upper case notation.static ExpressionmergeCompoundNoun(Expression word1, Expression word2) Merge two expressions into a compound noun.static StringNormalize the given derived adjective, or return null if not applicable.static Grammar.VerbnormalizeRegularVerb(String word) Normalize the given regular verb, or return null if not applicable.static IntegerInterprets number texts.static StringnumberString(int n) Converts numbers into their textual representation.static Stringordered(int n) first, second, third, ...static StringReturns either the plural or singular form of the given noun, depending on the quantity.static StringplnounCreature(int quantity, String noun) Returns either the plural or singular form of the given noun, depending on the quantity.static StringReturns the plural form of the given noun if not already given in plural form.static StringpluralCreature(String noun) Returns the plural form of the given noun if not already given in plural form.static StringquantityNumberStrNoun(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 Stringquantityplnoun(int quantity, String noun) Returns either the plural or singular form of the given noun, depending on the quantity; also prefixes the quantity.static Stringquantityplnoun(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 StringquantityplnounCreature(int quantity, String noun) Returns either the plural or singular form of the given noun, depending on the quantity; also prefixes the quantity.static StringquantityplnounWithHash(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 StringquantityplnounWithMarker(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 StringTo let the client display compound words like "#battle axe" in blue, we put the whole item name in quotes.static StringReplace internal item names bye their display name.static StringReturns 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 Stringthatthose(int quantity) "that" or "those", depending on the quantity.static StringThatThose(int quantity) "That or "Those", depending on the quantity.static Stringthisthese(int quantity) "this" or "these", depending on the quantity.static StringThisThese(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
-