edu.cornell.cs.nlp.spf.mr.lambda.visitor.ApplyAndSimplify Java Examples

The following examples show how to use edu.cornell.cs.nlp.spf.mr.lambda.visitor.ApplyAndSimplify. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogicalExpressionCategoryServices.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LogicalExpression apply(LogicalExpression function,
		LogicalExpression argument) {
	final LogicalExpression result;

	// Combined application and simplification
	final LogicalExpression applicationResult = ApplyAndSimplify.of(
			function, argument);
	// Verify application result is well typed, only if verification is
	// turned on
	if (applicationResult != null && doTypeChecking
			&& !IsTypeConsistent.of(applicationResult)) {
		result = null;
	} else {
		result = applicationResult;
	}

	return result;
}
 
Example #2
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test16() {
	final LogicalExpression result = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (c_ARGX:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $1:e (and:<t*,t> (oppose-01:<e,t> $1) (c_ARGX:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id (lambda $2:e (terrorism:<e,t> $2)))))))))");
	final LogicalExpression arg = TestServices.getCategoryServices()
			.readSemantics("(lambda $0:e (terrorism:<e,t> $0))");
	final LogicalExpression func = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $4:<e,t> (lambda $0:e (c_ARGX:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $1:e (and:<t*,t> (oppose-01:<e,t> $1) (c_ARGX:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id $4))))))))");
	Assert.assertEquals(result, ApplyAndSimplify.of(func, arg));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 1));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 2));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 3));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 4));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 5));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 6));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 7));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 8));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3, 9));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3, 10));
}
 
Example #3
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test17() {
	final LogicalExpression result = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (and:<t*,t> (become-01:<e,t> $0) "
							+ "(c_ARGX:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $1:e (and:<t*,t> (warfare:<e,t> $1) (c_REL:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id (lambda $2:e (cyber:<e,t> $2)))))))) "
							+ "(c_ARGX:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $3:e (and:<t*,t> (weapon:<e,t> $3) (c_REL:<e,<e,t>> $3 (a:<id,<<e,t>,e>> na:id (lambda $4:e (common:<e,t> $4)))))))) "
							+ "(c_REL:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $5:e (and:<t*,t> (person:<e,t> $5) (c_REL:<e,<e,t>> $5 (a:<id,<<e,t>,e>> na:id (lambda $6:e (and:<t*,t> (country:<e,t> $6) (c_REL:<e,<e,t>> $6 (a:<id,<<e,t>,e>> na:id (lambda $7:e (and:<t*,t> (name:<e,t> $7) (c_op:<e,<e,t>> $7 South++Korea:e)))))))))))))))");
	final LogicalExpression arg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (and:<t*,t> (become-01:<e,t> $0) "
							+ "(c_ARGX:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $1:e (and:<t*,t> (warfare:<e,t> $1) (c_REL:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id (lambda $2:e (cyber:<e,t> $2)))))))) "
							+ "(c_ARGX:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $3:e (and:<t*,t> (c_REL:<e,<e,t>> $3 (a:<id,<<e,t>,e>> na:id (lambda $4:e (common:<e,t> $4)))) (weapon:<e,t> $3)))))))");
	final LogicalExpression func = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $1:<e,t> (lambda $0:e (and:<t*,t>  "
							+ "($1 $0) "
							+ "(c_REL:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $5:e (and:<t*,t> (person:<e,t> $5) "
							+ "(c_REL:<e,<e,t>> $5 (a:<id,<<e,t>,e>> na:id (lambda $6:e (and:<t*,t> (country:<e,t> $6) (c_REL:<e,<e,t>> $6 (a:<id,<<e,t>,e>> na:id (lambda $7:e (and:<t*,t> (name:<e,t> $7) (c_op:<e,<e,t>> $7 South++Korea:e))))))))))))))))");
	Assert.assertEquals(result, ApplyAndSimplify.of(func, arg));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3));
}
 
