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

The following examples show how to use edu.cornell.cs.nlp.spf.mr.lambda.Literal. 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: 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 #2
Source File: PostProcessLogicalForm.java    From UDepLambda with Apache License 2.0 6 votes vote down vote up
/**
 * From a given logical expression, the main predicates are extracted, make
 * them more readable, link the variables to the sources from which they
 * originated.
 * 
 * @param sentence the source sentence
 * @param parse the logical expression to be processed
 * @param lexicalizePredicates lexicalize predicates by appending the event,
 *        e.g., eat(1:e) ^ arg1(1:e , 1:x) becomes eat.arg1(1:e , 1:x)
 * @return the set of main predicates in readable format
 */
public static Set<String> process(Sentence sentence, LogicalExpression parse,
    boolean lexicalizePredicates) {
  List<Literal> mainPredicates = new ArrayList<>();
  Map<Term, List<Integer>> varToEvents = new HashMap<>();
  Map<Term, List<Integer>> varToEntities = new HashMap<>();
  Map<Term, List<Term>> varToConj = new HashMap<>();
  List<Pair<Term, Term>> equalPairs = new ArrayList<>();
  process(mainPredicates, varToEvents, varToEntities, varToConj, equalPairs,
      sentence, parse);

  // TODO(sivareddyg) handle predicates p_CONJ and p_EQUAL in both varToEvents
  // and varToEntities.
  cleanVarToEntities(varToEntities, sentence);
  cleanVarToEvents(varToEvents, sentence);
  populateConj(varToConj, varToEntities, varToEvents);
  populateEquals(equalPairs, varToEntities, varToEvents);
  Set<String> cleanedPredicates =
      createCleanPredicates(mainPredicates, varToEvents, varToEntities,
          sentence, lexicalizePredicates);
  return cleanedPredicates;
}
 
Example #3
Source File: GetPredicateCounts.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visit(Literal literal) {
	if (literal.getPredicate() instanceof LogicalConstant) {
		if (!predicates.containsKey(literal.getPredicate())) {
			predicates.put((LogicalConstant) literal.getPredicate(),
					new Counter());
		}
		predicates.get(literal.getPredicate()).inc();
	}

	literal.getPredicate().accept(this);
	final int len = literal.numArgs();
	for (int i = 0; i < len; ++i) {
		literal.getArg(i).accept(this);
	}
}
 
Example #4
Source File: PostProcessLogicalForm.java    From UDepLambda with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the main predicates, i.e., the predicates that start with p_.
 * 
 * @param parse
 * @param predicates
 */
public static void getMainPredicates(LogicalExpression parse,
    List<Literal> predicates) {
  if (parse instanceof Lambda) {
    getMainPredicates(((Lambda) parse).getBody(), predicates);
  } else if (parse instanceof Literal) {
    if (((Literal) parse).getPredicate().toString().startsWith("p_")) {
      // System.out.println(parse);
      predicates.add((Literal) parse);
      ((Literal) parse).getArg(0).hashCode();
    } else {
      for (int i = 0; i < ((Literal) parse).numArgs(); i++) {
        getMainPredicates(((Literal) parse).getArg(i), predicates);
      }
    }
  }
}
 
Example #5
Source File: GetApplicationArgumentTest.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testCreateArg4() {
	final LogicalExpression resultSubExp = TestServices
			.getCategoryServices().readSemantics("(pred:<e,t> $0:e)");
	final LogicalExpression functionSubExp = TestServices
			.getCategoryServices().readSemantics("($1:<e,t> $0:e)");
	final Variable applicationArg = (Variable) ((Literal) functionSubExp)
			.getPredicate();
	final LogicalExpression expected = TestServices.getCategoryServices()
			.readSemantics("pred:<e,t>");
	final ScopeMapping<Variable, Variable> scope = new ScopeMapping<Variable, Variable>();
	scope.push((Variable) ((Literal) functionSubExp).getArg(0),
			(Variable) ((Literal) resultSubExp).getArg(0));
	Assert.assertEquals(expected, GetApplicationArgument.createArgument(
			resultSubExp, functionSubExp, applicationArg, scope));

}
 
