Package games.stendhal.common.parser

Examples of games.stendhal.common.parser.Sentence


   *
   * @return <code>true</code> if the user can use the portal.
   */
  @Override
  protected boolean isAllowed(final RPEntity user) {
    Sentence sentence = ConversationParser.parse(user.get("text"));
    if (condition != null) {
      return condition.fire((Player) user, sentence, this);
    }
    return true;
  }
View Full Code Here


  /**
   * Tests for sentenceMatching.
   */
  @Test
  public final void testSentenceMatching() {
    Sentence m1 = ConversationParser.parseAsMatcher("|ICASE|hello");
    assertFalse(m1.hasError());
    assertEquals("|ICASE|hello", m1.toString());

    assertEquals(true, ConversationParser.parse("hello").matchesFull(m1));
    assertEquals(true, ConversationParser.parse("hallo").matchesFull(m1));
    assertEquals(false, ConversationParser.parse("hailo").matchesFull(m1));

    m1 = ConversationParser.parseAsMatcher("|EXACT|ICASE|hello");
    assertFalse(m1.hasError());
    assertEquals("|EXACT|ICASE|hello", m1.toString());

    assertEquals(true, ConversationParser.parse("hello").matchesFull(m1));
    assertEquals(false, ConversationParser.parse("hallo").matchesFull(m1));
    assertEquals(false, ConversationParser.parse("hailo").matchesFull(m1));
  }
View Full Code Here

   * @param text
   *            input
   * @return true if a transition was made, false otherwise
   */
  public boolean step(final Player player, final String text) {
    final Sentence sentence = ConversationParser.parse(text);

    if (sentence.hasError()) {
      logger.warn("problem parsing the sentence '" + text + "': "
          + sentence.getErrorString());
    }

    return step(player, sentence);
  }
