Java Code Examples for edu.cornell.cs.nlp.spf.mr.lambda.LogicLanguageServices

The following examples show how to use edu.cornell.cs.nlp.spf.mr.lambda.LogicLanguageServices. These examples are extracted from open source projects. 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
@Override
public Object evaluateConstant(LogicalConstant logicalConstant) {
	
	// Try to treat the constant as a number
	final Long num = LogicLanguageServices
			.logicalExpressionToInteger(logicalConstant);
	if (num != null) {
		return new Double(num);
	}
	
	// Case true:t
	if (LogicLanguageServices.getTrue().equals(logicalConstant)) {
		return true;
	}
	
	// Case false:t
	if (LogicLanguageServices.getFalse().equals(logicalConstant)) {
		return false;
	}
	
	// Unknown constant
	return null;
}
 
Example 2
@Test
public void testSubExp14() {
	final LogicalExpression appArg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (lambda $1:e (lambda $2:e (and:<t*,t> (b:<e,t> $2) (a:<e,t> P:e) (boo:<e,<e,t>> $0 $1)))))");
	final LogicalExpression subExp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(and:<t*,t> (a:<e,t> P:e) (boo:<e,<e,t>> koo:e loo:e))");
	final Variable replacementVariable = new Variable(LogicLanguageServices
			.getTypeRepository().getType("<e,<e,<e,t>>>"));
	final LogicalExpression expected = null;
	Assert.assertEquals(expected, GetApplicationFunction.processSubExp(
			subExp, appArg, replacementVariable));
}
 
Example 3
@Test
public void testSubExp9() {
	final LogicalExpression appArg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $1:e (a:<<e,t>,e> (lambda $0:e (pred:<e,<e,t>> $1 $0))))");
	final LogicalExpression subExp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(a:<<e,t>,e> (lambda $0:e (pred:<e,<e,t>> boo:e $0))))");
	final Variable replacementVariable = new Variable(LogicLanguageServices
			.getTypeRepository().getType("<e,e>"));
	final LogicalExpression expected = new Literal(replacementVariable,
			ArrayUtils.create(TestServices.getCategoryServices()
					.readSemantics("boo:e")));
	Assert.assertEquals(expected, GetApplicationFunction.processSubExp(
			subExp, appArg, replacementVariable));
}
 
Example 4
Source Project: spf   Source File: SkolemIDRuleTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
public SkolemIDRuleTest() {
	TestServices.init();
	this.rule = new SkolemIDRule(
			SetUtils.createSet(LogicalConstant.create(
					"io:<id,<id,<<e,t>,e>>>",
					LogicLanguageServices.getTypeRepository()
							.getTypeCreateIfNeeded("<id,<id,<<e,t>,e>>>"),
					false),
					LogicalConstant
							.create("a:<id,<<e,t>,e>>",
									LogicLanguageServices
											.getTypeRepository()
											.getTypeCreateIfNeeded(
													"<id,<<e,t>,e>>"),
									false)));
}
 
Example 5
@Test
public void testSubExp11() {
	final LogicalExpression appArg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $1:e (a:<<e,t>,e> (lambda $0:e (and:<t*,t> (b:<e,t> A:e) (a:<e,t> P:e) (pred:<e,<e,t>> $1 $0)))))");
	final Variable replacementVariable = new Variable(LogicLanguageServices
			.getTypeRepository().getType("<e,e>"));
	final LogicalExpression subExp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(a:<<e,t>,e> (lambda $0:e (and:<t*,t> (b:<e,t> A:e) (pred:<e,<e,t>> boo:e $0) (a:<e,t> P:e))))");
	final LogicalExpression expected = new Literal(replacementVariable,
			ArrayUtils.create(TestServices.getCategoryServices()
					.readSemantics("boo:e")));
	Assert.assertEquals(expected, GetApplicationFunction.processSubExp(
			subExp, appArg, replacementVariable));
}
 
Example 6
Source Project: amr   Source File: DummyEntityServices.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given a lambda term (e.g., (lambda $0:e (and:<t*,t> ...))), return 'true'
 * iff its body contains relation literals and at least one of them has a
 * dummy entity.
 */