Example #6
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 #7
Source File: AbstractCoordinationCXRule.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ParseRuleResult<LogicalExpression> apply(
		Category<LogicalExpression> left,
		Category<LogicalExpression> right, SentenceSpan span) {
	final CoordinationSyntax unification = CoordinationServices
			.unifyCategories(left, right);
	if (unification != null) {
		final Category<LogicalExpression> resultCategory = doApply(
				ReplaceFreeVariablesIfPresent.of(left.getSemantics(), right
						.getSemantics().getFreeVariables()),
				(Literal) right.getSemantics(),
				unification.getCoordinatedSyntax(),
				(LogicalConstant) ((Literal) right.getSemantics())
						.getPredicate());
		if (resultCategory != null) {
			return new ParseRuleResult<>(ruleName, resultCategory);
		}
	}

	return null;
}
 
Example #8
Source File: CoordinationC2Rule.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
protected ParseRuleResult<LogicalExpression> doApply(
		LogicalExpression left, Literal right, CoordinationSyntax syntax) {
	final Type baseType = right.getType();

	// Create the argument list and the new semantic form.
	final int numArgs = right.numArgs();
	final LogicalExpression[] arguments = new LogicalExpression[numArgs + 1];
	// Make sure there's no free variable overlap.
	arguments[0] = ReplaceFreeVariablesIfPresent.of(left,
			right.getFreeVariables());
	right.copyArgsIntoArray(arguments, 0, 1, numArgs);

	// Create the return category, including the syntactic
	// component.
	final Category<LogicalExpression> resultCategory = Category
			.<LogicalExpression> create(syntax, CoordinationServices
					.createLiteral(((LogicalConstant) right.getPredicate())
							.getBaseName(), arguments, baseType));

	return new ParseRuleResult<>(ruleName, resultCategory);
}
 
Example #9
Source File: ExtractTypedSubExpression.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visit(Literal literal) {
	increaseDepth();
	boolean literalHasOnlyVariables = true;
	literal.getPredicate().accept(this);
	literalHasOnlyVariables &= variablesOnly;
	final int len = literal.numArgs();
	for (int i = 0; i < len; ++i) {
		literal.getArg(i).accept(this);
		literalHasOnlyVariables &= variablesOnly;
	}
	--depth;

	if (!literalHasOnlyVariables
			&& (!skipCoordinations || !LogicLanguageServices
					.isCoordinationPredicate(literal.getPredicate()))) {
		addCurrent(literal);
	}
}
 
Example #10
Source File: NounPhraseWithDummy.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)) {
		final Pair<Literal, LogicalConstant> pair = DummyEntityServices
				.stripDummy((Literal) category.getSemantics());
		if (pair != null) {
			final LogicalConstant inversedRelation = AMRServices
					.makeRelationPassive(pair.second(), true);
			if (inversedRelation != null) {
				return new ParseRuleResult<>(name, Category.create(
						targetSyntax, categoryServices.apply(
								categoryServices.apply(helperCategory,
										inversedRelation), pair.first())));
			}
		}
	}
	return null;
}
 
Example #11
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 #12
Source File: SemanticShiftingFeatureSet.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setFeatures(IParseStep<LogicalExpression> step,
		IHashVector feats, DI dataItem) {
	if (step instanceof IOverloadedParseStep) {
		final UnaryRuleName rule = ((IOverloadedParseStep<LogicalExpression>) step)
				.getRuleName().getUnaryRule();
		final LogicalExpression semantics = ((IOverloadedParseStep<LogicalExpression>) step)
				.getIntermediate().getSemantics();
		if (semantics != null) {
			final LogicalConstant instanceType;
			if (AMRServices.isSkolemTerm(semantics)) {
				instanceType = AMRServices
						.getTypingPredicate((Literal) semantics);
			} else if (AMRServices.isSkolemTermBody(semantics)) {
				instanceType = AMRServices
						.getTypingPredicate((Lambda) semantics);
			} else {
				return;
			}
			if (instanceType != null) {
				feats.set(tag, rule.toString(), instanceType.getBaseName(),
						1.0 * scale);
			}
		}
	}
}
 
Example #13
Source File: Evaluation.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
protected boolean isPartialLiteral(Literal literal) {
	// Count number of arguments on predicate type
	Type type = literal.getPredicateType();
	int numArgs = 0;
	while (type.isComplex()) {
		if (type instanceof RecursiveComplexType) {
			numArgs += ((RecursiveComplexType) type).getMinArgs();
			type = ((RecursiveComplexType) type).getFinalRange();
		} else {
			++numArgs;
			type = type.getRange();
		}
	}

	return literal.numArgs() < numArgs;
}
 
