Package games.stendhal.common.parser

Examples of games.stendhal.common.parser.Sentence


  /**
   * Test for findMatchingName().
   */
  @Test
  public final void testFindMatchingName() {
    Sentence sentence = ConversationParser.parse("i own two pigs, a cow and a horse.");
    assertFalse(sentence.hasError());
    assertEquals("i/SUB-PRO own/VER pig/OBJ-ANI-PLU, cow/OBJ-ANI, horse/SUB-ANI.", sentence.toString());

    Set<String> names = new HashSet<String>();
    names.add("pestle");
    names.add("mortar");
    names.add("cow");
    names.add("horse");
    NameSearch found = sentence.findMatchingName(names);
    assertTrue(found.found());
    assertEquals(1, found.getAmount());
    assertEquals("horse", found.getName());
  }
View Full Code Here


  /**
   * Test for findMatchingName() with plurals.
   */
  @Test
  public final void testFindMatchingNamePlural() {
    Sentence sentence = ConversationParser.parse("i own two pigs, a cow and a horse.");
    assertFalse(sentence.hasError());
    assertEquals("i/SUB-PRO own/VER pig/OBJ-ANI-PLU, cow/OBJ-ANI, horse/SUB-ANI.", sentence.toString());

    Set<String> names = new HashSet<String>();
    names.add("horses");
    NameSearch found = sentence.findMatchingName(names);
    assertTrue(found.found());
    assertEquals(1, found.getAmount());
    assertEquals("horses", found.getName());

    names = new HashSet<String>();
    names.add("pig");
    found = sentence.findMatchingName(names);
    assertTrue(found.found());
    assertEquals(2, found.getAmount());
    assertEquals("pig", found.getName());

    names = new HashSet<String>();
    names.add("pigs");
    found = sentence.findMatchingName(names);
    assertTrue(found.found());
    assertEquals(2, found.getAmount());
    assertEquals("pigs", found.getName());
  }
View Full Code Here

  /**
   * Tests for parseRequest.
   */
  @Test
  public void testParseRequest() {
    Sentence sentence = ConversationParser.parse("sell horse");
    assertFalse(sentence.hasError());

    Behaviour horseBeh = new Behaviour("horse");
    assertEquals(1, horseBeh.getItemNames().size());
    assertTrue(horseBeh.parse(sentence).wasFound());

View Full Code Here

  /**
   * Tests for parseNumbers.
   */
  @Test
  public void testParseRequestNumber() {
    Sentence sentence = ConversationParser.parse("50");
    assertFalse(sentence.hasError());

    Set<String> items = new HashSet<String>();
    items.add("gold");
    Behaviour beh = new Behaviour(items);
    ItemParserResult res = beh.parse(sentence);
View Full Code Here

      new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
          final String name = player.getQuest(QUEST_SLOT);
          final String quote = quotes.get(name);

          final Sentence answer = sentence.parseAsMatchingSource();
          final Sentence expected = ConversationParser.parse(quote, new SimilarExprMatcher());

          if (answer.matchesFull(expected)) {
            npc.say("Oh right, that's it! How could I forget this? Here, take this handy fishing rod as an acknowledgement of my gratitude!");
            final Item fishingRod = SingletonRepository.getEntityManager().getItem("fishing rod");
            fishingRod.setBoundTo(player.getName());
View Full Code Here

     * @param riddle The riddle to be answered
     * @param sentence The answer given by the player
     * @return <code>true</code> iff the answer is correct
     */
    public boolean matches(String riddle, Sentence sentence) {
      final Sentence answer = sentence.parseAsMatchingSource();

      // if the riddle is unknown, teleport the player out.
      // this can happen if the riddle was removed from the xml file
      // (or if the character is copied to a testserver with a different file)
      if (riddleMap.get(riddle) == null) {
        logger.warn("Accepting any answer for unknown riddle: " + riddle);
        return true;
      }
      for (String correct : riddleMap.get(riddle)) {
        final Sentence expected = ConversationParser.parse(correct, new SimilarExprMatcher());
        if (answer.matchesFull(expected)) {
          return true;
        }
      }

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.