public static boolean hasDummyEntity(Lambda lambda) {
	if (lambda.getBody() instanceof Literal) {
		final Literal bodyLiteral = (Literal) lambda.getBody();
		if (LogicLanguageServices.getConjunctionPredicate().equals(
				bodyLiteral.getPredicate())) {
			final int len = bodyLiteral.numArgs();
			for (int i = 0; i < len; ++i) {
				final LogicalExpression arg = bodyLiteral.getArg(i);
				if (arg instanceof Literal) {
					if (isRelationWithDummy((Literal) arg)) {
						return true;
					}
				}
			}
		} else if (isRelationWithDummy(bodyLiteral)) {
			return true;
		}
	}
	return false;

}
 
Example 7
@Test
public void testSubExp7() {
	final LogicalExpression appArg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (lambda $1:e (lambda $2:e (boo:<e,<e,<e,t>>> $0 $1 $2))))");
	final LogicalExpression subExp = TestServices.getCategoryServices()
			.readSemantics("(boo:<e,<e,<e,t>>> koo:e loo:e doo:e)");
	final Variable replacementVariable = new Variable(LogicLanguageServices
			.getTypeRepository().getType("<e,<e,<e,t>>>"));
	final LogicalExpression expected = new Literal(replacementVariable,
			ArrayUtils.create(
					TestServices.getCategoryServices().readSemantics(
							"koo:e"),
					TestServices.getCategoryServices().readSemantics(
							"loo:e"),
					TestServices.getCategoryServices().readSemantics(
							"doo:e")));
	Assert.assertEquals(expected, GetApplicationFunction.processSubExp(
			subExp, appArg, replacementVariable));
}
 
Example 8
@Test
public void testSubExp10() {
	final LogicalExpression appArg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $1:e (a:<<e,t>,e> (lambda $0:e (and:<t*,t> (b:<e,t> A:e) (a:<e,t> P:e) (pred:<e,<e,t>> $1 $0)))))");
	final LogicalExpression subExp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(a:<<e,t>,e> (lambda $0:e (and:<t*,t> (b:<e,t> A:e) (a:<e,t> P:e) (pred:<e,<e,t>> boo:e $0))))");
	final Variable replacementVariable = new Variable(LogicLanguageServices
			.getTypeRepository().getType("<e,e>"));
	final LogicalExpression expected = new Literal(replacementVariable,
			ArrayUtils.create(TestServices.getCategoryServices()
					.readSemantics("boo:e")));
	Assert.assertEquals(expected, GetApplicationFunction.processSubExp(
			subExp, appArg, replacementVariable));
}
 
Example 9
@Override
public ParseRuleResult<LogicalExpression> apply(
		Category<LogicalExpression> category, SentenceSpan span) {
	if (!isValidArgument(category, span)) {
		return null;
	}

	return new ParseRuleResult<>(name,
			Category.<LogicalExpression> create(
					new CoordinationSyntax(AMRServices.KEY),
					CoordinationServices.createLiteral(
							CoordinationServices.getConjunctionLabel(),
							ArrayUtils.create(category.getSemantics()),
							LogicLanguageServices.getTypeRepository()
									.getEntityType())));
}
 
Example 10
@Test
public void test1() {
	final Variable variable = new Variable(LogicLanguageServices
			.getTypeRepository().getEntityType());
	final LogicalExpression e1 = new Lambda(variable, new Literal(
			LogicalConstant.read("boo:<e,<<e,t>,t>>"), ArrayUtils.create(
					variable,
					new Lambda(variable,
							new Literal(LogicalConstant.read("goo:<e,t>"),
									ArrayUtils.create(variable))))));
	final LogicalExpression e2 = LogicalExpression
			.read("(lambda $0:e (boo:<e,<<e,t>,t>> $0 (lambda $1:e (goo:<e,t> $1))))");
	Assert.assertEquals(e2, e1);

	final LogicalExpression result1 = TestServices.getCategoryServices()
			.apply(e1, LogicalConstant.read("foo:e"));
	final LogicalExpression result2 = TestServices.getCategoryServices()
			.apply(e2, LogicalConstant.read("foo:e"));
	Assert.assertEquals(result1, result2);
	System.out.println(result1);
}
 
