Class ConversationParser

java.lang.Object
games.stendhal.common.ErrorBuffer
games.stendhal.common.parser.ConversationParser
All Implemented Interfaces:
ErrorDrain

public final class ConversationParser extends ErrorBuffer
Parser for conversations with a SpeakerNPC This class parses strings in English language and returns them as Sentence objects. All sentence constituents are in lower case.
Author:
Martin Fuchs
  • Constructor Details

    • ConversationParser

      protected ConversationParser(SentenceImplementation sentence)
      Create a new conversation parser and initialise with the given sentence.
      Parameters:
      sentence -
  • Method Details

    • normalize

      public static String normalize(String text)
      Parameters:
      text -
      Returns:
      the sentence in normalized form.
    • createTriggerExpression

      public static Expression createTriggerExpression(String text)
      Create trigger expression to match the parsed user input in the FSM engine.
      Parameters:
      text -
      Returns:
      Expression
    • createTriggerExpression

      public static Expression createTriggerExpression(String text, ExpressionMatcher matcher)
      Create trigger expression to match the parsed user input in the FSM engine.
      Parameters:
      text -
      matcher -
      Returns:
      Expression
    • parse

      public static Sentence parse(String text)
      Parse function without conversation context.
      Parameters:
      text -
      Returns:
      the parsed text
    • parseAsMatchingSource

      public static Sentence parseAsMatchingSource(String text)
      Parse the given text sentence to be used as matching source.
      Parameters:
      text -
      Returns:
      the parsed text
    • parseAsMatcher

      public static Sentence parseAsMatcher(String text)
      Parse the given text sentence to be used for sentence matching.
      Parameters:
      text -
      Returns:
      the parsed text
    • parse

      public static Sentence parse(String text, ExpressionMatcher matcher)
      Parse the given text sentence using an explicit Expression matcher.
      Parameters:
      text -
      matcher -
      Returns:
      the parsed text
    • parse

      public static Sentence parse(String text, ConversationContext ctx, ExpressionMatcher matcher)
      Parse the given text sentence using an ConversationContext and an explicit Expression matcher.
      Parameters:
      text -
      ctx -
      matcher -
      Returns:
      the parsed text
    • parse

      public static Sentence parse(String text, ConversationContext ctx)
      Parse the given text sentence.
      Parameters:
      text -
      ctx -
      Returns:
      the parsed text
    • readNextWord

      public String readNextWord()
      Read the next word from the parsed sentence.
      Returns:
      word string
    • detectSentenceType

      public static String detectSentenceType(String text, Sentence sentence)
      Evaluates and sets sentence type by looking at the trailing punctuation characters.
      Parameters:
      text - the text to evaluate
      sentence - where the type is to be set
      Returns:
      text without trailing or leading punctuation