Example #4
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test9() {
	final LogicalExpression result = TestServices
			.getCategoryServices()
			.readSemantics(
					"(a:<id,<<e,t>,e>> na:id (lambda $0:e (and:<t*,t> "
							+ "(and:<e,t> $0) "
							+ "(c_op1:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $1:e (international:<e,t> $1)))) "
							+ "(c_op2:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $2:e (military:<e,t> $2)))) "
							+ "(c_op2:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $3:e (terrorism:<e,t> $3)))))))");
	final LogicalExpression arg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,<e,t>> (lambda $1:e (lambda $2:e ($0 $1 $2))))");
	Assert.assertEquals(result, ApplyAndSimplify.of(
			GetApplicationFunction.of(result, arg, 3), arg));
}
 
Example #5
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test10() {
	final LogicalExpression e1 = LogicalExpression
			.read("(lambda $0:t (or:<t*,t> (boo:<e,t> foo:e) $0))");
	final LogicalExpression a1 = LogicalExpression
			.read("(or:<t*,t> (goo:<e,t> foo:e) (koo:<e,t> foo:e))");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	final LogicalExpression expected1 = LogicalExpression
			.read("(or:<t*,t> (goo:<e,t> foo:e) (koo:<e,t> foo:e) (boo:<e,t> foo:e))");
	assertTrue(String.format("%s != %s", r1, expected1),
			expected1.equals(r1));
}
 
Example #6
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test9() {
	final LogicalExpression e1 = LogicalExpression
			.read("(lambda $0:t (and:<t*,t> (boo:<e,t> foo:e) $0))");
	final LogicalExpression a1 = LogicalExpression
			.read("(and:<t*,t> (goo:<e,t> foo:e) (koo:<e,t> foo:e))");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	final LogicalExpression expected1 = LogicalExpression
			.read("(and:<t*,t> (goo:<e,t> foo:e) (koo:<e,t> foo:e) (boo:<e,t> foo:e))");
	assertTrue(String.format("%s != %s", r1, expected1),
			expected1.equals(r1));
}
 
Example #7
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test8() {
	final LogicalExpression e1 = LogicalExpression
			.read("(lambda $0:e (and:<t*,t> (p:<e,t> $0) (q:<e,t> $0)))");
	final LogicalExpression a1 = LogicalExpression
			.read("(a:<<e,t>,e> (lambda $0:e (r:<e,t> $0)))");
	final LogicalExpression expected = LogicalExpression
			.read("(and:<t*,t> (p:<e,t> (a:<<e,t>,e> (lambda $0:e (r:<e,t> $0)))) (q:<e,t> (a:<<e,t>,e> (lambda $1:e (r:<e,t> $1)))))");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	assertTrue(String.format("%s != %s", r1, expected), r1.equals(expected));
}
 
Example #8
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test7() {
	final LogicalExpression e1 = LogicalExpression
			.read("(lambda $0:<e,<e,e>> ($0 "
					+ "(do_until:<e,<t,e>> (do:<e,e> turn:e) (notempty:<<e,t>,t> (intersect:<<e,t>*,<e,t>> chair:<e,t> (front:<<e,t>,<e,t>> at:<e,t>)))) "
					+ "(do_until:<e,<t,e>> (do:<e,e> travel:e) (notempty:<<e,t>,t> (intersect:<<e,t>*,<e,t>> chair:<e,t> at:<e,t>)))))");
	final LogicalExpression a1 = LogicalExpression.read("do_seq:<e+,e>");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	final LogicalExpression expected = LogicalExpression
			.read("(do_seq:<e+,e> (do_until:<e,<t,e>> (do:<e,e> turn:e) (notempty:<<e,t>,t> (intersect:<<e,t>*,<e,t>> chair:<e,t> (front:<<e,t>,<e,t>> at:<e,t>)))) (do_until:<e,<t,e>> (do:<e,e> travel:e) (notempty:<<e,t>,t> (intersect:<<e,t>*,<e,t>> chair:<e,t> at:<e,t>))))");
	assertTrue(String.format("%s != %s", r1, expected), r1.equals(expected));
}
 