Example 11
@SuppressWarnings("unchecked")
public AMRSupervisedFilterFactory(
		Predicate<LogicalConstant> constantsFilter) {
	this.constantFilter = (Serializable & Predicate<LogicalConstant>) constant -> !(LogicLanguageServices
			.isCollpasibleConstant(constant)
			|| LogicLanguageServices.isArrayIndexPredicate(constant)
			|| constant.getType().equals(SkolemServices.getIDType())
			|| constant.equals(AMRServices.getDummyEntity())
			|| CoordinationServices.isCoordinator(constant))
			&& constantsFilter.test(constant);
	this.baseFilterFactory = new SupervisedFilterFactory<>(
			this.constantFilter,
			(Serializable & Predicate<LogicalExpression>) (
					arg) -> !(arg instanceof Literal && (DummyEntityServices
							.isRelationWithDummy((Literal) arg)
							|| ((Literal) arg).numArgs() == 2
									&& ((Literal) arg)
											.getArg(1) instanceof Variable)),
			(Serializable & UnaryOperator<LogicalConstant>) c -> OverloadedLogicalConstant
					.getWrapped(c));
}
 
Example 12
@Test
public void test1() {
	final LogicalExpression exp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> ($0 $1) (boo:<e,<e,t>> $1 goo:e))))");
	final Result result = ExtractTypedSubExpression.of(exp, LogicalConstant
			.read("p:e"), LogicLanguageServices.getTypeRepository()
			.getEntityType(), true);
	Assert.assertNotNull(result);
	final LogicalExpression expectedSubExp = TestServices
			.getCategoryServices().readSemantics("goo:e");
	final LogicalExpression expectedRemainder = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> ($0 $1) (boo:<e,<e,t>> $1 p:e))))");
	Assert.assertEquals(expectedRemainder,
			result.getExpressionWithPlaceholder());
	Assert.assertEquals(expectedSubExp, result.getExtractedSubExpression());
}
 
Example 13
@Test
public void test2() {
	final LogicalExpression exp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> ($0 $1) (boo:<e,<e,t>> $1 goo:e))))");
	final Result result = ExtractTypedSubExpression.of(exp, LogicalConstant
			.read("p:<e,<e,t>>"), LogicLanguageServices.getTypeRepository()
			.getTypeCreateIfNeeded("<e,<e,t>>"), false);
	Assert.assertNotNull(result);
	final LogicalExpression expectedSubExp = LogicalConstant
			.read("boo:<e,<e,t>>");
	final LogicalExpression expectedRemainder = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> ($0 $1) (p:<e,<e,t>> $1 goo:e))))");
	Assert.assertEquals(expectedRemainder,
			result.getExpressionWithPlaceholder());
	Assert.assertEquals(expectedSubExp, result.getExtractedSubExpression());
}
 
Example 14
@Test
public void test3() {
	final LogicalExpression exp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> (do:<e,<e,<e,t>>> roo:e $1 (a:<<e,t>,e> (lambda $0:e (boo:<e,<e,t>> $0 too:e)))) ($0 $1) (boo:<e,<e,t>> $1 goo:e))))");
	final Result result = ExtractTypedSubExpression.of(exp, LogicalConstant
			.read("p:<e,<e,t>>"), LogicLanguageServices.getTypeRepository()
			.getTypeCreateIfNeeded("<e,<e,t>>"), false);
	Assert.assertNotNull(result);
	final LogicalExpression expectedSubExp = LogicalConstant
			.read("boo:<e,<e,t>>");
	final LogicalExpression expectedRemainder = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> (do:<e,<e,<e,t>>> roo:e $1 (a:<<e,t>,e> (lambda $0:e (boo:<e,<e,t>> $0 too:e)))) ($0 $1) (p:<e,<e,t>> $1 goo:e))))");
	Assert.assertEquals(expectedRemainder,
			result.getExpressionWithPlaceholder());
	Assert.assertEquals(expectedSubExp, result.getExtractedSubExpression());
}
 