Example #14
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 #15
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 #16
Source File: ExtractTypedSubExpressionTest.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test6() {
	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:t"), LogicLanguageServices.getTypeRepository()
			.getTypeCreateIfNeeded("t"), true);
	Assert.assertNotNull(result);
	final LogicalExpression expectedSubExp = ((Literal) ((Lambda) ((Lambda) exp)
			.getBody()).getBody()).getArg(1);
	final LogicalExpression expectedRemainder = TestServices
			.getCategoryServices()
			.readSemantics(
					"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> ($0 $1) p:t)))");
	Assert.assertEquals(expectedRemainder,
			result.getExpressionWithPlaceholder());
	Assert.assertEquals(expectedSubExp, result.getExtractedSubExpression());
}
 
Example #17
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 #18
Source File: GetConstCounts.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visit(Literal literal) {
	literal.getPredicate().accept(this);
	final int len = literal.numArgs();
	for (int i = 0; i < len; ++i) {
		literal.getArg(i).accept(this);
	}
}
 
Example #19
Source File: SingleKeyword.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ParseRuleResult<LogicalExpression> apply(
		Category<LogicalExpression> category, SentenceSpan span) {
	if (isValidArgument(category, span)) {
		final Literal skolemized = AMRServices
				.skolemize(category.getSemantics());
		if (skolemized != null) {
			return new ParseRuleResult<>(name, Category.create(
					AMRServices.getCompleteSentenceSyntax(), skolemized));
		}
	}
	return null;
}
 
Example #20
Source File: GetAllSkolemTerms.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visit(Literal literal) {
	final boolean isSkolemTerm = AMRServices.isSkolemTerm(literal);
	if (isSkolemTerm) {
		skolemTerms.add(literal);
	}

	if (!shallow || !isSkolemTerm) {
		literal.getPredicate().accept(this);
		final int len = literal.numArgs();
		for (int i = 0; i < len; ++i) {
			literal.getArg(i).accept(this);
		}
	}
}
 
Example #21
Source File: DetermineNamedEntity.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Set<Category<LogicalExpression>> reverseApply(
		Category<LogicalExpression> result, SentenceSpan span) {
	if (result.getSemantics() != null
			&& targetSyntax.equals(result.getSyntax())
			&& result.getSemantics() instanceof Literal
			&& AMRServices.isNamedEntity((Literal) result.getSemantics())) {
		return SetUtils.createSingleton(Category.create(sourceSyntax,
				((Literal) result.getSemantics()).getArg(1)));
	} else {
		return Collections.emptySet();
	}
}
 
Example #22
Source File: DummyEntityServices.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a skolem term (i.e., (a:<<e,t>,<id,e>> na:id (lambda $0:e
 * (and:<t*,t> .... (pred:<e,<e,t>> $0 DUMMY:e) .... )))), removes the
 * literal that includes the DUMMY:e entity as second argument, and returns
 * its predicate. If the dummy entity appears more than once, fail.
 *
 * @return Pair of stripped skolem term (in first position) and the
 *         predicate of the relation with the stripped dummy argument
 *         (second position).
 */
public static Pair<Literal, LogicalConstant> stripDummy(Literal literal) {
	if (AMRServices.isSkolemTerm(literal) && literal.numArgs() == 2
			&& literal.getArg(1) instanceof Lambda) {
		final Pair<Lambda, LogicalConstant> pair = stripDummy((Lambda) literal
				.getArg(1));
		if (pair != null) {
			return Pair.of(AMRServices.skolemize(pair.first()),
					pair.second());
		}
	}
	return null;
}
 
Example #23
Source File: GetAllStrings.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visit(Literal literal) {
	literal.getPredicate().accept(this);
	final int len = literal.numArgs();
	for (int i = 0; i < len; ++i) {
		literal.getArg(i).accept(this);
	}
}
 
Example #24
Source File: AMRServices.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the unary typing predicate (if one exists) from a <e,t>-typed lambda
 * term (the body of a skolem term).
 */