Example #9
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test6() {
	final LogicalExpression e1 = LogicalExpression
			.read("(and:<t*,t> go:t do:t)");
	final LogicalExpression a1 = LogicalExpression.read("lo:t");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	assertTrue(String.format("%s != %s", r1, null), r1 == null);
}
 
Example #10
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test5() {
	final LogicalExpression e1 = LogicalExpression
			.read("(and:<t*,t> go:t)");
	final LogicalExpression a1 = LogicalExpression.read("do:t");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	final LogicalExpression expected1 = LogicalExpression
			.read("(and:<t*,t> go:t do:t)");
	assertTrue(String.format("%s != %s", r1, expected1),
			expected1.equals(r1));
}
 
Example #11
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test4() {
	final LogicalExpression e1 = LogicalExpression
			.read("(boo:<e,<e,t>> go:e)");
	final LogicalExpression a1 = LogicalExpression.read("bo:e");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	final LogicalExpression expected1 = LogicalExpression
			.read("(boo:<e,<e,t>> go:e bo:e)");
	assertTrue(String.format("%s != %s", r1, expected1),
			expected1.equals(r1));
}
 
Example #12
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test3() {
	final LogicalExpression e1 = LogicalExpression
			.read("(lambda $0:e (lambda $1:e (boo:<e,<e,t>> $0 $1)))");
	final LogicalExpression a1 = LogicalExpression.read("goo:e");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	final LogicalExpression expected1 = LogicalExpression
			.read("(lambda $0:e (boo:<e,<e,t>> goo:e $0))");
	assertTrue(String.format("%s != %s", r1, expected1),
			expected1.equals(r1));
}
 
Example #13
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test2() {
	final LogicalExpression e1 = LogicalExpression.read("goo:<<e,t>,t>");
	final LogicalExpression a1 = LogicalExpression.read("doo:<e,t>");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	final LogicalExpression expected1 = LogicalExpression
			.read("(goo:<<e,t>,t> doo:<e,t>)");
	assertTrue(String.format("%s != %s", r1, expected1),
			expected1.equals(r1));
}
 
Example #14
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test11() {
	final LogicalExpression e1 = LogicalExpression
			.read("(lambda $0:t (or:<t*,t> (boo:<e,t> foo:e) $0))");
	final LogicalExpression a1 = LogicalExpression
			.read("(and:<t*,t> (goo:<e,t> foo:e) (koo:<e,t> foo:e))");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	final LogicalExpression expected1 = LogicalExpression
			.read("(or:<t*,t> (and:<t*,t> (goo:<e,t> foo:e) (koo:<e,t> foo:e)) (boo:<e,t> foo:e))");
	assertTrue(String.format("%s != %s", r1, expected1),
			expected1.equals(r1));
}
 
Example #15
Source File: TreeTransformer.java    From UDepLambda with Apache License 2.0 5 votes vote down vote up
private static LogicalExpression bindOperation(
    LogicalExpression leftTreeParse, LogicalExpression rightTreeParse) {
  Preconditions.checkNotNull(leftTreeParse);
  Preconditions.checkNotNull(rightTreeParse);
  Preconditions.checkArgument(rightTreeParse instanceof LogicalConstant);

  // Dirty implementation. A better way is to work with objects and not the
  // strings.
  Type leftType = leftTreeParse.getType();
  String existsExpression =
      String.format("(lambda $f:%s (exists:<%s,<%s,%s>> $x:%s ($f $x))",
          leftType, leftType.getDomain(), leftType.getRange(),
          leftType.getRange(), leftType.getDomain());
  leftTreeParse =
      ApplyAndSimplify
          .of(SimpleLogicalExpressionReader.read(existsExpression),
              leftTreeParse);

  String variable = rightTreeParse.toString();
  String leftParse = leftTreeParse.toString();
  String variableType = rightTreeParse.getType().getDomain().toString();
  String returnType = rightTreeParse.getType().getRange().toString();
  Pattern variablePattern =
      Pattern.compile(String.format("([\\(\\)\\s])(%s)([\\(\\)\\s])",
          variable));
  Matcher matcher = variablePattern.matcher(leftParse);

  String finalString =
      matcher
          .replaceAll(String.format("$1%s:<%s,<%s,%s>> \\$x$3",
              PredicateKeys.EQUAL_PREFIX, variableType, variableType,
              returnType));
  finalString = String.format("(lambda $x:%s %s)", variableType, finalString);
  return SimpleLogicalExpressionReader.read(finalString);
}
 