View Full Code Here

   */
  public boolean stepTest(final Player player, final String text) {
    logger.debug(">>> " + text);
    speakerNPC.remove("text");

    final Sentence sentence = ConversationParser.parse(text);

    if (sentence.hasError()) {
      logger.warn("problem parsing the sentence '" + text + "': "
          + sentence.getErrorString());
    }

    final boolean res = step(player, sentence);

    logger.debug("<<< " + speakerNPC.get("text"));
View Full Code Here

   */
  @Test
  public final void testParsing() {
    final ExpressionMatcher matcher = new ExpressionMatcher();

    Sentence sentence = matcher.parseSentence("", new ConversationContext());
    assertFalse(sentence.hasError());
    assertEquals("", sentence.toString());

    String str = matcher.readMatchingFlags("Lazy dog");
    assertEquals("Lazy dog", str);
    assertTrue(matcher.isEmpty());
    assertEquals("", matcher.toString());

    sentence = matcher.parseSentence(str, new ConversationContext());
    assertFalse(sentence.hasError());
    assertEquals("lazy dog/SUB-ANI", sentence.toString());

    str = matcher.readMatchingFlags("|TYPE|abcdef/OBJ");
    assertEquals("abcdef/OBJ", str);
    assertTrue(matcher.isAnyFlagSet());
    assertFalse(matcher.getExactMatching());
    assertTrue(matcher.getTypeMatching());
    assertEquals("|TYPE", matcher.toString());

    sentence = matcher.parseSentence(str, new ConversationContext());
    assertFalse(sentence.hasError());
    assertEquals("|TYPE|abcdef/OBJ", sentence.toString());

    str = matcher.readMatchingFlags("|EXACT|Hello world!");
    assertEquals("Hello world!", str);
    assertTrue(matcher.isAnyFlagSet());
    assertTrue(matcher.getExactMatching());
    assertFalse(matcher.getTypeMatching());
    assertEquals("|EXACT", matcher.toString());

    sentence = matcher.parseSentence(str, new ConversationContext());
    assertFalse(sentence.hasError());
    assertEquals("|EXACT|Hello world!", sentence.toString());
  }
View Full Code Here

*/
public class ExpressionTest {

  @Test
  public final void testAmount() {
    Sentence sentence = ConversationParser.parse("buy 15 bananas");
    assertFalse(sentence.hasError());
    Expression verb = sentence.getVerb();
    assertEquals("buy", verb.getNormalized());
    Expression object = sentence.getObject(0);
    assertEquals(15, object.getAmount());
    assertEquals(15, object.getAmountLong());

    sentence = ConversationParser.parse("sell banana");
    assertFalse(sentence.hasError());
    assertEquals("sell", sentence.getVerbString());
    object = sentence.getObject(0);
    assertEquals(1, object.getAmount());
    assertEquals(1, object.getAmountLong());
  }
View Full Code Here

    assertEquals(1, object.getAmountLong());
  }

  @Test
  public final void testTypes() {
    Sentence sentence = ConversationParser.parse("sally, please buy 5 bananas");
    assertFalse(sentence.hasError());

    Expression verb = sentence.getVerb();
    assertEquals("buy", verb.getNormalized());
    assertTrue(verb.isVerb());
    assertFalse(verb.isObject());
    assertFalse(verb.isSubject());

    Expression subject = sentence.getSubject(0);
    assertTrue(subject.isSubject());
    assertFalse(subject.isVerb());
    Expression object = sentence.getObject(0);
    assertTrue(object.isObject());
  }
View Full Code Here

  /**
   * Tests for triggerMatching.
   */
  @Test
  public final void testTriggerMatching() {
    final Sentence s1 = ConversationParser.parse("spade");
    final Expression e1 = s1.getTriggerExpression();
    final Sentence s2 = ConversationParser.parse("a spade");
    final Expression e2 = s2.getTriggerExpression();
    assertFalse(s1.hasError());
    assertFalse(s2.hasError());
    assertTrue(e1.matchesNormalized(e2));
    assertTrue(e2.matchesNormalized(e1));
  }
View Full Code Here

   * Tests for typeTriggerMatching.
   */
  @Test
  public final void testTypeTriggerMatching() {
    // First show, that "do" without the exactMatching flag matches "done".
    Sentence m1 = ConversationParser.parseAsMatcher("done");
    assertFalse(m1.hasError());
    assertEquals("do/VER-PAS", m1.toString());
    Expression e1 = m1.getTriggerExpression();

    Sentence s = ConversationParser.parse("do");
    assertFalse(s.hasError());
    Expression e2 = s.getTriggerExpression();
    assertTrue(e2.matchesNormalized(e1));
    assertEquals("do/VER", s.toString());

    // Using the typeMatching flag, it doesn't match any more...
    m1 = ConversationParser.parseAsMatcher("|TYPE|done/VER-PAS");
    assertFalse(m1.hasError());
    assertEquals("|TYPE|done/VER-PAS", m1.toString());
    e1 = m1.getTriggerExpression();

    assertFalse(e2.matches(e1));
    assertFalse(e2.matchesNormalized(e1));

    // ...but "done" matches the given type string pattern.
    s = ConversationParser.parse("done");
    assertFalse(s.hasError());
    assertEquals("do/VER-PAS", s.toString());
    e2 = s.getTriggerExpression();
    assertTrue(e2.matches(e1));
    assertTrue(e2.matchesNormalized(e1));
  }
View Full Code Here

   * Tests for exactTriggerMatching.
   */
  @Test
  public final void testExactTriggerMatching() {
    // First show, that "do" without the exactMatching flag matches "done".
    Sentence m1 = ConversationParser.parseAsMatcher("done");
    assertFalse(m1.hasError());
    assertEquals("do/VER-PAS", m1.toString());
    Expression e1 = m1.getTriggerExpression();

    Sentence s = ConversationParser.parse("do");
    assertFalse(s.hasError());
    Expression e2 = s.getTriggerExpression();
    assertTrue(e2.matchesNormalized(e1));
    assertEquals("do/VER", s.toString());

    // Using the exactMatching flag, it doesn't match any more...
    m1 = ConversationParser.parseAsMatcher("|EXACT|dONe");
    assertFalse(m1.hasError());
    assertEquals("|EXACT|dONe", m1.toString());
    e1 = m1.getTriggerExpression();

    assertFalse(e2.matches(e1));
    assertFalse(e2.matchesNormalized(e1));

    // ...but "done" matches the given exact matching pattern.
    s = ConversationParser.parse("dONe");
    assertFalse(s.hasError());
    assertEquals("do/VER-PAS", s.toString());
    e2 = s.getTriggerExpression();
    assertTrue(e2.matches(e1));
    assertTrue(e2.matchesNormalized(e1));
  }
View Full Code Here

TOP

Related Classes of games.stendhal.common.parser.Sentence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.