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

The following examples show how to use edu.cornell.cs.nlp.spf.mr.lambda.visitor.HasFreeVariables. 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: HasFreeVariablesTest.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() {
	final LogicalExpression exp = LogicalExpression
			.read("(lambda $0:e (pred1:<e,<e,t>> $0 (a:<<e,t>,e> (lambda $1:e (pred2:<e,t> $1)))))");
	Assert.assertFalse(HasFreeVariables.of(exp));
	Assert.assertTrue(HasFreeVariables.of(((Lambda) exp).getBody()));
}
 
Example #2
Source File: LogicalExpressionSimpleIndenter.java    From UDepLambda with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(Literal literal) {
	final int len = literal.numArgs();
	 TypeRepository typeRepository = LogicLanguageServices
		        .getTypeRepository();
	
	if (LogicLanguageServices.isCoordinationPredicate(literal
			.getPredicate())
			// TODO: Fix this hack. Figure out how 
			|| literal.getPredicate().equals(AND_c)) {
		outputString.append("(");
		literal.getPredicate().accept(this);
		// Visit the arguments to print them. Print a space before each
		// argument.
		++currentDepth;
		for (int i = 0; i < len; ++i) {
			outputString.append("\n"
					+ StringUtils.multiply(indentation, currentDepth));
			literal.getArg(i).accept(this);
		}
		--currentDepth;
		outputString.append(')');
	} else if (literal.getPredicate().equals(EX_ex)) {
		outputString.append("(");
		literal.getPredicate().accept(this);
		// Visit the arguments to print them. Print a space before each
		// argument.
		outputString.append(' ');
		literal.getArg(0).accept(this); // the variable
		
		++currentDepth;
		for (int i = 1; i < len; ++i) {
			outputString.append("\n"
					+ StringUtils.multiply(indentation, currentDepth));
			literal.getArg(i).accept(this);
		}
		--currentDepth;
		outputString.append(')');
	} else if (!HasFreeVariables.of(literal, true)
			&& outputString.length() > 0) {
		++currentDepth;
		outputString.append("\n"
				+ StringUtils.multiply(indentation, currentDepth));
		outputString.append("(");
		literal.getPredicate().accept(this);
		// Visit the arguments to print them. Print a space before each
		// argument.
		// ++currentDepth;
		for (int i = 0; i < len; ++i) {
			// outputString.append("\n"
			// + StringUtils.multiply(indentation, currentDepth));
			outputString.append(' ');
			literal.getArg(i).accept(this);
		}
		// --currentDepth;
		--currentDepth;
		outputString.append(')');
	} else {
		outputString.append("(");
		literal.getPredicate().accept(this);
		// Visit the arguments to print them. Print a space before each
		// argument.
		for (int i = 0; i < len; ++i) {
			outputString.append(' ');
			literal.getArg(i).accept(this);
		}
		outputString.append(')');
	}
}
 
Example #3
Source File: AMRSupervisedFilter.java    From amr with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see CollectStats#typeRelatedTypeTriplets
 * @see TypeRelatedTypeTriplet
 */
private void countInstanceTypeRelatedTypeTriplets(
		Literal conjunctionLiteral) {
	// Can collect triplets only from conjunctions with multiple
	// conjuncts.
	final int conjLiteralNumArgs = conjunctionLiteral.numArgs();
	if (conjLiteralNumArgs > 1) {
		// Try to get the typing predicate if one exists.
		final LogicalConstant typingPredicate = OverloadedLogicalConstant
				.getWrapped(
						AMRServices.getTypingPredicateFromConjunction(
								conjunctionLiteral));
		if (typingPredicate == null
				|| !constantFilter.test(typingPredicate)) {
			return;
		}

		// For every binary relation, create a triplet if the second
		// argument has no free variables.
		for (int i = 0; i < conjLiteralNumArgs; ++i) {
			final LogicalExpression arg = conjunctionLiteral.getArg(i);
			if (arg instanceof Literal && ((Literal) arg).numArgs() == 2
					&& ((Literal) arg)
							.getPredicate() instanceof LogicalConstant
					&& !HasFreeVariables.of(((Literal) arg).getArg(1),
							true)) {
				final LogicalExpression arg2 = ((Literal) arg)
						.getArg(1);
				final LogicalConstant relation = OverloadedLogicalConstant
						.getWrapped((LogicalConstant) ((Literal) arg)
								.getPredicate());
				if (arg2 instanceof Literal
						&& AMRServices.isSkolemTerm((Literal) arg2)) {
					final LogicalConstant arg2TypingPredicate = OverloadedLogicalConstant
							.getWrapped(AMRServices.getTypingPredicate(
									(Literal) arg2));
					if (arg2TypingPredicate != null && constantFilter
							.test(arg2TypingPredicate)) {
						count(new TypeRelatedTypeTriplet(
								typingPredicate, relation,
								arg2TypingPredicate),
								typeRelatedTypeTriplets,
								typeRelatedTypeTripletsRef);
						if (!isValid) {
							return;
						}
					}
				} else if (arg2 instanceof LogicalConstant) {
					final LogicalConstant arg2Const = OverloadedLogicalConstant
							.getWrapped((LogicalConstant) arg2);
					if (constantFilter.test(arg2Const)) {
						count(new TypeRelatedTypeTriplet(
								typingPredicate, relation, arg2Const),
								typeRelatedTypeTriplets,
								typeRelatedTypeTripletsRef);
						if (!isValid) {
							return;
						}
					}
				} else if (arg2 instanceof Literal
						&& AMRServices.isRefPredicate(
								((Literal) arg2).getPredicate())) {
					count(new TypeRelatedTypeTriplet(typingPredicate,
							relation, ((Literal) arg2).getPredicate()),
							typeRelatedTypeTriplets,
							typeRelatedTypeTripletsRef);
					if (!isValid) {
						return;
					}
				}
			}
		}
	}
}
 
Example #4
Source File: LogicalExpressionToIndentedString.java    From spf with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(Literal literal) {
	final int len = literal.numArgs();
	if (LogicLanguageServices.isCoordinationPredicate(literal
			.getPredicate())) {
		outputString.append("(");
		literal.getPredicate().accept(this);
		// Visit the arguments to print them. Print a space before each
		// argument.
		++currentDepth;
		for (int i = 0; i < len; ++i) {
			outputString.append("\n"
					+ StringUtils.multiply(indentation, currentDepth));
			literal.getArg(i).accept(this);
		}
		--currentDepth;
		outputString.append(')');
	} else if (!HasFreeVariables.of(literal, true)
			&& outputString.length() > 0) {
		++currentDepth;
		outputString.append("\n"
				+ StringUtils.multiply(indentation, currentDepth));
		outputString.append("(");
		literal.getPredicate().accept(this);
		// Visit the arguments to print them. Print a space before each
		// argument.
		// ++currentDepth;
		for (int i = 0; i < len; ++i) {
			// outputString.append("\n"
			// + StringUtils.multiply(indentation, currentDepth));
			outputString.append(' ');
			literal.getArg(i).accept(this);
		}
		// --currentDepth;
		--currentDepth;
		outputString.append(')');
	} else {
		outputString.append("(");
		literal.getPredicate().accept(this);
		// Visit the arguments to print them. Print a space before each
		// argument.
		for (int i = 0; i < len; ++i) {
			outputString.append(' ');
			literal.getArg(i).accept(this);
		}
		outputString.append(')');
	}
}