Package games.stendhal.common.parser

Examples of games.stendhal.common.parser.ExpressionMatcher


  }// GEN-LAST:event_cbMatchTypeActionPerformed

  private void updateMatching() {
    Object sel = cbMatchType.getSelectedItem();

    ExpressionMatcher selectedMatcher = null;
    boolean mergeExpressions = false;

    if (sel.equals("joker matching")) {
      selectedMatcher = new JokerExprMatcher();
    } else if (sel.equals("exact matching")) {
      selectedMatcher = new ExactExprMatcher();
    } else if (sel.equals("case insensitive")) {
      selectedMatcher = new CaseInsensitiveExprMatcher();
    } else if (sel.equals("similarity matching")) {
      selectedMatcher = new SimilarExprMatcher();
    } else if (sel.equals("controlled matching")) {
      selectedMatcher = null;
    } else if (sel.equals("merged expressions")) {
      selectedMatcher = new ExpressionMatcher();
      mergeExpressions = true;
//    } else if (sel.equals("type expression")) {
//      selectedMatcher = new TypeExprMatcher();
    }
View Full Code Here


  /**
   * Tests for similarMatching.
   */
  @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

*/
public class CaseInsensitiveExprMatcherTest {

  @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));
    assertFalse(matcher.match(e4, e5));
  }
View Full Code Here

*/
public class ExpressionMatcherTest {

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

    assertTrue(matcher.isEmpty());
    assertFalse(matcher.isAnyFlagSet());
  }
View Full Code Here

  /**
   * Tests for parsing.
   */
  @Test
  public final void testParsing() {
    final ExpressionMatcher matcher = new ExpressionMatcher();

    Sentence sentence = matcher.parseSentence("", new ConversationContext());
    assertFalse(sentence.hasError());
    assertEquals("", sentence.toString());

    String str = matcher.readMatchingFlags("Lazy dog");
    assertEquals("Lazy dog", str);
    assertTrue(matcher.isEmpty());
    assertEquals("", matcher.toString());

    sentence = matcher.parseSentence(str, new ConversationContext());
    assertFalse(sentence.hasError());
    assertEquals("lazy dog/SUB-ANI", sentence.toString());

    str = matcher.readMatchingFlags("|TYPE|abcdef/OBJ");
    assertEquals("abcdef/OBJ", str);
    assertTrue(matcher.isAnyFlagSet());
    assertFalse(matcher.getExactMatching());
    assertTrue(matcher.getTypeMatching());
    assertEquals("|TYPE", matcher.toString());

    sentence = matcher.parseSentence(str, new ConversationContext());
    assertFalse(sentence.hasError());
    assertEquals("|TYPE|abcdef/OBJ", sentence.toString());

    str = matcher.readMatchingFlags("|EXACT|Hello world!");
    assertEquals("Hello world!", str);
    assertTrue(matcher.isAnyFlagSet());
    assertTrue(matcher.getExactMatching());
    assertFalse(matcher.getTypeMatching());
    assertEquals("|EXACT", matcher.toString());

    sentence = matcher.parseSentence(str, new ConversationContext());
    assertFalse(sentence.hasError());
    assertEquals("|EXACT|Hello world!", sentence.toString());
  }
View Full Code Here

  /**
   * Tests for typeMatching.
   */
  @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));
    assertTrue(matcher.match(e1, e4));
    assertFalse(matcher.match(e1, e5));
    assertFalse(matcher.match(e4, e5));

    matcher.setTypeMatching(true);
    matcher.setExactMatching(false);
    assertTrue(matcher.match(e1, e2));
    assertFalse(matcher.match(e1, e3));
    assertFalse(matcher.match(e1, e4));
    assertFalse(matcher.match(e1, e5));
    assertFalse(matcher.match(e4, e5));

    matcher.setTypeMatching(true);
    matcher.setExactMatching(true);
    assertTrue(matcher.match(e1, e2));
    assertFalse(matcher.match(e1, e3));
    assertFalse(matcher.match(e1, e4));
    assertFalse(matcher.match(e1, e5));
    assertFalse(matcher.match(e4, e5));

    matcher.setTypeMatching(false);
    matcher.setExactMatching(true);
    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));
  }
View Full Code Here

  /**
   * Tests for exactMatching.
   */
  @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));
    assertFalse(matcher.match(abcSUB, X));
    assertFalse(matcher.match(abcVER, aBc));
  }
View Full Code Here

  /**
   * Tests for equals.
   */
  @Test
  public final void testEquals() {
    final ExpressionMatcher m1 = new ExpressionMatcher();
    final ExpressionMatcher m2 = new ExpressionMatcher();
    assertEquals(m1, m2);
    assertEquals(m1, m1);

    assertFalse(m1.equals(null));

    m1.setCaseInsensitive(true);
    assertFalse(m1.equals(m2));
    assertFalse(m2.equals(m1));

    assertEquals(m1, m1);

    m2.setCaseInsensitive(true);
    assertEquals(m1, m2);
  }
View Full Code Here

*/
public class JokerExprMatcherTest {

  @Test
  public final void testJokerMatching() {
    final ExpressionMatcher matcher = new JokerExprMatcher();

    final Expression e1 = new Expression("abc", "VER");
    final Expression e2 = new Expression("a*c", "VER");
    final Expression e3 = new Expression("ab", "VER");
    final Expression e4 = new Expression("ab*", "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));
  }
View Full Code Here

TOP

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

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.