Example 15
@Test
public void test4() {
	final LogicalExpression exp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> (do:<e,<e,<e,t>>> roo:e $1 (a:<<e,t>,e> (lambda $0:e (boo:<e,<e,t>> $0 too:e)))) ($0 $1) (boo:<e,<e,t>> $1 goo:e))))");
	final Result result = ExtractTypedSubExpression.of(exp, LogicalConstant
			.read("p:t"), LogicLanguageServices.getTypeRepository()
			.getTypeCreateIfNeeded("t"), false);
	Assert.assertNotNull(result);
	final LogicalExpression expectedSubExp = ((Lambda) ((Lambda) exp)
			.getBody()).getBody();
	final LogicalExpression expectedRemainder = TestServices
			.getCategoryServices().readSemantics(
					"(lambda $0:<e,t> (lambda $1:e p:t))");
	Assert.assertEquals(expectedRemainder,
			result.getExpressionWithPlaceholder());
	Assert.assertEquals(expectedSubExp, result.getExtractedSubExpression());
}
 
Example 16
@Test
public void test5() {
	final LogicalExpression exp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> (do:<e,<e,<e,t>>> roo:e $1 (a:<<e,t>,e> (lambda $0:e (boo:<e,<e,t>> $0 too:e)))) ($0 $1) (boo:<e,<e,t>> $1 goo:e))))");
	final Result result = ExtractTypedSubExpression.of(exp, LogicalConstant
			.read("p:t"), LogicLanguageServices.getTypeRepository()
			.getTypeCreateIfNeeded("t"), true);
	Assert.assertNotNull(result);
	final LogicalExpression expectedSubExp = ((Literal) ((Lambda) ((Lambda) exp)
			.getBody()).getBody()).getArg(0);
	final LogicalExpression expectedRemainder = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> p:t ($0 $1) (boo:<e,<e,t>> $1 goo:e))))");
	Assert.assertEquals(expectedRemainder,
			result.getExpressionWithPlaceholder());
	Assert.assertEquals(expectedSubExp, result.getExtractedSubExpression());
}
 
Example 17
Source Project: amr   Source File: AttachmentFeaturesTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test() {
	final AttachmentFeatures<Sentence> fs = new AttachmentFeatures<>(1.0,
			LogicLanguageServices.getTypeRepository()
					.getTypeCreateIfNeeded("<e,t>"), 1000, 10);

	final IHashVector features = HashVectorFactory.create();
	fs.setFeatures(
			createParseStep(
					TestServices
							.getCategoryServices()
							.read("N : (lambda $0:e (and:<t*,t> (pred:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id type:<e,t>)) (boo:<e,t> $0)))"),
					TestServices.getCategoryServices().read(
							"N : (lambda $0:e (boo:<e,t> $0))")), features,
			new Sentence("dummy"));
	Assert.assertEquals(
			"{ATTACH#boo#pred=1.000, ATTACH#boo#pred#type=1.000, ATTACH#pred#type=1.000}",
			features.toString());
}
 
Example 18
Source Project: amr   Source File: AttachmentFeaturesTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test6() {
	final AttachmentFeatures<Sentence> fs = new AttachmentFeatures<>(1.0,
			LogicLanguageServices.getTypeRepository()
					.getTypeCreateIfNeeded("<e,t>"), 1000, 10);

	final IHashVector features = HashVectorFactory.create();
	fs.setFeatures(
			createParseStep(
					TestServices
							.getCategoryServices()
							.read("N : (lambda $0:<<e,t>,<e,t>> (lambda $1:e (and:<t*,t> (sponsor-01:<e,t> $1) (c_ARGX:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id (lambda $2:e (and:<t*,t> ($0 (lambda $3:e (expert-41:<e,t> $3)) $2) (c_REL:<e,<i,t>> $2 50:i))))))))"),
					TestServices
							.getCategoryServices()
							.read("N : (lambda $0:<<e,t>,<e,t>> (lambda $1:<e,t> (lambda $2:e (and:<t*,t> ($0 (lambda $3:e ($1 $3)) $2) (c_REL:<e,<i,t>> $2 50:i)))))"),
					TestServices
							.getCategoryServices()
							.read("N : (lambda $0:<<e,t>,<e,t>> (lambda $1:e (and:<t*,t> (sponsor-01:<e,t> $1) (c_ARGX:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id (lambda $2:e ($0 (lambda $3:e (expert-41:<e,t> $3)) $2)))))))")),
			features, new Sentence("dummy"));
	Assert.assertEquals("{}", features.toString());
}
 
