edu.cornell.cs.nlp.spf.mr.lambda.visitor.Simplify Java Examples
The following examples show how to use
edu.cornell.cs.nlp.spf.mr.lambda.visitor.Simplify.
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: SimpleLogicalExpressionReader.java From UDepLambda with Apache License 2.0 | 5 votes |
public static LogicalExpression read(String string) { TypeRepository typeRepository = LogicLanguageServices .getTypeRepository(); ITypeComparator typeComparator = LogicLanguageServices .getTypeComparator(); LogicalExpression exp = LogicalExpressionReader.INSTANCE.read(string, new ScopeMapping<>(), typeRepository, typeComparator); return Simplify.of(exp); }
Example #2
Source File: MakeCompositionSplits.java From spf with GNU General Public License v2.0 | 5 votes |
private SplittingPair createSplittingPair(Lambda f, LogicalExpression g) { // Simplify f and g final LogicalExpression simplifiedF = Simplify.of(f); final LogicalExpression simlifiedG = Simplify.of(g); // Create the categories for the composition final Slash slash = originalCategory.getSlash(); final Category<LogicalExpression> sharedCategory = Category .create(SplittingServices.typeToSyntax(simplifiedF.getType() .getDomain())); final ComplexCategory<LogicalExpression> fCategory = new ComplexCategory<LogicalExpression>( new ComplexSyntax(originalCategory.getSyntax().getLeft(), sharedCategory.getSyntax(), slash), simplifiedF); final ComplexCategory<LogicalExpression> gCategory = new ComplexCategory<LogicalExpression>( new ComplexSyntax(sharedCategory.getSyntax(), originalCategory .getSyntax().getRight(), slash), simlifiedG); // Create the splitting pair. Don't allow crossing composition final SplittingPair newSplit; if (slash == Slash.BACKWARD) { // Cator goes on right newSplit = new SplittingPair(gCategory, fCategory); } else { // Cator goes on left newSplit = new SplittingPair(fCategory, gCategory); } // Error checking final Category<LogicalExpression> composed = categoryServices.compose( fCategory, gCategory, 1, false); if (!originalCategory.equals(composed)) { LOG.error("ERROR: bad Cat composition split"); LOG.error("%s ---> %s != %s", newSplit, composed, originalCategory); } return newSplit; }
Example #3
Source File: AToExistsTest.java From spf with GNU General Public License v2.0 | 5 votes |
@Test public void test11() { final LogicalExpression exp = LogicalExpression .read("(lambda $0:e (a:<<e,t>,e> (lambda $1:e (boo:<e,<e,t>> $1 $0))))"); final LogicalExpression result = LogicalExpression .read("(lambda $0:e (exists:<<e,t>,t> (lambda $1:e (boo:<e,<e,t>> $1 $0))))"); final LogicalExpression out = AToExists.of(exp, existsPredicate, aPredicate, equalsPredicates); Assert.assertEquals(Simplify.of(result), out); }
Example #4
Source File: AToExistsTest.java From spf with GNU General Public License v2.0 | 5 votes |
@Test public void test7() { final LogicalExpression exp = LogicalExpression .read("(fun:<e,e> (a:<<e,t>,e> (lambda $0:e true:t)))"); final LogicalExpression result = LogicalExpression .read("(lambda $0:e (exists:<<e,t>,t> (lambda $1:e (and:<t*,t> true:t (eq:<e,<e,t>> $0 (fun:<e,e> $1))))))"); final LogicalExpression out = AToExists.of(exp, existsPredicate, aPredicate, equalsPredicates); Assert.assertEquals(Simplify.of(result), out); }
Example #5
Source File: AToExistsTest.java From spf with GNU General Public License v2.0 | 5 votes |
@Test public void test8() { final LogicalExpression exp = LogicalExpression .read("(fun:<e,e> (a:<<e,t>,e> (lambda $0:e (pred:<e,t> $0))))"); final LogicalExpression result = LogicalExpression .read("(lambda $1:e (exists:<<e,t>,t> (lambda $0:e (and:<t*,t> (pred:<e,t> $0) (eq:<e,<e,t>> $1 (fun:<e,e> $0)))))))"); final LogicalExpression out = AToExists.of(exp, existsPredicate, aPredicate, equalsPredicates); Assert.assertEquals(Simplify.of(result), out); }
Example #6
Source File: AToExistsTest.java From spf with GNU General Public License v2.0 | 5 votes |
@Test public void test9() { final LogicalExpression exp = LogicalExpression .read("(lambda $0:e (a:<<e,t>,e> (lambda $1:e (boo:<e,<e,t>> $1 $0))))"); final LogicalExpression result = LogicalExpression .read("(lambda $0:e (exists:<<e,t>,t> (lambda $1:e (boo:<e,<e,t>> $1 $0))))"); final LogicalExpression out = AToExists.of(exp, existsPredicate, aPredicate, equalsPredicates); Assert.assertEquals(Simplify.of(result), out); }
Example #7
Source File: LogicalExpressionCategoryServices.java From spf with GNU General Public License v2.0 | 5 votes |
@Override public LogicalExpression readSemantics(String string, boolean checkType) { final LogicalExpression exp = LogicalExpression.read(string); if (checkType) { final Pair<Boolean, String> typeChecking = IsTypeConsistent .ofVerbose(exp); if (!typeChecking.first()) { throw new IllegalStateException("Semantics not well typed [" + typeChecking.second() + "]: " + string); } } return Simplify.of(exp); }
Example #8
Source File: LogicalExpressionCoordinationServices.java From spf with GNU General Public License v2.0 | 5 votes |
@Override public LogicalExpression createSimpleCoordination( LogicalExpression coordinated, LogicalExpression coordinator) { // Create a binary predicate from coordinator if (!isBaseCoordinator(coordinator)) { return null; } if (LogicLanguageServices.getTypeRepository().getTruthValueType() .equals(coordinated.getType())) { // Case coordinating truth-typed expressions final LogicalExpression coordinationPredicate; if (isConjunctionCoordinator((LogicalConstant) coordinator)) { coordinationPredicate = LogicLanguageServices .getConjunctionPredicate(); } else if (isDisjunctionCoordinator((LogicalConstant) coordinator)) { coordinationPredicate = LogicLanguageServices .getDisjunctionPredicate(); } else { throw new IllegalStateException("invalid coordinator: " + coordinator); } final Variable variable = new Variable(LogicLanguageServices .getTypeRepository().getTruthValueType()); final LogicalExpression[] args = new LogicalExpression[2]; args[0] = variable; args[1] = coordinated; return Simplify.of(new Literal(coordinationPredicate, args)); } return null; }
Example #9
Source File: SententialAdverbialTypeShifting.java From spf with GNU General Public License v2.0 | 4 votes |
/** * (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 #10
Source File: AbstractShiftingRule.java From spf with GNU General Public License v2.0 | 4 votes |
/** * (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 #11
Source File: MakeApplicationSplits.java From spf with GNU General Public License v2.0 | 4 votes |
public static Set<SplittingPair> createAllSplittingPairs( Category<LogicalExpression> rootCategory, LogicalExpression functor, LogicalExpression functee, ICategoryServices<LogicalExpression> categoryServices) { // Simplify the functee and functor final LogicalExpression simplifiedFunctor = Simplify.of(functor); final LogicalExpression simplifiedFunctee = Simplify.of(functee); // make the category that will be pulled out final Category<LogicalExpression> functeeCategory = makeCategoryFor(simplifiedFunctee); // now, make the categories. the split can be either a forward // application or a backward application final SplittingPair forwardSplit; final ComplexCategory<LogicalExpression> forwardCategory = new ComplexCategory<LogicalExpression>( new ComplexSyntax(rootCategory.getSyntax(), functeeCategory.getSyntax(), Slash.FORWARD), simplifiedFunctor); forwardSplit = new SplittingPair(forwardCategory, functeeCategory); // error check. do the two pieces recombine to make the original // category? final Category<LogicalExpression> applyCat = categoryServices.apply( forwardCategory, functeeCategory); if (!rootCategory.equals(applyCat)) { LOG.error("ERROR: bad forward split"); LOG.error("%s --> %s == %s != %s", forwardCategory, functeeCategory, applyCat, rootCategory); } final SplittingPair backSplit; final ComplexCategory<LogicalExpression> backCategory = new ComplexCategory<LogicalExpression>( new ComplexSyntax(rootCategory.getSyntax(), functeeCategory.getSyntax(), Slash.BACKWARD), simplifiedFunctor); backSplit = new SplittingPair(functeeCategory, backCategory); // error check. do the two pieces recombine to make the original // category? final Category<LogicalExpression> applyCat2 = categoryServices.apply( backCategory, functeeCategory); if (!rootCategory.equals(applyCat2)) { LOG.error("ERROR: bad backward split"); LOG.error("%s --> %s == %s != %s", functeeCategory, backCategory, applyCat2, rootCategory); } final Set<SplittingPair> newSplits = new HashSet<SplittingServices.SplittingPair>(); newSplits.add(forwardSplit); newSplits.add(backSplit); return newSplits; }