예제 #1
0
  private void doTest(String input, String expectedOutput, boolean isQuestion) {

    interpreter.question = isQuestion;
    ArrayList<CNF> cnfInput = interpreter.getCNFInput(input);
    ArrayList<String> kifClauses = interpreter.interpretCNF(cnfInput);
    String actual = interpreter.fromKIFClauses(kifClauses);

    Formula actualFormula = new Formula(actual);

    assertEquals(
        expectedOutput.replaceAll("\\s+", " ").trim(), actual.replaceAll("\\s+", " ").trim());
    assertTrue(actualFormula.logicallyEquals(expectedOutput));
  }
예제 #2
0
  /**
   * ************************************************************** John has a red car. amod(?X,?Y),
   * sumo(?C,?Y) ==> (attribute(?X,?C)).
   */
  @Test
  public void testAMod() {

    String input =
        "root(ROOT-0,have-2), nsubj(have-2,John-1), det(car-5,a-3), amod(car-5,red-4), dobj(have-2,car-5), names(John-1,\"John\"), sumo(Automobile,car-5), attribute(John-1,Male), sumo(Human,John-1), sumo(Red,red-4), number(SINGULAR,John-1), tense(PRESENT,have-2), number(SINGULAR,car-5)";
    ArrayList<CNF> cnfInput = interpreter.getCNFInput(input);

    String[] expected = {"(attribute car-5 Red)"};

    ArrayList<String> kifClauses = interpreter.interpretCNF(cnfInput);
    Set<String> actual = Sets.newHashSet(kifClauses);
    Set<String> cleanedActual =
        actual.stream().map(str -> str.replaceAll("\\s+", " ")).collect(Collectors.toSet());

    assertThat(cleanedActual, hasItems(expected));
  }
예제 #3
0
  /**
   * ************************************************************** Mary, my sister, arrived.
   * appos(?X,?Y) ==> (equals(?X,?Y)).
   */
  @Test
  public void testAppos() {

    String input =
        "sumo(Woman,Mary-1), number(SINGULAR,London-1), tense(PRESENT,smells-2), number(SINGULAR,Sam-1), number(SINGULAR,brother-3), tense(PAST,arrived-4), number(SINGULAR,Mary-1), appos(Mary-1,sister-4), poss(sister-4,my-2), sumo(sister,sister-4), number(SINGULAR,sister-4), root(ROOT-0,arrive-6), nsubj(arrive-6,Mary-1), sumo(Arriving,arrive-6), tense(PAST,arrive-6)";
    ArrayList<CNF> cnfInput = interpreter.getCNFInput(input);

    String[] expected = {"(equals Mary-1 sister-4)"};

    ArrayList<String> kifClauses = interpreter.interpretCNF(cnfInput);
    Set<String> actual = Sets.newHashSet(kifClauses);
    Set<String> cleanedActual =
        actual.stream().map(str -> str.replaceAll("\\s+", " ")).collect(Collectors.toSet());

    assertThat(cleanedActual, hasItems(expected));
  }
예제 #4
0
  /**
   * ************************************************************** Yesterday, Mary ran. tmod(?V,?T)
   * ==> (during(?V,?T)).
   */
  @Test
  public void testTmod() {

    String input =
        "names(Mary-3,\"Mary\"), attribute(Mary-3,Female), sumo(Human,Mary-3), number(SINGULAR,Mary-3), tmod(ran-4,yesterday-1), sumo(Day,yesterday-1), number(SINGULAR,yesterday-1), root(ROOT-0,run-4), tmod(run-4,Yesterday-1), nsubj(run-4,Mary-3), sumo(Running,run-4), tense(PAST,run-4)";
    ArrayList<CNF> cnfInput = interpreter.getCNFInput(input);

    String[] expected = {"(during run-4 Yesterday-1)"};

    ArrayList<String> kifClauses = interpreter.interpretCNF(cnfInput);
    Set<String> actual = Sets.newHashSet(kifClauses);
    Set<String> cleanedActual =
        actual.stream().map(str -> str.replaceAll("\\s+", " ")).collect(Collectors.toSet());

    assertThat(cleanedActual, hasItems(expected));
  }
예제 #5
0
  /**
   * ************************************************************** The meat smells sweet.
   * acomp(?V,?A), sumo(?AC,?A), nsubj(?V,?O), sumo(?C,?O), isSubclass(?C,Object) ==>
   * (attribute(?O,?AC)).
   */
  @Test
  public void testAcomp2() {

    String input =
        "det(meat-2,the-1), det(meat-2,The-1), sumo(Meat,meat-2), number(SINGULAR,meat-2), root(ROOT-0,smell-3), nsubj(smell-3,meat-2), acomp(smell-3,sweet-4), sumo(Smelling,smell-3), tense(PRESENT,smell-3), acomp(smells-3,sweet-4), sumo(Sweetness,sweet-4)";
    ArrayList<CNF> cnfInput = interpreter.getCNFInput(input);

    String[] expected = {"(attribute meat-2 Sweetness)"};

    ArrayList<String> kifClauses = interpreter.interpretCNF(cnfInput);
    Set<String> actual = Sets.newHashSet(kifClauses);
    Set<String> cleanedActual =
        actual.stream().map(str -> str.replaceAll("\\s+", " ")).collect(Collectors.toSet());

    assertThat(cleanedActual, hasItems(expected));
  }