Example 19
Source Project: amr   Source File: AttachmentFeaturesTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test7() {
	final AttachmentFeatures<Sentence> fs = new AttachmentFeatures<>(1.0,
			LogicLanguageServices.getTypeRepository()
					.getTypeCreateIfNeeded("<e,t>"), 1000, 10);

	final IHashVector features = HashVectorFactory.create();
	fs.setFeatures(
			createParseStep(
					TestServices
							.getCategoryServices()
							.read("N : (lambda $0:<e,t> (lambda $1:e (and:<t*,t> ($0 $1) (c_ARG1-of:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id "
									+ "(lambda $2:e (and:<t*,t> (base-01:<e,t> $2) (c_location:<e,<e,t>> $2 (a:<id,<<e,t>,e>> na:id (lambda $2:e (type:<e,t> $2)))))))))))"),
					TestServices
							.getCategoryServices()
							.read("N : (lambda $0:<<e,t>,<e,t>> (lambda $1:<e,t> (lambda $2:e (and:<t*,t> ($0 (lambda $3:e ($1 $3)) $2) (c_REL:<e,<i,t>> $2 50:i)))))"),
					TestServices
							.getCategoryServices()
							.read("N : (lambda $0:<<e,t>,<e,t>> (lambda $1:e (and:<t*,t> (sponsor-01:<e,t> $1) (c_ARGX:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id (lambda $2:e ($0 (lambda $3:e (expert-41:<e,t> $3)) $2)))))))")),
			features, new Sentence("dummy"));
	Assert.assertEquals(
			"{ATTACH#base-01#c_location=1.000, ATTACH#base-01#c_location#type=1.000, ATTACH#c_ARG1-of#base-01=1.000, ATTACH#c_location#type=1.000}",
			features.toString());
}
 
Example 20
Source Project: amr   Source File: AttachmentFeaturesTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test9() {
	final AttachmentFeatures<Sentence> fs = new AttachmentFeatures<>(1.0,
			LogicLanguageServices.getTypeRepository()
					.getTypeCreateIfNeeded("<e,t>"), 1000, 10);

	final IHashVector features = HashVectorFactory.create();
	fs.setFeatures(
			createParseStep(
					TestServices
							.getCategoryServices()
							.read("N : (lambda $0:e (and:<t*,t> (name:<e,t> $0) (c_REL:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $1:e (and:<t*,t> (and:<e,t> $1) "
									+ "(c_op1:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id (lambda $2:e (and:<t*,t> (c_op:<e,<txt,t>> $2 Zvezda:txt) (spaceship:<e,t> $2))))) "
									+ "(c_op2:<e,<e,t>> $1 (a:<id,<<e,t>,e>> na:id (lambda $3:e (and:<t*,t> (c_op:<e,<txt,t>> $3 Zarya:txt) (spaceship:<e,t> $3)))))))))))"),
					TestServices
							.getCategoryServices()
							.read("N : (lambda $0:e (and:<t*,t> (name:<e,t> $0) (c_REL:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $1:e (and:<t*,t> (c_op:<e,<txt,t>> $1 Zvezda:txt) (spaceship:<e,t> $1)))))))"),
					TestServices
							.getCategoryServices()
							.read("N : (conj:<<e,t>,<e,t>> (lambda $0:e (and:<t*,t> (name:<e,t> $0) (c_REL:<e,<e,t>> $0 (a:<id,<<e,t>,e>> na:id (lambda $1:e (and:<t*,t> (c_op:<e,<txt,t>> $1 Zarya:txt) (spaceship:<e,t> $1))))))))")),
			features, new Sentence("dummy"));
	Assert.assertEquals("{}", features.toString());
}
 