Example #16
Source File: ApplyAndSimplifyTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test1() {
	final LogicalExpression e1 = LogicalExpression
			.read("(lambda $0:<e,t> (lambda $1:e (and:<t*,t> (boo:<e,t> $1) ($0 $1))))");
	final LogicalExpression a1 = LogicalExpression.read("doo:<e,t>");
	final LogicalExpression r1 = ApplyAndSimplify.of(e1, a1);
	final LogicalExpression expected1 = LogicalExpression
			.read("(lambda $0:e (and:<t*,t> (boo:<e,t> $0) (doo:<e,t> $0)))");
	assertTrue(String.format("%s != %s", r1, expected1),
			expected1.equals(r1));
}
 
Example #17
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test14() {
	final LogicalExpression result = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $4:e (c_ARGX:<e,<e,t>> $4\n"
							+ "                (a:<id,<<e,t>,e>> na:id (lambda $5:e (and:<t*,t>\n"
							+ "                  (oppose-01:<e,t> $5)\n"
							+ "                  (c_ARGX:<e,<e,t>> $5\n"
							+ "                    (a:<id,<<e,t>,e>> na:id (lambda $6:e (terrorism:<e,t> $6)))))))))");
	final LogicalExpression arg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (c_ARGX:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $1:e (terrorism:<e,t> $1)))))");
	final LogicalExpression func = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $4:e (c_ARGX:<e,<e,t>> $4\n"
							+ "                (a:<id,<<e,t>,e>> na:id (lambda $5:e (and:<t*,t>\n"
							+ "                  (oppose-01:<e,t> $5)\n"
							+ "                  ($0 $5)))))))");
	Assert.assertEquals(result, ApplyAndSimplify.of(func, arg));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 1));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 2));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 3));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 4));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3, 5));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3, 6));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3, 7));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3, 8));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3, 9));
}
 
Example #18
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test13() {
	final LogicalExpression result = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (lambda $1:e (and:<t*,t> (propose-01:<e,t> $1) (c_ARGX:<e,<e,t>> $1 $0))))");
	final LogicalExpression arg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,<e,t>> (lambda $1:e (lambda $2:e ($0 $1 $2))))");
	Assert.assertEquals(result, ApplyAndSimplify.of(
			GetApplicationFunction.of(result, arg, 3), arg));
}
 
