Package games.stendhal.common.parser

Examples of games.stendhal.common.parser.WordList


  /**
   * Tests for prepositions.
   */
  @Test
  public final void testPrepositions() {
    final WordList wl = WordList.getInstance();

    WordEntry w = wl.find("with");
    assertNotNull(w);
    assertTrue(w.getType().isPreposition());
    assertEquals(ExpressionType.PREPOSITION, w.getTypeString());

    w = wl.find("on");
    assertNotNull(w);
    assertTrue(w.getType().isPreposition());
    assertEquals(ExpressionType.PREPOSITION, w.getTypeString());
  }
View Full Code Here


  /**
   * Tests for plural.
   */
  @Test
  public final void testPlural() {
    final WordList wl = WordList.getInstance();

    assertEquals("houses", wl.plural("house"));
    assertEquals("cookies", wl.plural("cookie"));
    assertEquals("cookies", wl.plural("cooky"));
  }
View Full Code Here

  /**
   * Tests for singular.
   */
  @Test
  public final void testSingular() {
    final WordList wl = WordList.getInstance();

    assertEquals("house", wl.singular("houses"));
    assertEquals("cookie", wl.singular("cookies"));
  }
View Full Code Here

  /**
   * Tests for WordEntry.print().
   */
  @Test
  public final void testPrintWord() {
    final WordList wl = WordList.getInstance();

    assertEquals("blue\tADJ-COL", printWord(wl, "blue"));
    assertEquals("with\tPRE", printWord(wl, "with"));
    assertEquals("mary\tSUB-NAM", printWord(wl, "mary"));
    assertEquals("doesn't\tVER-NEG  =do", printWord(wl, "doesn't"));
View Full Code Here

  /**
   * Tests for compound names.
   */
  @Test
  public final void testCompoundNames() {
    final WordList wl = WordList.getInstance();

    Sentence sentence = ConversationParser.parse("call Sherlock Holmes");
    assertFalse(sentence.hasError());
    assertEquals("call/VER sherlock/ holmes/SUB-NAM", sentence.toString());
    assertEquals(3, sentence.getExpressions().size());
    assertEquals("Holmes", sentence.getSubject(0).getOriginal());

    sentence = ConversationParser.parse("listen Elvis Presley");
    assertFalse(sentence.hasError());
    assertEquals("listen/VER elvis presley/", sentence.toString());
    assertEquals(2, sentence.getExpressions().size());
    assertNull("There should be no recognized subject.", sentence.getSubject(0));

    wl.registerSubjectName("Sherlock Holmes");
    wl.registerSubjectName("John Watson");
    wl.registerSubjectName("Professor Moriarty");
    wl.registerSubjectName("Baby Herman");
    wl.registerSubjectName("Lady Gaga");
    wl.registerSubjectName("Elvis Presley");

    sentence = ConversationParser.parse("call Sherlock Holmes");
    assertFalse(sentence.hasError());
    assertEquals("call/VER sherlock holmes/SUB-NAM-DYN", sentence.toString());
    assertEquals(2, sentence.getExpressions().size());
    assertEquals("Sherlock Holmes", sentence.getSubject(0).getOriginal());

    sentence = ConversationParser.parse("call John Watson");
    assertFalse(sentence.hasError());
    assertEquals("call/VER john watson/SUB-NAM-DYN", sentence.toString());
    assertEquals(2, sentence.getExpressions().size());
    assertEquals("John Watson", sentence.getSubject(0).getOriginal());

    sentence = ConversationParser.parse("call professor moriarty");
    assertFalse(sentence.hasError());
    assertEquals("call/VER professor moriarty/SUB-NAM-DYN", sentence.toString());
    assertEquals(2, sentence.getExpressions().size());
    assertEquals("professor moriarty", sentence.getSubject(0).getOriginal());

    sentence = ConversationParser.parse("look for baby Herman");
    assertFalse(sentence.hasError());
    assertEquals("look/VER for/PRE baby herman/SUB-NAM-DYN", sentence.toString());
    assertEquals(3, sentence.getExpressions().size());
    assertEquals("baby herman", sentence.getSubject(0).getNormalized());

    sentence = ConversationParser.parse("look for Lady Gaga");
    assertFalse(sentence.hasError());
    assertEquals("look/VER for/PRE lady gaga/SUB-NAM-DYN", sentence.toString());
    assertEquals(3, sentence.getExpressions().size());
    assertEquals("lady gaga", sentence.getSubject(0).getNormalized());

    sentence = ConversationParser.parse("listen Elvis Presley");
    assertFalse(sentence.hasError());
    assertEquals("listen/VER elvis presley/SUB-NAM-DYN", sentence.toString());
    assertEquals(2, sentence.getExpressions().size());
    assertEquals("elvis presley", sentence.getSubject(0).getNormalized());

    wl.unregisterSubjectName("Sherlock Holmes");
    wl.unregisterSubjectName("John Watson");
    wl.unregisterSubjectName("Professor Moriarty");
    wl.unregisterSubjectName("Baby Herman");
    wl.unregisterSubjectName("Lady Gaga");
    wl.unregisterSubjectName("Elvis Presley");
  }
View Full Code Here

  /**
   * Tests for compound names containing non-SUBject expressions.
   */
  @Test
  public final void testComplexCompoundNames() {
    final WordList wl = WordList.getInstance();

    Sentence sentence = ConversationParser.parse("catch Bugs Bunny");
    assertFalse(sentence.hasError());
    assertEquals("catch/VER bug bunny/OBJ-ANI", sentence.toString());
    assertEquals(2, sentence.getExpressions().size());
    assertNull("There should be no recognized subject.", sentence.getSubject(0));

    wl.registerSubjectName("Bugs Bunny");

    sentence = ConversationParser.parse("catch Bugs Bunny");
    assertFalse(sentence.hasError());
    assertEquals("catch/VER bugs bunny/SUB-NAM", sentence.toString());
    assertEquals(2, sentence.getExpressions().size());
    assertEquals("Bugs Bunny", sentence.getSubject(0).getOriginal());
    assertEquals("bugs bunny", sentence.getSubject(0).getNormalized());

    wl.unregisterSubjectName("Bugs Bunny");
  }
View Full Code Here

  /**
   * Compound names tests.
   */
  @Test
  public final void testCompoundNames() {
    WordList wl = WordList.getInstance();

    wl.registerName("ados city", ExpressionType.OBJECT);
    wl.registerName("ados city scroll", ExpressionType.OBJECT);

    Sentence sentence = ConversationParser.parse("I think this kobold npc up ados city");
    assertFalse(sentence.hasError());
    assertEquals(6, sentence.getExpressions().size());
    assertEquals("i/SUB-PRO think/VER this kobold/SUB-PRO npc/OBJ up/PRE ados city/OBJ", sentence.toString());

    CompoundName cn = wl.searchCompoundName(ConversationParser.parseAsMatchingSource("ados").expressions, 0);
    assertNull(cn);

    cn = wl.searchCompoundName(ConversationParser.parseAsMatchingSource("ados scroll").expressions, 0);
    assertNull(cn);

    cn = wl.searchCompoundName(ConversationParser.parseAsMatchingSource("ados city").expressions, 0);
    assertArrayEquals(new String[]{"ados","city"}, cn.toArray());
    assertNotNull(cn);

    cn = wl.searchCompoundName(ConversationParser.parseAsMatchingSource("ados city scroll").expressions, 0);
    assertArrayEquals(new String[]{"ados","city","scroll"}, cn.toArray());
    assertNotNull(cn);

    cn = wl.searchCompoundName(ConversationParser.parseAsMatchingSource("buy ados city scroll").expressions, 0);
    assertNull(cn);

    cn = wl.searchCompoundName(ConversationParser.parseAsMatchingSource("buy ados city scroll").expressions, 1);
    assertArrayEquals(new String[]{"ados","city","scroll"}, cn.toArray());
    assertNotNull(cn);
  }
View Full Code Here

*/
public class WordListTest {

  @Test
  public final void testNouns() {
    final WordList wl = WordList.getInstance();

    WordEntry w = wl.find("house");
    assertNotNull(w);
    assertTrue(w.getType().isObject());
    assertEquals(ExpressionType.OBJECT, w.getTypeString());
    assertFalse(w.isPlural());
    assertEquals("houses", w.getPlurSing());

    w = wl.find("man");
    assertNotNull(w);
    assertTrue(w.getType().isSubject());
    assertEquals(ExpressionType.SUBJECT, w.getTypeString());
    assertFalse(w.isPlural());
    assertEquals("men", w.getPlurSing());

    w = wl.find("men");
    assertNotNull(w);
    assertTrue(w.getType().isSubject());
    assertEquals(ExpressionType.SUBJECT+ExpressionType.SUFFIX+ExpressionType.PLURAL, w.getTypeString());
    assertTrue(w.isPlural());
    assertEquals("man", w.getPlurSing());

    w = wl.find("carrot");
    assertNotNull(w);
    assertTrue(w.getType().isObject());
    assertEquals(ExpressionType.OBJECT + ExpressionType.SUFFIX_FOOD, w.getTypeString());
    assertFalse(w.isPlural());
    assertEquals("carrots", w.getPlurSing());

    w = wl.find("carrots");
    assertNotNull(w);
    assertTrue(w.getType().isObject());
    assertEquals(ExpressionType.OBJECT + ExpressionType.SUFFIX_FOOD + ExpressionType.SUFFIX_PLURAL, w.getTypeString());
    assertTrue(w.isPlural());
    assertEquals("carrot", w.getPlurSing());

    w = wl.find("water");
    assertNotNull(w);
    assertTrue(w.getType().isObject());
    assertEquals(ExpressionType.OBJECT + ExpressionType.SUFFIX_FOOD + ExpressionType.SUFFIX_FLUID, w.getTypeString());
    assertEquals("waters", w.getPlurSing());

    w = wl.find("she");
    assertNotNull(w);
    assertTrue(w.getType().isSubject());
    assertEquals(ExpressionType.SUBJECT + ExpressionType.SUFFIX_PRONOUN, w.getTypeString());
    assertEquals("they", w.getPlurSing());
  }
View Full Code Here

  /**
   * Tests for verbs.
   */
  @Test
  public final void testVerbs() {
    final WordList wl = WordList.getInstance();

    WordEntry w = wl.find("say");
    assertNotNull(w);
    assertTrue(w.getType().isVerb());
    assertEquals(ExpressionType.VERB, w.getTypeString());

    w = wl.find("open");
    assertNotNull(w);
    assertTrue(w.getType().isVerb());
    assertEquals(ExpressionType.VERB, w.getTypeString());

    w = wl.find("are");
    assertNotNull(w);
    assertTrue(w.getType().isVerb());
    assertEquals(ExpressionType.VERB + ExpressionType.SUFFIX_PLURAL, w.getTypeString());
  }
View Full Code Here

  /**
   * Tests for adjectives.
   */
  @Test
  public final void testAdjectives() {
    final WordList wl = WordList.getInstance();

    WordEntry w = wl.find("white");
    assertNotNull(w);
    assertTrue(w.getType().isAdjective());
    assertEquals(ExpressionType.ADJECTIVE + ExpressionType.SUFFIX_COLOR, w.getTypeString());

    w = wl.find("silvery");
    assertNotNull(w);
    assertTrue(w.getType().isAdjective());
    assertEquals(ExpressionType.ADJECTIVE + ExpressionType.SUFFIX_COLOR, w.getTypeString());

    w = wl.find("nomadic");
    assertNotNull(w);
    assertTrue(w.getType().isAdjective());
    assertEquals(ExpressionType.ADJECTIVE, w.getTypeString());
  }
View Full Code Here

TOP

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

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.