Package games.stendhal.common.parser

Examples of games.stendhal.common.parser.Expression


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

    final Expression abcVER = new Expression("abc", "VER");
    final Expression abcVERCopy = new Expression("abc", "VER");
    final Expression ab = new Expression("ab", "VER");
    final Expression abcSUB = new Expression("abc", "SUB");
    final Expression X = new Expression("X", "SUB");
    final Expression aBc = new Expression("aBc", "SUB");

    assertTrue(matcher.match(abcVER, abcVERCopy));
    assertFalse(matcher.match(abcVER, ab));
    assertTrue(matcher.match(abcVER, abcSUB));
    assertFalse(matcher.match(abcVER, X));
View Full Code Here


    for(final String itemName : NEEDED_CLOAKS) {
      npc.add(ConversationStates.QUEST_OFFERED, itemName, null,
        ConversationStates.QUEST_OFFERED, null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
            Expression obj = sentence.getObject(0);
            if (obj!=null && !obj.getNormalized().equals(itemName)) {
              raiser.say("I don't know " + obj.getOriginal() + ". Can you name me another cloak please?");
            } else {
              final Item item = SingletonRepository.getEntityManager().getItem(itemName);
              StringBuilder stringBuilder = new StringBuilder();
              stringBuilder.append("You haven't seen one before? Well, it's a ");
View Full Code Here

  protected Integer getOfferNumberFromSentence(Sentence sentence) {
    final SimilarExprMatcher matcher = new SimilarExprMatcher();
    final int last = sentence.getExpressions().size();
 
    for (Expression expr : sentence.getExpressions().subList(1, last)) {
      if (matcher.match(expr, new Expression("number", "NUM"))) {
        /*
         * The player wrote either "command number", "command number <number>",
         * or something along those lines. Ignore the "number" parts until
         * we get to the actual numeral.
         */
 
View Full Code Here

  @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

  @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

    assertTrue(object.isObject());
  }

  @Test
  public final void testMatch() {
    final Expression expr1 = ConversationParser.createTriggerExpression("cloak");
    final Expression expr2 = ConversationParser.createTriggerExpression("cloaks");
    final Expression expr3 = ConversationParser.createTriggerExpression("trousers");

    assertEquals("cloak", expr1.toString());
    assertEquals("|TYPE|cloak", expr2.toString());
    assertEquals("|TYPE|trouser", expr3.toString());

    assertTrue(expr1.matches(expr1));
    assertFalse(expr1.matches(expr2));
    assertFalse(expr1.matches(expr3));

    assertFalse(expr1.matchesNormalized(expr2));
    assertTrue(expr2.matchesNormalized(expr1));
    assertFalse(expr1.matchesNormalized(expr3));
    assertFalse(expr3.matchesNormalized(expr1));

    assertFalse(expr1.matchesNormalizedSimilar(expr2));
    assertTrue(expr2.matchesNormalizedSimilar(expr1));
    assertFalse(expr1.matchesNormalizedSimilar(expr3));
    assertFalse(expr3.matchesNormalizedSimilar(expr1));
  }
View Full Code Here

  /**
   * Tests for equals.
   */
  @Test
  public final void testEquals() {
    final Expression exp = new Expression("blabla");

    // compare with the same object
    assertTrue(exp.equals(exp));

    // check equals() with null parameter
    assertFalse(exp.equals(null));

    // negative equal() tests
    assertFalse(exp.equals("blabla"));

    Object x = "abc";
    Object y = new Expression("abc");
    assertFalse(y.equals(x));
    assertFalse(x.equals(y));

    assertFalse("should not break equals contract", "blabla".equals(exp));

    // positive equals() test
    x = new Expression("abc");
    y = new Expression("abc");
    assertTrue(y.equals(x));
    assertTrue(x.equals(y));
  }
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

  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

  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.Expression

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.