Example 21
Source Project: spf   Source File: LogicalConstantTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Before
public void before() {
	originalLLS = LogicLanguageServices.instance();
	try {
		LogicLanguageServices
				.setInstance(new LogicLanguageServices.Builder(
						LogicLanguageServices.getTypeRepository(),
						LogicLanguageServices.getTypeComparator())
						.setUseOntology(true)
						.addConstantsToOntology(
								TestServices.DEFAULT_ONTOLOGY_FILES)
						.setNumeralTypeName("n").closeOntology(true)
						.build());
	} catch (final IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 22
@Override
public LogicalExpression createPartialCoordination(
		LogicalExpression coordinated, LogicalExpression coordinator) {
	// Create a binary predicate from coordinator
	if (!isBaseCoordinator(coordinator)) {
		return null;
	}

	// The type of the coordinated element is generalized to create the
	// coordination predicate
	final Type argType = LogicLanguageServices.getTypeRepository()
			.generalizeType(coordinated.getType());
	final LogicalConstant coordinationPredicate = createPredicate(
			(LogicalConstant) coordinator, 2, argType);

	// Create a literal using the predicate, with a variable as the
	// first argument and 'coordinated' as the second, and wrap the literal
	// with a lambda expression binding the varaible.
	final LogicalExpression[] arguments = new LogicalExpression[2];
	final Variable variable = new Variable(argType);
	arguments[0] = variable;
	arguments[1] = coordinated;
	return new Lambda(variable, new Literal(coordinationPredicate,
			arguments));
}
 
Example 23
@Test
public void testSubExp13() {
	final LogicalExpression appArg = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:e (lambda $1:e (lambda $2:e (and:<t*,t> (b:<e,t> $2) (a:<e,t> P:e) (boo:<e,<e,t>> $0 $1)))))");
	final LogicalExpression subExp = TestServices
			.getCategoryServices()
			.readSemantics(
					"(and:<t*,t> (a:<e,t> P:e) (boo:<e,<e,t>> koo:e loo:e) (b:<e,t> doo:e))");
	final Variable replacementVariable = new Variable(LogicLanguageServices
			.getTypeRepository().getType("<e,<e,<e,t>>>"));
	final LogicalExpression expected = new Literal(replacementVariable,
			ArrayUtils.create(
					TestServices.getCategoryServices().readSemantics(
							"koo:e"),
					TestServices.getCategoryServices().readSemantics(
							"loo:e"),
					TestServices.getCategoryServices().readSemantics(
							"doo:e")));
	Assert.assertEquals(expected, GetApplicationFunction.processSubExp(
			subExp, appArg, replacementVariable));
}
 
Example 24
Source Project: spf   Source File: IncSimplifier.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public LogicalExpression simplify(LogicalExpression exp) {
	if (exp instanceof Literal) {
		final Literal literal = (Literal) exp;
		if (literal.numArgs() == 1
				&& literal.getArg(0) instanceof LogicalConstant
				&& literal.getArg(0).getType() == LogicLanguageServices
						.getTypeRepository().getIndexType()) {
			// If we have a single argument and it's a constant of type
			// index, replace it with a new constant
			final int i = LogicLanguageServices
					.indexConstantToInt((LogicalConstant) literal.getArg(0));
			return LogicLanguageServices.intToIndexConstant(i + 1);
		}
	}
	return exp;
}
 
Example 25
@Test
public void test7() {
	final Variable variable = new Variable(LogicLanguageServices
			.getTypeRepository().getEntityType());
	final LogicalExpression e1 = new Lambda(variable, new Literal(
			LogicalConstant.read("boo:<e,<<e,t>,t>>"), ArrayUtils.create(
					variable,
					new Lambda(variable,
							new Literal(LogicalConstant.read("goo:<e,t>"),
									ArrayUtils.create(variable))))));
	final LogicalExpression e2 = LogicalExpression
			.read("(lambda $0:e (boo:<e,<<e,t>,t>> $0 (lambda $1:e (goo:<e,t> $1))))");
	Assert.assertEquals(e2, e1);
}
 
Example 26
private static Literal createBinaryLiteral(String predicateName,
		LogicalExpression arg1, LogicalExpression arg2, Type returnType) {
	return createBinaryLiteral(
			createConstant(
					predicateName,
					LogicLanguageServices.getTypeRepository()
							.getTypeCreateIfNeeded(
									LogicLanguageServices
											.getTypeRepository()
											.getTypeCreateIfNeeded(
													returnType,
													arg2.getType()),
									arg1.getType())), arg1, arg2);
}
 
Example 27
private Literal parseRelation(StringReader reader, String argKey,
		Variable variable, Map<String, Variable> variables,
		Map<LogicalConstant, Pair<SkolemId, Type>> skolemIDs)
		throws IOException {
	if (!argKey.startsWith(":")) {
		throw new IllegalStateException("Arg not starting with :");
	}
	// Create the predicate. The predicate name is stripped of the
	// leading ':'.
	final String predicateName = createModifierPrediacteName(argKey);

	final char peek = peek(reader);
	if (peek == '"') {
		// Case quoted text.
		final LogicalConstant constant = parseQuote(getNextToken(reader));
		return createBinaryLiteral(predicateName, variable, constant,
				LogicLanguageServices.getTypeRepository()
						.getTruthValueType());
	} else if (peek == '(') {
		// String the opening parenthesis.
		getNextToken(reader);
		final LogicalExpression argInstance = parseInstance(reader,
				variables, skolemIDs);
		return createBinaryLiteral(predicateName, variable, argInstance,
				LogicLanguageServices.getTypeRepository()
						.getTruthValueType());
	} else {
		// Case constant.
		final String token = getNextToken(reader);
		// If this is a reference variable, create an entity anyway. We
		// don't want to have variables used in such cases. References
		// should be resolved using IDs.
		final LogicalExpression arg = createEntity(token);
		return createBinaryLiteral(predicateName, variable, arg,
				LogicLanguageServices.getTypeRepository()
						.getTruthValueType());
	}
}
 
Example 28
Source Project: amr   Source File: AMRServices.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a skolem term predicate, e.g., a:<id,<<e,t>,e>>.
 */
public static LogicalConstant createSkolemPredicate(Type type) {
	final LogicalConstant cached = INSTANCE.skolemPredicatesCache.get(type);

	if (cached != null) {
		return cached;
	}

	final ComplexType predicateType = LogicLanguageServices
			.getTypeRepository().getTypeCreateIfNeeded(
					LogicLanguageServices.getTypeRepository()
							.getTypeCreateIfNeeded(type,
									LogicLanguageServices
											.getTypeRepository()
											.getTypeCreateIfNeeded(
													LogicLanguageServices
															.getTypeRepository()
															.getTruthValueType(),
													type)),
					SkolemServices.getIDType());
	final LogicalConstant predicate = LogicalConstant
			.create(INSTANCE.skolemPredicateBaseName, predicateType, true);

	INSTANCE.skolemPredicatesCache.put(type, predicate);

	return predicate;
}
 
Example 29
Source Project: amr   Source File: AMRServices.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the unary typing predicate (if one exists) from a <e,t>-typed lambda
 * term (the body of a skolem term).
 */
public static LogicalConstant getTypingPredicate(Lambda set) {
	if (set.getBody() instanceof Literal) {
		final Literal bodyLiteral = (Literal) set.getBody();
		final int len = bodyLiteral.numArgs();
		if (bodyLiteral.getPredicate()
				.equals(LogicLanguageServices.getConjunctionPredicate())) {
			return getTypingPredicateFromConjunction(bodyLiteral);
		} else if (len == 1
				&& bodyLiteral.getPredicate() instanceof LogicalConstant) {
			return (LogicalConstant) bodyLiteral.getPredicate();
		}
	}
	return null;
}
 
Example 30
Source Project: amr   Source File: AMRServices.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean isNamedEntityBody(Lambda entityBody) {
	if (entityBody.getComplexType().getDomain()
			.equals(LogicLanguageServices.getTypeRepository()
					.getEntityType())
			&& entityBody.getComplexType().getRange()
					.equals(LogicLanguageServices.getTypeRepository()
							.getTruthValueType())
			&& entityBody.getBody() instanceof Literal) {
		final Literal bodyLiteral = (Literal) entityBody.getBody();
		if (bodyLiteral.getPredicate()
				.equals(LogicLanguageServices.getConjunctionPredicate())) {
			final int len = bodyLiteral.numArgs();
			for (int i = 0; i < len; ++i) {
				final LogicalExpression arg = bodyLiteral.getArg(i);
				if (arg instanceof Literal && ((Literal) arg).numArgs() == 2
						&& ((Literal) arg).getArg(1) instanceof Literal
						&& isSkolemTerm(
								(Literal) ((Literal) arg).getArg(1))) {
					if (INSTANCE.nameInstancePredicate
							.equals(getTypingPredicate(
									(Literal) ((Literal) arg).getArg(1)))) {
						return true;
					}
				}
			}
		}
	}
	return false;
}