Package games.stendhal.common.parser

Examples of games.stendhal.common.parser.SentenceImplementation


    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

    assertEquals(0, sentence.getObjectCount());
    assertNull(sentence.getObject(0));
    assertNull(sentence.getObjectName());
    assertFalse(sentence.hasError());

    SentenceImplementation impl = new SentenceImplementation(null, null);
    ConversationParser parser = new ConversationParser(impl);
    impl.parse(parser);
    assertNotNull(impl);
    assertEquals(0, impl.getSubjectCount());
    assertNull(impl.getSubject(0));
    assertEquals(0, impl.getVerbCount());
    assertNull(impl.getVerb(0));
    assertEquals(0, impl.getObjectCount());
    assertNull(impl.getObject(0));
    assertNull(impl.getObjectName());
    assertFalse(impl.hasError());
  }
View Full Code Here

   */
  @Test
  public final void testGrammar() {
    final ConversationContext ctx = new ConversationContext();

    SentenceImplementation sentence = new SentenceImplementation(ctx, "The quick brown fox jumps over the lazy dog.");
    ConversationParser parser = new ConversationParser(sentence);
    sentence.parse(parser);
    sentence.classifyWords(parser);
    assertFalse(sentence.hasError());
    assertEquals("quick/ADJ brown/ADJ-COL fox/SUB-ANI jump/VER over/PRE lazy/ADJ dog/SUB-ANI.",
        sentence.toString());

    sentence.mergeWords();
    assertEquals("quick brown fox/SUB-ANI-COL jump/VER over/PRE lazy dog/SUB-ANI.", sentence.toString());
    assertEquals(Sentence.SentenceType.STATEMENT, sentence.getType());

    sentence = new SentenceImplementation(ctx, "does it fit");
    parser = new ConversationParser(sentence);
    sentence.parse(parser);
    sentence.classifyWords(parser);
    assertFalse(sentence.hasError());
    assertEquals("do/VER it/OBJ-PRO fit/VER", sentence.toString());
    assertEquals(Sentence.SentenceType.QUESTION, sentence.evaluateSentenceType());
    assertEquals("it/OBJ-PRO fit/VER?", sentence.toString());
  }
View Full Code Here

   * Tests for withoutParser.
   */
  @Test
  public final void testWithoutParser() {
    final Expression expr = new Expression("hello", "VER");
    final Sentence sentence = new SentenceImplementation(expr);

    assertTrue(sentence.matchesFull(sentence));
  }
View Full Code Here

TOP

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

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.