Package games.stendhal.common.parser

Examples of games.stendhal.common.parser.Expression


    final SpeakerNPC barMaid = (SpeakerNPC) zone.getNPCList().get(0);
    assertThat(barMaid.getName(), is("Siandra"));
    final Engine engine = barMaid.getEngine();
    engine.setCurrentState(ConversationStates.IDLE);

    Sentence sentence = new SentenceImplementation(new Expression("hi", ExpressionType.VERB));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.ATTENDING));
    assertThat(getReply(barMaid), is("Hi!"));

    sentence = new SentenceImplementation(new Expression("bye", ExpressionType.VERB));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.IDLE));
    assertThat(getReply(barMaid), is("Bye bye!"));
  }
View Full Code Here


    final SpeakerNPC barMaid = (SpeakerNPC) zone.getNPCList().get(0);
    assertThat(barMaid.getName(), is("Siandra"));
    final Engine engine = barMaid.getEngine();
    engine.setCurrentState(ConversationStates.ATTENDING);

    Sentence sentence = new SentenceImplementation(new Expression("job", ExpressionType.VERB));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.ATTENDING));
    assertThat("job text", getReply(barMaid),
        is("I'm a bar maid. But we've run out of food to feed our customers, can you #offer any?"));

    sentence = new SentenceImplementation(new Expression("help", ExpressionType.VERB));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.ATTENDING));
    assertThat("help text", getReply(barMaid),
        is("If you could #offer any meat, ham or cheese to restock our larders I'd be grateful."));

    sentence = new SentenceImplementation(new Expression("quest", ExpressionType.VERB));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.ATTENDING));
    assertThat("quest text", getReply(barMaid), is("Just #offers of food is enough, thank you."));
  }
