Ejemplo n.º 1
0
 @Test
 public void ComplexRegex() {
   Template t = new Template("a (pizza)? margherita");
   assertTrue(t.match("a margherita").isMatching());
   assertTrue(t.match("a pizza margherita").isMatching());
   assertFalse(t.match("a pizza").isMatching());
   assertTrue(t.partialmatch("I would like a margherita").isMatching());
   Template t2 = new Template("a (bottle of)? (beer|wine)");
   assertTrue(t2.match("a beer").isMatching());
   assertTrue(t2.match("a bottle of wine").isMatching());
   assertFalse(t2.match("a bottle of").isMatching());
   assertFalse(t2.match("a coke").isMatching());
   assertTrue(t2.partialmatch("I would like a bottle of beer").isMatching());
   Template t3 = new Template("move (a (little)? bit)? (to the)? left");
   assertTrue(t3.match("move a little bit to the left").isMatching());
   assertTrue(t3.match("move a bit to the left").isMatching());
   assertTrue(t3.match("move to the left").isMatching());
   assertTrue(t3.match("move a little bit left").isMatching());
   assertFalse(t3.match("move a to the left").isMatching());
   Template t4 = new Template("I want beer(s)?");
   assertTrue(t4.match("I want beer").isMatching());
   assertTrue(t4.match("I want beers").isMatching());
   assertFalse(t4.match("I want beer s").isMatching());
   Template t5 = new Template("(beer(s)?|wine)");
   assertTrue(t5.match("beer").isMatching());
   assertTrue(t5.match("beers").isMatching());
   assertTrue(t5.match("wine").isMatching());
   assertFalse(t5.match("wines").isMatching());
   assertFalse(t5.match("beer wine").isMatching());
   assertTrue(
       new Template("* (to the|at the)? left of").match("window to the left of").isMatching());
   assertTrue(new Template("* (to the|at the)? left of").match("window left of").isMatching());
   assertTrue(new Template("* (to the|at the)? left of").match("left of").isMatching());
 }
Ejemplo n.º 2
0
  @Test
  public void testTemplate9() {
    Template template1 = new Template("{anything}");
    assertEquals(0, template1.match("bla bla bla").getBoundaries()[0], 0.0);
    assertEquals(11, template1.match("bla bla bla").getBoundaries()[1], 0.0);
    Template template2 = new Template("this could be {anything}, right");
    assertEquals(
        4,
        template2.partialmatch("and this could be pretty much anything, right").getBoundaries()[0],
        0.0);
    assertEquals(
        "and this could be pretty much anything, right".length(),
        template2.partialmatch("and this could be pretty much anything, right").getBoundaries()[1],
        0.0);
    assertEquals(
        -1,
        template2.partialmatch("and this could be pretty much anything").getBoundaries()[1],
        0.0);

    Template template3 = new Template("{}");
    assertEquals(0, template3.getSlots().size());
    assertTrue(template3.match("{}").isMatching());
    // assertTrue(template3.partialmatch("{}").isMatching());
    assertFalse(template3.match("something").isMatching());
    assertFalse(template3.partialmatch("something").isMatching());
  }
Ejemplo n.º 3
0
  @Test
  public void testTemplate6() {
    Template template1 = new Template("{anything}");
    assertEquals(
        "bla bla bla",
        template1.match("bla bla bla").getFilledSlots().getValue("anything").toString());

    Template template2 = new Template("{anything} is good");
    assertEquals(
        "bla bla bla",
        template2.match("bla bla bla is good").getFilledSlots().getValue("anything").toString());
    assertFalse(template2.match("blo blo").isMatching());
    assertFalse(template2.match("bla bla bla is bad").getFilledSlots().containsVar("anything"));
    assertTrue(template2.match("blo is good").isMatching());

    Template template3 = new Template("this could be {anything}");
    assertEquals(
        "pretty much anything",
        template3
            .match("this could be pretty much anything")
            .getFilledSlots()
            .getValue("anything")
            .toString());
    assertFalse(template3.match("but not this").isMatching());
    assertFalse(template3.match("this could beA").isMatching());
    assertFalse(template3.partialmatch("this could beA").isMatching());
    assertFalse(template3.match("this could be").isMatching());
    assertFalse(template3.partialmatch("this could be").isMatching());
  }
Ejemplo n.º 4
0
 @Test
 public void testTemplate2() {
   Template template = new Template("hi my name is {name}");
   String utterance1 = "hi my name is Pierre, how are you?";
   assertTrue(template.partialmatch(utterance1).isMatching());
   String utterance2 = "hello how are you?";
   assertFalse(template.partialmatch(utterance2).isMatching());
   String utterance3 = "hi my name is Pierre";
   assertTrue(template.partialmatch(utterance3).isMatching());
   assertTrue(template.match(utterance3).isMatching());
 }
Ejemplo n.º 5
0
  @Test
  public void testTemplate3() {
    Template template = new Template("hi my name is {name} and I need coffee");
    String utterance1 = " hi my name is Pierre and i need coffee ";
    String utterance2 = "hi my name is Pierre and I need coffee right now";
    assertTrue(template.partialmatch(utterance1).isMatching());
    assertTrue(template.partialmatch(utterance2).isMatching());
    String utterance3 = "hello how are you?";
    assertFalse(template.partialmatch(utterance3).isMatching());

    assertFalse(template.match(utterance3).isMatching());
    assertTrue(template.match(utterance1).isMatching());
  }
Ejemplo n.º 6
0
  @Test
  public void testTemplate8() throws Exception {
    Template template = new Template("here we have a test");
    assertFalse(template.match("here we have a test2").isMatching());
    assertFalse(template.partialmatch("here we have a test2").isMatching());
    assertTrue(template.partialmatch("here we have a test that is working").isMatching());
    assertFalse(template.match("here we have a test that is working").isMatching());

    Template template2 = new Template("bla");
    assertFalse(template2.partialmatch("bla2").isMatching());
    assertFalse(template2.partialmatch("blabla").isMatching());
    assertTrue(template2.partialmatch("bla bla").isMatching());
    assertFalse(template2.match("bla bla").isMatching());
  }
Ejemplo n.º 7
0
 @Test
 public void testMatchInString() {
   Template t = new Template("{X}th of March");
   assertTrue(t.match("20th of March").isMatching());
   assertTrue(t.partialmatch("on the 20th of March").isMatching());
   assertFalse(t.match("20 of March").isMatching());
 }
Ejemplo n.º 8
0
 @Test
 public void testTemplate1() {
   Template template = new Template("this is a first test");
   String utterance = "bla bla this is a first test bla";
   assertTrue(template.partialmatch(utterance).isMatching());
 }