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

The following examples show how to use edu.cornell.cs.nlp.spf.mr.lambda.LogicLanguageServices. 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: AMRSupervisedFilterFactory.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@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 #2
Source File: AttachmentFeaturesTest.java    From amr with 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 #3
Source File: AttachmentFeaturesTest.java    From amr with 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 #4
Source File: SkolemIDRuleTest.java    From spf with 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
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@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 File: AttachmentFeaturesTest.java    From amr with 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 #7
Source File: DummyEntityServices.java    From amr with 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 #8
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@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 #9
Source File: LogicalConstantTest.java    From spf with 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 #10
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@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 #11
Source File: NamedEntityKeywordCoordination.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@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 #12
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@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 #13
Source File: LogicalExpressionCoordinationServices.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@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 #14
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@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 #15
Source File: AttachmentFeaturesTest.java    From amr with 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 #16
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@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 #17
Source File: ExtractTypedSubExpressionTest.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@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 #18
Source File: ExtractTypedSubExpressionTest.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@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 #19
Source File: ExtractTypedSubExpressionTest.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@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 #20
Source File: AbstractEvaluationServices.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@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 #21
Source File: ExtractTypedSubExpressionTest.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@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 #22
Source File: IncSimplifier.java    From spf with 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 #23
Source File: ExtractTypedSubExpressionTest.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@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 #24
Source File: LogicalExpressionApplicationTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@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 #25
Source File: GetApplicationArgumentTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testCreateArg1() {
	final LogicalExpression resultSubExp = TestServices
			.getCategoryServices().readSemantics("boo:e");
	final Variable applicationArg = new Variable(
			LogicLanguageServices.getTypeRepository().getEntityType());
	Assert.assertEquals(resultSubExp,
			GetApplicationArgument.createArgument(resultSubExp,
					applicationArg, applicationArg,
					new ScopeMapping<Variable, Variable>()));

}
 
Example #26
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSubExp5() {
	final LogicalExpression appArg = TestServices.getCategoryServices()
			.readSemantics("(lambda $0:e (boo:<e,t> $0))");
	final LogicalExpression subExp = TestServices.getCategoryServices()
			.readSemantics("(boo:<e,t> koo:e)");
	final Variable replacementVariable = new Variable(LogicLanguageServices
			.getTypeRepository().getType("<e,t>"));
	final LogicalExpression expected = new Literal(replacementVariable,
			ArrayUtils.create(TestServices.getCategoryServices()
					.readSemantics("koo:e")));
	Assert.assertEquals(expected, GetApplicationFunction.processSubExp(
			subExp, appArg, replacementVariable));
}
 
Example #27
Source File: GetApplicationFunctionTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSubExp1() {
	final LogicalExpression appArg = TestServices.getCategoryServices()
			.readSemantics("boo:e");
	final LogicalExpression subExp = TestServices.getCategoryServices()
			.readSemantics("boo:e");
	final Variable replacementVariable = new Variable(LogicLanguageServices
			.getTypeRepository().getType("e"));
	final LogicalExpression expected = replacementVariable;
	Assert.assertEquals(expected, GetApplicationFunction.processSubExp(
			subExp, appArg, replacementVariable));
}
 
Example #28
Source File: LogicalExpressionTypingTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test1() {
	final LogicalExpression exp = TestServices.CATEGORY_SERVICES
			.readSemantics("(lambda $0:e (intersect:<<e,t>*,<e,t>> (lambda $1:e (chair:<e,t> $1)) (lambda $2:e (front:<<e,t>,<e,t>> (lambda $3:e (at:<e,t> $3)) $2)) $0))");
	assertEquals(
			LogicLanguageServices.getTypeRepository().getType("<e,t>"),
			exp.getType());

}
 
Example #29
Source File: TemplateCoarseGenlex.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
private Set<LogicalConstant> createAbstractConstants() {
	final Set<LogicalConstant> abstractConstants = new HashSet<LogicalConstant>();
	for (final LogicalConstant constant : constants) {
		final Type type = LogicLanguageServices.getTypeRepository()
				.generalizeType(constant.getType());
		abstractConstants.add(LogicalConstant
				.createDynamic(CONST_SEED_NAME, type, true));
	}
	return abstractConstants;
}
 
Example #30
Source File: StructureOnlyComaprator.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Override
public StructureOnlyComaprator create(Parameters params,
		IResourceRepository repo) {
	return new StructureOnlyComaprator(
			params.contains("comparator") ? (ILogicalExpressionComparator) repo
					.get("comparator") : LogicLanguageServices
					.getComparator());
}