public static LogicalConstant getTypingPredicate(Lambda set) {
	if (set.getBody() instanceof Literal) {
		final Literal bodyLiteral = (Literal) set.getBody();
		final int len = bodyLiteral.numArgs();
		if (bodyLiteral.getPredicate()
				.equals(LogicLanguageServices.getConjunctionPredicate())) {
			return getTypingPredicateFromConjunction(bodyLiteral);
		} else if (len == 1
				&& bodyLiteral.getPredicate() instanceof LogicalConstant) {
			return (LogicalConstant) bodyLiteral.getPredicate();
		}
	}
	return null;
}
 
Example #25
Source File: NamedEntityKeywordCoordination.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isValidArgument(Category<LogicalExpression> category,
		SentenceSpan span) {
	// Only apply to the right-most span.
	return category.getSemantics() != null && span.isEnd()
			&& sourceSyntax.equals(category.getSyntax())
			&& category.getSemantics().numFreeVariables() == 0
			&& AMRServices.isSkolemTerm(category.getSemantics())
			&& AMRServices.isNamedEntity((Literal) category.getSemantics());
}
 
Example #26
Source File: AttachmentFeatures.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visit(Literal literal) {
	final int len = literal.numArgs();
	if (literal.getPredicate().equals(
			LogicLanguageServices.getConjunctionPredicate())) {
		visitConjunction(literal);
	} else {
		for (int i = 0; i < len; ++i) {
			literal.getArg(i).accept(this);
		}
		literal.getPredicate().accept(this);
	}
}
 
Example #27
Source File: GetApplicationArgument.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
private void visitConventionalLiteral(Literal sourceLiteral,
		final Literal resultLiteral) {
	final int len = sourceLiteral.numArgs();
	final boolean noPriorArgument = argument == null;
	if (len == resultLiteral.numArgs()) {
		applicationResult = resultLiteral.getPredicate();
		sourceLiteral.getPredicate().accept(this);
		if (isValid) {
			for (int i = 0; i < len; ++i) {
				applicationResult = resultLiteral.getArg(i);
				sourceLiteral.getArg(i).accept(this);
				if (!isValid) {
					break;
				}

			}
		}
	} else {
		isValid = false;
	}

	if (!isValid) {
		final LogicalExpression newArgument = createArgument(resultLiteral,
				sourceLiteral, applicationArgument, scope);
		if (newArgument != null) {
			if (noPriorArgument) {
				argument = newArgument;
				isValid = true;
			} else if (!argument.equals(newArgument)) {
				isValid = false;
			}
		}
	}
}
 
Example #28
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 #29
Source File: AMRSupervisedFilter.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visit(Literal literal) {
	final int numArgs = literal.numArgs();
	final LogicalExpression predicate = literal
			.getPredicate() instanceof LogicalConstant
					? OverloadedLogicalConstant.getWrapped(
							(LogicalConstant) literal.getPredicate())
					: literal.getPredicate();
	if (numArgs == 2
			&& !LogicLanguageServices.isCoordinationPredicate(predicate)
			&& predicate instanceof LogicalConstant
			&& constantFilter.test((LogicalConstant) predicate)) {
		countRelationalPairs((LogicalConstant) predicate,
				literal.getArg(1));
		if (!isValid) {
			return;
		}
	}

	if (LogicLanguageServices.isCoordinationPredicate(predicate)) {
		// Try to construct the instance-type-related-type triplets as
		// much as possible. We are trying to do as early as possible,
		// even before the skolem term is closed.
		countInstanceTypeRelatedTypeTriplets(literal);
		if (!isValid) {
			return;
		}
	}

	predicate.accept(this);
	for (int i = 0; i < numArgs; ++i) {
		literal.getArg(i).accept(this);
		if (!isValid) {
			return;
		}
	}
}
 
Example #30
Source File: DateStamp.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
private boolean isDateSemantics(LogicalExpression semantics) {
	if (semantics == null || !AMRServices.isSkolemTerm(semantics)) {
		return false;
	}

	final LogicalConstant typingPredicate = AMRServices
			.getTypingPredicate((Literal) semantics);
	if (typingPredicate == null) {
		LOG.error("Null typing predicate: %s", semantics);
		return false;
	}

	return typingPredicate.equals(dateInstanceType);
}