Java Code Examples for edu.cornell.cs.nlp.spf.mr.lambda.Lambda#getArgument()

The following examples show how to use edu.cornell.cs.nlp.spf.mr.lambda.Lambda#getArgument() . 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: GetMapping.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visit(LambdaNode node) {
	final Lambda resultLambda = (Lambda) currentResult;

	// Visit the argument.
	currentResult = resultLambda.getArgument();
	node.getArgument().accept(this);

	if (fail) {
		return;
	}

	// Visit the body.
	currentResult = resultLambda.getBody();
	node.getBody().accept(this);
}
 
Example 2
Source File: ApplyAndSimplify.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Does apply-and-simplify without replacing any free variables. This method
 * should be used with extreme caution.
 */
static LogicalExpression ofUnsafe(LogicalExpression func,
		LogicalExpression arg) {
	// Verify type matching. The functor must be have a complex type, and
	// need to be in some kind of parent-child relationship with the
	// argument, as we allow flexible typing syntax-wise.
	if (!func.getType().isComplex()
			|| !LogicLanguageServices.getTypeComparator().verifyArgType(
					func.getType().getDomain(), arg.getType())) {
		// Case typing mismatch
		return null;
	} else if (func instanceof Lambda) {
		// Case the functor is a Lambda expression
		final Lambda lambda = (Lambda) func;
		final Variable variable = lambda.getArgument();

		final ApplyAndSimplify visitor = new ApplyAndSimplify(arg, variable);

		visitor.visit(lambda.getBody());

		return visitor.result;
	} else if (func instanceof Literal) {
		// Case the functor is a literal, append the argument to
		// the end of the arguments list
		return Simplify.of(literalApplication((Literal) func, arg));
	} else if (func instanceof Term) {
		// Case the functor is a variable or logical constant,
		// create the a literal with the functor as predicate and the
		// argument as the only argument in the argument list
		return Simplify.of(termApplication((Term) func, arg));
	} else {
		// Should never happen
		throw new LogicalExpressionRuntimeException(
				"Impossible condition: un-handled logical expression object");
	}
}
 
Example 3
Source File: SententialAdverbialTypeShifting.java    From spf with GNU General Public License v2.0 4 votes vote down vote up
/**
 * (lambda $0:x (g $0)) ==> (lambda $0:<x,t> (lambda $1:x (and:<t*,t> ($0
 * $1) (g $1))))
 */
protected LogicalExpression typeShiftSemantics(LogicalExpression sem) {
	final Type semType = sem.getType();
	final Type range = semType.getRange();

	if (semType.isComplex()
			&& range.equals(LogicLanguageServices.getTypeRepository()
					.getTruthValueType())) {

		// Make sure the expression is wrapped with lambda operators, since
		// the variables are required
		final Lambda lambda = (Lambda) sem;

		// Variable for the new outer lambda
		final Variable outerVariable = new Variable(LogicLanguageServices
				.getTypeRepository().getTypeCreateIfNeeded(
						LogicLanguageServices.getTypeRepository()
								.getTruthValueType(),
						lambda.getArgument().getType()));

		// Create the literal applying the function to the original
		// argument
		final LogicalExpression[] args = new LogicalExpression[1];
		args[0] = lambda.getArgument();
		final Literal newLiteral = new Literal(outerVariable, args);

		// Create the conjunction of newLitral and the original body
		final Literal conjunction = new Literal(
				LogicLanguageServices.getConjunctionPredicate(),
				ArrayUtils.create(newLiteral, lambda.getBody()));

		// The new inner lambda
		final Lambda innerLambda = new Lambda(lambda.getArgument(),
				conjunction);

		// The new outer lambda
		final Lambda outerLambda = new Lambda(outerVariable, innerLambda);

		// Simplify the output and return it
		final LogicalExpression ret = Simplify.of(outerLambda);

		return ret;
	}

	return null;
}
 
Example 4
Source File: AbstractShiftingRule.java    From spf with GNU General Public License v2.0 4 votes vote down vote up
/**
 * (lambda $0:x (g $0)) ==> (lambda $0:<x,t> (lambda $1:x (and:<t*,t> ($0
 * $1) (g $1))))
 */
protected LogicalExpression typeShiftSemantics(LogicalExpression sem) {
	final Type semType = sem.getType();
	final Type range = semType.getRange();

	if (semType.isComplex() && range.equals(LogicLanguageServices
			.getTypeRepository().getTruthValueType())) {

		// Make sure the expression is wrapped with lambda operators, since
		// the variables are required
		final Lambda lambda = (Lambda) sem;

		// Variable for the new outer lambda
		final Variable outerVariable = new Variable(LogicLanguageServices
				.getTypeRepository().getTypeCreateIfNeeded(
						LogicLanguageServices.getTypeRepository()
								.getTruthValueType(),
						lambda.getArgument().getType()));

		// Create the literal applying the function to the original
		// argument
		final LogicalExpression[] args = new LogicalExpression[1];
		args[0] = lambda.getArgument();
		final Literal newLiteral = new Literal(outerVariable, args);

		// Create the conjunction of newLitral and the original body
		final Literal conjunction = new Literal(
				LogicLanguageServices.getConjunctionPredicate(),
				ArrayUtils.create(newLiteral, lambda.getBody()));

		// The new inner lambda
		final Lambda innerLambda = new Lambda(lambda.getArgument(),
				conjunction);

		// The new outer lambda
		final Lambda outerLambda = new Lambda(outerVariable, innerLambda);

		// Simplify the output and return it
		final LogicalExpression ret = Simplify.of(outerLambda);

		return ret;
	}

	return null;
}