View Full Code Here

    final SpeakerNPC barMaid = (SpeakerNPC) zone.getNPCList().get(0);
    assertThat(barMaid.getName(), is("Siandra"));
    final Engine engine = barMaid.getEngine();
    engine.setCurrentState(ConversationStates.ATTENDING);

    Sentence sentence = new SentenceImplementation(new Expression("offer", ExpressionType.VERB));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.ATTENDING));
    assertThat("offer text", getReply(barMaid), equalTo("I buy pieces of cheese, pieces of meat, spinaches, pieces of ham, sacks of flour, and porcini."));

    final Expression sell = new Expression("sell", ExpressionType.VERB);

    sentence = new SentenceImplementation(sell);
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.ATTENDING));
    assertThat("offer text", getReply(barMaid), is("Please tell me what you want to sell."));

    sentence = new SentenceImplementation(sell, new Expression("cheese", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A piece of cheese is worth 5. Do you want to sell it?"));
    engine.setCurrentState(ConversationStates.ATTENDING);

    sentence = new SentenceImplementation(sell, new Expression("meat", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A piece of meat is worth 10. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    sentence = new SentenceImplementation(sell, new Expression("spinach", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A spinach is worth 15. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    sentence = new SentenceImplementation(sell, new Expression("ham", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A piece of ham is worth 20. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    sentence = new SentenceImplementation(sell, new Expression("flour", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A sack of flour is worth 25. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    sentence = new SentenceImplementation(sell, new Expression("porcini", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A porcino is worth 30. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    final Expression porcini = new Expression("porcini", ExpressionType.OBJECT);
    porcini.setAmount(2);
    sentence = new SentenceImplementation(sell, porcini);
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("2 porcini are worth 60. Do you want to sell them?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    final Expression flour = new Expression("flour", ExpressionType.OBJECT);
    flour.setAmount(2);
    sentence = new SentenceImplementation(sell, flour);
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("2 sacks of flour are worth 50. Do you want to sell them?"));
  }
View Full Code Here

    this.min = min;
    this.max = max;
  }

  public boolean fire(final Player player, final Sentence sentence, final Entity entity) {
    final Expression number = sentence.getNumeral();

    if (number != null) {
      final int num = number.getAmount();
      if ((num >= min) && (num <= max)) {
        return true;
      }
    }
    return false;
View Full Code Here

        List<Expression> expressions = sentence.getExpressions();
        String chosenName;
        int amount;

        if (expressions.size() == 1) {
        Expression expr = expressions.get(0);
        amount = expr.getAmount();
        chosenName = expr.getNormalized();
      } else {
        final Expression numeral = sentence.getNumeral();
          amount = numeral!=null? numeral.getAmount(): 1;
          chosenName = sentence.getExpressionStringAfterVerb();
      }

      return new ItemParserResult(false, chosenName, amount, null);
    }

    NameSearch search = sentence.findMatchingName(itemNames);

    boolean found = search.found();

    // Store found name.
    String chosenName = search.getName();
    int amount = search.getAmount();
    Set<String> mayBeItems = null;

    if (!found) {
      if ((sentence.getNumeralCount() == 1)
          && (sentence.getUnknownTypeCount() == 0)
          && (sentence.getObjectCount() == 0)) {
        final Expression number = sentence.getNumeral();

          // If there is given only a number, return this as amount.
            amount = number.getAmount();
        } else {
          // If there was no match, return the given object name instead
          // and set amount to 1.
            chosenName = sentence.getExpressionStringAfterVerb();
            amount = 1;
View Full Code Here

    String verb = sentence.getVerbString();
    tfVerb.setText(verb != null ? verb :
      "[" + sentence.getVerbCount() + " verbs]");

    Expression num = sentence.getNumeral();
    tfNumeral.setText(num != null ? num.getNormalized() :
      "[" + sentence.getNumeralCount() + " numerals]");

    String obj = sentence.getObjectName();
    tfObject.setText(obj != null ? obj :
      "[" + sentence.getObjectCount() + " objects]");
View Full Code Here

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

    final Expression e1 = new Expression("aBc", "VER");
    final Expression e2 = new Expression("abc", "VER");
    final Expression e3 = new Expression("ab", "VER");
    final Expression e4 = new Expression("abc", "SUB");
    final Expression e5 = new Expression("X", "SUB");
    assertTrue(matcher.match(e1, e2));
    assertFalse(matcher.match(e1, e3));
    assertTrue(matcher.match(e1, e4));
    assertFalse(matcher.match(e1, e5));
    assertFalse(matcher.match(e4, e5));

    final Expression e6 = new Expression("hello", "VER");
    final Expression e7 = new Expression("hallo", "VER");
    final Expression e8 = new Expression("hailo", "VER");
    assertTrue(matcher.match(e6, e7));
    assertFalse(matcher.match(e6, e8));
    assertTrue(matcher.match(e7, e8));
  }
View Full Code Here

  @Test
  public final void testCaseInsensitiveMatching() {
    final ExpressionMatcher matcher = new CaseInsensitiveExprMatcher();

    final Expression e1 = new Expression("aBc", "VER");
    final Expression e2 = new Expression("abc", "VER");
    final Expression e3 = new Expression("ab", "VER");
    final Expression e4 = new Expression("abc", "SUB");
    final Expression e5 = new Expression("X", "SUB");

    assertTrue(matcher.match(e1, e2));
    assertFalse(matcher.match(e1, e3));
    assertTrue(matcher.match(e1, e4));
    assertFalse(matcher.match(e1, e5));
View Full Code Here

      final String reply, final ChatAction action) {
    Collection<Expression> triggerExpressions = new ArrayList<Expression>();

    for(final String triggerString : triggerStrings) {
      // normalise trigger expressions using the conversation parser
      final Expression triggerExpression = ConversationParser.createTriggerExpression(triggerString, matcher);

      // look for already existing rule with identical input parameters
      final Transition existing = get(state, triggerExpression, condition);

      if (existing != null) {
View Full Code Here

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

    final Expression e1 = new Expression("abc", "VER");
    final Expression e2 = new Expression("abc", "VER");
    final Expression e3 = new Expression("ab", "VER");
    final Expression e4 = new Expression("abc", "SUB");
    final Expression e5 = new Expression("X", "SUB");

    matcher.setTypeMatching(false);
    matcher.setExactMatching(false);
    assertTrue(matcher.match(e1, e2));
    assertFalse(matcher.match(e1, e3));
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.