Example #19
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test12() {
	final LogicalExpression result = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (lambda $1:<e,t> (a:<id,<<e,t>,e>> na:id (lambda $2:e (and:<t*,t>\n"
							+ "	($1 $2)\n"
							+ "	(c_ARGX:<e,<e,t>> $2 (a:<id,<<e,t>,e>> na:id (lambda $3:e (and:<t*,t>\n"
							+ "		(and:<e,t> $3)\n"
							+ "		(c_op1:<e,<e,t>> $3 (a:<id,<<e,t>,e>> na:id (lambda $4:e (and:<t*,t>\n"
							+ "			(bias-01:<e,t> $4)\n"
							+ "			(c_ARGX:<e,<e,t>> $4 $0)\n"
							+ "			(c_REL:<e,<e,t>> $4 \n"
							+ "				(a:<id,<<e,t>,e>> na:id (lambda $5:e (cultural:<e,t> $5))))))))\n"
							+ "		(c_op2:<e,<e,t>> $3 (a:<id,<<e,t>,e>> na:id (lambda $6:e (and:<t*,t>\n"
							+ "			(insult-01:<e,t> $6)\n"
							+ "			(c_ARGX:<e,<e,t>> $6 $0)\n"
							+ "			(c_ARGX:<e,<e,t>> $6 $0))))))))))))))");
	final LogicalExpression arg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (lambda $1:e (lambda $2:e (c_ARGX:<e,<e,t>> $2 (a:<id,<<e,t>,e>> na:id (lambda $3:e (and:<t*,t>\n"
							+ "	(c_op1:<e,<e,t>> $3 $1)\n"
							+ "	(c_op2:<e,<e,t>> $3 $0)\n"
							+ "	(and:<e,t> $3))))))))");
	Assert.assertEquals(result, ApplyAndSimplify.of(
			GetApplicationFunction.of(result, arg, 3), arg));
}
 
Example #20
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test15() {
	final LogicalExpression result = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (and:<t*,t>\n"
							+ "	(sponsor-01:<e,t> $0)\n"
							+ "	(c_ARGX:<e,<e,t>> $0 \n"
							+ "		(a:<id,<<e,t>,e>> na:id (lambda $1:e (it:<e,t> $1))))\n"
							+ "	(c_ARGX:<e,<e,t>> $0 \n"
							+ "		(a:<id,<<e,t>,e>> na:id (lambda $2:e (and:<t*,t>\n"
							+ "			(workshop:<e,t> $2)\n"
							+ "			(c_REL:<e,<e,t>> $2 \n"
							+ "				(a:<id,<<e,t>,e>> na:id (lambda $3:e (and:<t*,t>\n"
							+ "					(person:<e,t> $3)\n"
							+ "					(c_REL:<e,<i,t>> $3 50:i)\n"
							+ "					(c_ARGX-of:<e,<e,t>> $3 \n"
							+ "						(a:<id,<<e,t>,e>> na:id (lambda $4:e (and:<t*,t>\n"
							+ "							(expert-41:<e,t> $4)\n"
							+ "							(c_ARGX:<e,<e,t>> $4 \n"
							+ "								(a:<id,<<e,t>,e>> na:id (lambda $5:e (and:<t*,t>\n"
							+ "									(oppose-01:<e,t> $5)\n"
							+ "									(c_ARGX:<e,<e,t>> $5 \n"
							+ "										(a:<id,<<e,t>,e>> na:id (lambda $6:e (terrorism:<e,t> $6))))))))))))))))\n"
							+ "			(c_REL:<e,<e,t>> $2 \n"
							+ "				(a:<id,<<e,t>,e>> na:id (lambda $7:e (and:<t*,t>\n"
							+ "					(temporal-quantity:<e,t> $7)\n"
							+ "					(c_REL:<e,<i,t>> $7 2:i)\n"
							+ "					(c_REL:<e,<e,t>> $7 \n"
							+ "						(a:<id,<<e,t>,e>> na:id (lambda $8:e (week:<e,t> $8))))))))))))))");
	final LogicalExpression arg = TestServices.getCategoryServices()
			.readSemantics(
					"(a:<id,<<e,t>,e>> na:id (lambda $0:e (it:<e,t> $0)))");
	final LogicalExpression func = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $1:e (lambda $0:e (and:<t*,t>\n"
							+ "	(sponsor-01:<e,t> $0)\n"
							+ "	(c_ARGX:<e,<e,t>> $0 \n"
							+ "		$1)\n"
							+ "	(c_ARGX:<e,<e,t>> $0 \n"
							+ "		(a:<id,<<e,t>,e>> na:id (lambda $2:e (and:<t*,t>\n"
							+ "			(workshop:<e,t> $2)\n"
							+ "			(c_REL:<e,<e,t>> $2 \n"
							+ "				(a:<id,<<e,t>,e>> na:id (lambda $3:e (and:<t*,t>\n"
							+ "					(person:<e,t> $3)\n"
							+ "					(c_REL:<e,<i,t>> $3 50:i)\n"
							+ "					(c_ARGX-of:<e,<e,t>> $3 \n"
							+ "						(a:<id,<<e,t>,e>> na:id (lambda $4:e (and:<t*,t>\n"
							+ "							(expert-41:<e,t> $4)\n"
							+ "							(c_ARGX:<e,<e,t>> $4 \n"
							+ "								(a:<id,<<e,t>,e>> na:id (lambda $5:e (and:<t*,t>\n"
							+ "									(oppose-01:<e,t> $5)\n"
							+ "									(c_ARGX:<e,<e,t>> $5 \n"
							+ "										(a:<id,<<e,t>,e>> na:id (lambda $6:e (terrorism:<e,t> $6))))))))))))))))\n"
							+ "			(c_REL:<e,<e,t>> $2 \n"
							+ "				(a:<id,<<e,t>,e>> na:id (lambda $7:e (and:<t*,t>\n"
							+ "					(temporal-quantity:<e,t> $7)\n"
							+ "					(c_REL:<e,<i,t>> $7 2:i)\n"
							+ "					(c_REL:<e,<e,t>> $7 \n"
							+ "						(a:<id,<<e,t>,e>> na:id (lambda $8:e (week:<e,t> $8))))))))))))))");
	Assert.assertEquals(result, ApplyAndSimplify.of(func, arg));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 1));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 2));
	Assert.assertEquals(null, GetApplicationFunction.of(result, arg, 3, 3));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3, 4));
	Assert.assertEquals(func, GetApplicationFunction.of(result, arg, 3, 5));
}
 
Example #21
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test11() {
	final LogicalExpression result = TestServices
			.getCategoryServices()
			.readSemantics(
					"(a:<id,<<e,t>,e>> na:id (lambda $0:e (and:<t*,t>\n"
							+ "	(sign-02:<e,t> $0)\n"
							+ "	(c_ARGX:<e,<e,t>> $0 \n"
							+ "		(a:<id,<<e,t>,e>> na:id (lambda $1:e (and:<t*,t>\n"
							+ "			(country:<e,t> $1)\n"
							+ "			(c_REL:<e,<e,t>> $1 \n"
							+ "				(a:<id,<<e,t>,e>> na:id (lambda $2:e (and:<t*,t>\n"
							+ "					(ethnic-group:<e,t> $2)\n"
							+ "					(c_REL:<e,<e,t>> $2 \n"
							+ "						(a:<id,<<e,t>,e>> na:id (lambda $3:e (and:<t*,t>\n"
							+ "							(name:<e,t> $3)\n"
							+ "							(c_op:<e,<e,t>> $3 Arab:e)))))))))))))\n"
							+ "	(c_ARGX:<e,<e,t>> $0 \n"
							+ "		(a:<id,<<e,t>,e>> na:id (lambda $4:e (and:<t*,t>\n"
							+ "			(agree-01:<e,t> $4)\n"
							+ "			(c_REL:<e,<e,t>> $4 \n"
							+ "				(a:<id,<<e,t>,e>> na:id (lambda $5:e (and:<t*,t>\n"
							+ "					(counter-01:<e,t> $5)\n"
							+ "					(c_ARGX:<e,<e,t>> $5 \n"
							+ "						(a:<id,<<e,t>,e>> na:id (lambda $6:e (terrorism:<e,t> $6))))\n"
							+ "					(c_ARGX-of:<e,<e,t>> $5 \n"
							+ "						(a:<id,<<e,t>,e>> na:id (lambda $7:e (and:<t*,t>\n"
							+ "							(bind-01:<e,t> $7)\n"
							+ "							(c_ARGX:<e,<e,t>> $7 \n"
							+ "								(ref:<id,e> na:id))\n"
							+ "							(c_ARGX:<e,<e,t>> $7 \n"
							+ "								(a:<id,<<e,t>,e>> na:id (lambda $8:e (and:<t*,t>\n"
							+ "									(coordinate-01:<e,t> $8)\n"
							+ "									(c_ARGX:<e,<e,t>> $8 \n"
							+ "										(ref:<id,e> na:id))\n"
							+ "									(c_REL:<e,<e,t>> $8 \n"
							+ "										(a:<id,<<e,t>,e>> na:id (lambda $9:e (and:<t*,t>\n"
							+ "											(fight-01:<e,t> $9)\n"
							+ "											(c_ARGX:<e,<e,t>> $9 \n"
							+ "												(ref:<id,e> na:id))\n"
							+ "											(c_ARGX:<e,<e,t>> $9 \n"
							+ "												(a:<id,<<e,t>,e>> na:id (lambda $10:e (terrorism:<e,t> $10))))))))))))))))))))))))\n"
							+ "	(c_REL:<e,<e,t>> $0 \n"
							+ "		(a:<id,<<e,t>,e>> na:id (lambda $11:e (and:<t*,t>\n"
							+ "			(date-entity:<e,t> $11)\n"
							+ "			(c_year:<e,<i,t>> $11 1998:i)\n"
							+ "			(c_month:<e,<i,t>> $11 4:i))))))))\n"
							+ "");
	final LogicalExpression arg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $1:e (lambda $2:e (and:<t*,t>\n"
							+ "	(bind-01:<e,t> $2)\n"
							+ "	(c_ARGX:<e,<e,t>> $2 (a:<id,<<e,t>,e>> na:id (lambda $3:e (and:<t*,t>\n"
							+ "		(coordinate-01:<e,t> $3)\n"
							+ "		(c_ARGX:<e,<e,t>> $3 \n"
							+ "			(ref:<id,e> na:id))\n"
							+ "		(c_REL:<e,<e,t>> $3 $1))))))))");
	Assert.assertEquals(result, ApplyAndSimplify.of(
			GetApplicationFunction.of(result, arg, 3), arg));
}
 
Example #22
Source File: SloppyAmrClosure.java    From amr with GNU General Public License v2.0 4 votes vote down vote up
public static LogicalExpression of(LogicalExpression semantics) {
	final Type etType = LogicLanguageServices.getTypeRepository()
			.getTypeCreateIfNeeded(
					LogicLanguageServices.getTypeRepository()
							.getTruthValueType(),
					LogicLanguageServices.getTypeRepository()
							.getEntityType());
	final Type eType = LogicLanguageServices.getTypeRepository()
			.getEntityType();

	LogicalExpression stripped = semantics;
	while (!(stripped.getType().equals(etType)
			|| stripped.getType().equals(eType))
			&& stripped instanceof Lambda) {
		final Variable variable = ((Lambda) stripped).getArgument();
		if (variable.getType().isComplex() && variable.getType().getRange()
				.equals(variable.getType().getDomain())) {
			final Variable argVariable = new Variable(
					variable.getType().getDomain());
			stripped = ApplyAndSimplify.of(stripped,
					new Lambda(argVariable, argVariable));
		} else {
			stripped = ((Lambda) stripped).getBody();
		}
	}

	final SloppyAmrClosure visitor = new SloppyAmrClosure();
	visitor.visit(stripped);

	final LogicalExpression resultSemantics;
	if (visitor.result == null) {
		LOG.info(() -> {
			if (GetConstantsSet.of(semantics)
					.stream().filter(c -> AMRServices
							.getTypingPredicateType().equals(c.getType()))
					.count() != 0) {
				// This is fairly rare.
				LOG.debug(
						"Failed to close to AMR, but there are instance predicates: %s",
						semantics);
			}
		});
		return null;
	} else if (visitor.result.getType().equals(eType)) {
		resultSemantics = visitor.result;
	} else if (visitor.result.getType().equals(etType)) {
		resultSemantics = AMRServices.skolemize(visitor.result);
	} else {
		// Mostly (or even only) happens in the case of a coordination that
		// is not finalized.
		LOG.info("Unexpected return type from closing to AMR: %s -> %s",
				semantics, visitor.result);
		return null;
	}

	// TODO Fix to avoid this, pretty common (~900)
	if (IsValidAmr.of(resultSemantics, false, true)
			&& AMRServices.isSkolemTerm(resultSemantics)) {
		return resultSemantics;
	} else {
		LOG.info("Result of closing to AMR is invalid: %s -> %s", semantics,
				resultSemantics);
		return null;
	}
}