Package games.stendhal.common.parser
Class Sentence
java.lang.Object
games.stendhal.common.ErrorBuffer
games.stendhal.common.parser.Sentence
- All Implemented Interfaces:
ErrorDrain
,Iterable<Expression>
- Direct Known Subclasses:
SentenceImplementation
ConversationParser returns the parsed sentence in this class. The Sentence class stores the sentence content in a
list of parsed and classified expressions composed of the words forming the sentence. Words belonging to each other
are merged into common Expression objects.
- Author:
- Martin Fuchs
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected ConversationContext
protected AbstractList<Expression>
protected String
protected Sentence.SentenceType
Fields inherited from class games.stendhal.common.ErrorBuffer
errorBuffer
-
Constructor Summary
ModifierConstructorDescriptionprotected
Sentence(ConversationContext ctx)
Create a Sentence object. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
appendPunctation(SentenceBuilder builder)
Append the trailing punctuation depending on the sentence type to the given SentenceBuilder.diffNormalized(Sentence other)
Compare two sentences and return the difference as String.boolean
equalsNormalized(Sentence other)
Check if two Sentences consist of identical normalized Expressions.findMatchingName(Set<String> names)
Searches for a matching name in the given Set.getExpression(int idx, String typePrefix)
Return verb [i] of the sentence.Return the list of expressions.protected Expression[]
Return an array of the expressions.Return a string containing the sentence part referenced by a verb or simply the single object name.Return the expression matcher of the first expression.Return the sentence with all words normalized.Return the single numeral of the parsed sentence.getNumeral(int i)
Return numeral [i] of the parsed sentence.int
Return the number of number Expressions.getObject(int i)
Return object [i] of the parsed sentence (e.g.int
Return the number of objects.Return the object as String for the special case of sentences with only one object.getObjectName(int i)
Return object name [i] of the parsed sentence.Return the original parsed text of the sentence.getPreposition(int i)
Return the preposition [i] of the parsed sentence.int
Return the number of prepositions.getSubject(int i)
Return subject [i] of the sentence.int
Return the number of subjects.Return the subject as String for the special case of sentences with only one subject.Return trigger Expression for the FSM engine.Return the complete text of the sentence with unchanged case, but with trimmed white space.getType()
int
Count the number of Expressions with unknown type.getUnknownTypeExpression(int idx)
Return unknown word [i] of the sentence.getVerb()
Return verb as Expression object for the special case of sentences with only one verb.getVerb(int i)
Return verb [i] of the sentence.int
Return the number of Expression objects of type "VER" in the sentence.Return verb as String for the special case of sentences with only one verb.boolean
isEmpty()
Return true if the sentence is empty.protected boolean
isIgnorable(Expression expr)
Check if the given Expression should be ignored.iterator()
Return an iterator over all expressions.boolean
matchesFull(Sentence other)
Check if the Sentence completely matches the given Sentence.boolean
matchesNormalized(String text)
Check if the Sentence matches the given String.boolean
matchesNormalizedStart(String text)
Check if the Sentence beginning matches the given String.boolean
matchesStart(Sentence other)
Check if the Sentence start matches the given Sentence.boolean
matchesStartNormalized(String text)
Check if the Sentence matches the beginning of the given String.nextValid(Iterator<Expression> it)
Advance the iterator and return the next non-ignorable Expression.parse(ConversationContext ctx)
Parse the sentence again, using the given conversation context.Return a parsed sentence object to be used as source in matching.toString()
Return the full sentence as lower case string including type specifiers.Methods inherited from class games.stendhal.common.ErrorBuffer
getErrorString, hasError, setError
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
originalText
-
context
-
sentenceType
-
expressions
-
-
Constructor Details
-
Sentence
Create a Sentence object.- Parameters:
ctx
-
-
-
Method Details
-
getType
- Returns:
- sentence type.
-
getExpressions
Return the list of expressions.- Returns:
- Expression iterator
-
getExpressionsArrayList
Return an array of the expressions.- Returns:
- Expression array
-
iterator
Return an iterator over all expressions.- Specified by:
iterator
in interfaceIterable<Expression>
- Returns:
- Expression iterator
-
getExpression
Return verb [i] of the sentence.- Parameters:
idx
-typePrefix
-- Returns:
- verb
-
getUnknownTypeCount
public int getUnknownTypeCount()Count the number of Expressions with unknown type.- Returns:
- number of Expressions with unknown type
-
getUnknownTypeExpression
Return unknown word [i] of the sentence.- Parameters:
idx
-- Returns:
- Expression with unknown type
-
getTriggerExpression
Return trigger Expression for the FSM engine. TODO mf - replace by sentence matching.- Returns:
- trigger string
-
getVerbCount
public int getVerbCount()Return the number of Expression objects of type "VER" in the sentence.- Returns:
- number of subjects
-
getVerb
Return verb [i] of the sentence.- Parameters:
i
-- Returns:
- subject
-
getVerb
Return verb as Expression object for the special case of sentences with only one verb.- Returns:
- normalized verb string
-
getVerbString
Return verb as String for the special case of sentences with only one verb.- Returns:
- normalized verb string
-
getSubjectCount
public int getSubjectCount()Return the number of subjects.- Returns:
- number of subjects
-
getSubject
Return subject [i] of the sentence.- Parameters:
i
-- Returns:
- subject
-
getSubjectName
Return the subject as String for the special case of sentences with only one subject.- Returns:
- normalized subject string
-
getObjectCount
public int getObjectCount()Return the number of objects.- Returns:
- number of objects
-
getObject
Return object [i] of the parsed sentence (e.g. item to be bought).- Parameters:
i
-- Returns:
- object
-
getObjectName
Return the object as String for the special case of sentences with only one object.- Returns:
- normalized object name
-
getObjectName
Return object name [i] of the parsed sentence.- Parameters:
i
-- Returns:
- normalized object name
-
getPrepositionCount
public int getPrepositionCount()Return the number of prepositions.- Returns:
- number of objects
-
getPreposition
Return the preposition [i] of the parsed sentence.- Parameters:
i
-- Returns:
- object
-
getNumeralCount
public int getNumeralCount()Return the number of number Expressions.- Returns:
- number of number Expressions
-
getNumeral
Return numeral [i] of the parsed sentence.- Parameters:
i
-- Returns:
- numeral
-
getNumeral
Return the single numeral of the parsed sentence.- Returns:
- numeral
-
isEmpty
public boolean isEmpty()Return true if the sentence is empty.- Returns:
- empty flag
-
getTrimmedText
Return the complete text of the sentence with unchanged case, but with trimmed white space. There should be only as few code places as possible to rely on this method.- Returns:
- string
-
getOriginalText
Return the original parsed text of the sentence. Leading and trailing white space is already trimmed. deprecate: There should be only as few code places as possible to rely on this method.- Returns:
- string
-
getNormalized
Return the sentence with all words normalized.- Returns:
- string
-
getMatcher
Return the expression matcher of the first expression.- Returns:
- expression matcher
-
parse
Parse the sentence again, using the given conversation context.- Parameters:
ctx
-- Returns:
- parsed Sentence
-
parseAsMatchingSource
Return a parsed sentence object to be used as source in matching.- Returns:
- parsed for matching as source Sentence
-
isIgnorable
Check if the given Expression should be ignored.- Parameters:
expr
-- Returns:
- true, if the expression should be ignored
-
toString
Return the full sentence as lower case string including type specifiers. -
appendPunctation
Append the trailing punctuation depending on the sentence type to the given SentenceBuilder.- Parameters:
builder
-
-
equalsNormalized
Check if two Sentences consist of identical normalized Expressions.- Parameters:
other
-- Returns:
- true if so
-
diffNormalized
Compare two sentences and return the difference as String.- Parameters:
other
-- Returns:
- difference String
-
nextValid
Advance the iterator and return the next non-ignorable Expression.- Parameters:
it
-- Returns:
- the next non-ignorable Expression
-
matchesNormalized
Check if the Sentence matches the given String. The match Sentence can contain explicit expressions, which are compared after normalizing, or ExpressionType specifiers like "VER" or "SUB*" in upper case.- Parameters:
text
-- Returns:
- true if it matches.
-
matchesNormalizedStart
Check if the Sentence beginning matches the given String. The match Sentence can contain explicit expressions, which are compared after normalizing, or ExpressionType specifiers like "VER" or "SUB*" in upper case.- Parameters:
text
-- Returns:
- true, if the text matches
-
matchesStartNormalized
Check if the Sentence matches the beginning of the given String. The match Sentence can contain explicit expressions, which are compared after normalizing, or ExpressionType specifiers like "VER" or "SUB*" in upper case.- Parameters:
text
-- Returns:
- true, if the text matches
-
matchesFull
Check if the Sentence completely matches the given Sentence. The match Sentence can contain explicit expressions, which are compared after normalizing, or ExpressionType specifiers like "VER" or "SUB*" in upper case.- Parameters:
other
-- Returns:
- true, if the complete sentence matches
-
matchesStart
Check if the Sentence start matches the given Sentence. The match Sentence can contain explicit expressions, which are compared after normalizing, or ExpressionType specifiers like "VER" or "SUB*" in upper case.- Parameters:
other
-- Returns:
- true, if the start sentence start matches
-
findMatchingName
Searches for a matching name in the given Set.- Parameters:
names
-- Returns:
- name, or null if no match
-
getExpressionStringAfterVerb
Return a string containing the sentence part referenced by a verb or simply the single object name.- Returns:
- String or null if nothing found
-