本文整理汇总了Java中edu.cornell.cs.nlp.spf.mr.lambda.visitor.HasFreeVariables类的典型用法代码示例。如果您正苦于以下问题:Java HasFreeVariables类的具体用法?Java HasFreeVariables怎么用?Java HasFreeVariables使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HasFreeVariables类属于edu.cornell.cs.nlp.spf.mr.lambda.visitor包,在下文中一共展示了HasFreeVariables类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import edu.cornell.cs.nlp.spf.mr.lambda.visitor.HasFreeVariables; //导入依赖的package包/类
@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()));
}
示例2: visit
import edu.cornell.cs.nlp.spf.mr.lambda.visitor.HasFreeVariables; //导入依赖的package包/类
@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(')');
}
}
示例3: visit
import edu.cornell.cs.nlp.spf.mr.lambda.visitor.HasFreeVariables; //导入依赖的package包/类
@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(')');
}
}
示例4: countInstanceTypeRelatedTypeTriplets
import edu.cornell.cs.nlp.spf.mr.lambda.visitor.HasFreeVariables; //导入依赖的package包/类
/**
* @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;
}
}
}
}
}
}