Java Code Examples for edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant#create()

The following examples show how to use edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant#create() . 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: AMRServices.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a reference predicate, e.g., ref:<id,e>.
 */
public static LogicalConstant createRefPredicate(Type type) {
	final LogicalConstant cached = INSTANCE.refPredicatesCache.get(type);

	if (cached != null) {
		return cached;
	}

	final ComplexType predicateType = LogicLanguageServices
			.getTypeRepository()
			.getTypeCreateIfNeeded(type, SkolemServices.getIDType());
	final LogicalConstant predicate = LogicalConstant
			.create(INSTANCE.refPredicateBaseName, predicateType, true);

	INSTANCE.refPredicatesCache.put(type, predicate);

	return predicate;
}
 
Example 2
Source File: AMRServices.java    From amr with GNU General Public License v2.0 6 votes vote down vote up
public static LogicalConstant createTextConstant(List<String> tokens) {
	final String TEXT_STRING_SEP = "++";
	final String escapedString = LogicalConstant
			.escapeString(tokens.stream().map(token -> {
				final StringBuilder modifiedToken = new StringBuilder(
						token);
				if (modifiedToken.charAt(0) == '"') {
					modifiedToken.deleteCharAt(0);
				}
				if (modifiedToken
						.charAt(modifiedToken.length() - 1) == '"') {
					modifiedToken.deleteCharAt(modifiedToken.length() - 1);
				}
				return modifiedToken.toString();
			}).collect(Collectors.joining(TEXT_STRING_SEP)));
	return LogicalConstant.create(escapedString, INSTANCE.textType, true);
}
 
Example 3
Source File: AMRServices.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a skolem term predicate, e.g., a:<id,<<e,t>,e>>.
 */
public static LogicalConstant createSkolemPredicate(Type type) {
	final LogicalConstant cached = INSTANCE.skolemPredicatesCache.get(type);

	if (cached != null) {
		return cached;
	}

	final ComplexType predicateType = LogicLanguageServices
			.getTypeRepository().getTypeCreateIfNeeded(
					LogicLanguageServices.getTypeRepository()
							.getTypeCreateIfNeeded(type,
									LogicLanguageServices
											.getTypeRepository()
											.getTypeCreateIfNeeded(
													LogicLanguageServices
															.getTypeRepository()
															.getTruthValueType(),
													type)),
					SkolemServices.getIDType());
	final LogicalConstant predicate = LogicalConstant
			.create(INSTANCE.skolemPredicateBaseName, predicateType, true);

	INSTANCE.skolemPredicatesCache.put(type, predicate);

	return predicate;
}
 
Example 4
Source File: AMRServices.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a passive relation, returns its active form. Otherwise, returns
 * null.
 *
 * @param underspecified
 *            The output should be underspecified or not.
 */
public static LogicalExpression makeRelationActive(LogicalConstant constant,
		boolean underspecified) {
	if (isAmrRelation(constant)) {
		String baseName;
		boolean overload;
		if (constant instanceof OverloadedLogicalConstant) {
			baseName = ((OverloadedLogicalConstant) constant)
					.getWrappedConstant().getBaseName();
			overload = true;
		} else {
			baseName = constant.getBaseName();
			overload = false;
		}

		if (baseName.endsWith(INVERSE_RELATION_SUFFIX)) {
			final LogicalConstant activeConstant = underspecified
					? (LogicalConstant) underspecify(LogicalConstant.create(
							baseName.substring(0, baseName.length()
									- INVERSE_RELATION_SUFFIX.length()),
							constant.getType(), true))
					: LogicalConstant.create(
							baseName.substring(0, baseName.length()
									- INVERSE_RELATION_SUFFIX.length()),
							constant.getType(), true);
			if (overload) {
				return ((OverloadedLogicalConstant) constant)
						.cloneWrapper(activeConstant);
			} else {
				return activeConstant;
			}
		}
	}
	return null;
}
 
Example 5
Source File: AMRServices.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert a binary relation to its passive version, e.g., boo:<e,<e,t>> ->
 * boo-of:<e,<e,t>>.
 */
public static LogicalConstant makeRelationPassive(LogicalConstant constant,
		boolean underspecified) {
	if (isAmrRelation(constant)) {
		String baseName;
		boolean overload;
		if (constant instanceof OverloadedLogicalConstant) {
			baseName = ((OverloadedLogicalConstant) constant)
					.getWrappedConstant().getBaseName();
			overload = true;
		} else {
			baseName = constant.getBaseName();
			overload = false;
		}

		if (!baseName.endsWith(INVERSE_RELATION_SUFFIX)) {
			final LogicalConstant passiveConstant = underspecified
					? (LogicalConstant) underspecify(LogicalConstant.create(
							baseName + INVERSE_RELATION_SUFFIX,
							constant.getType(), true))
					: LogicalConstant.create(
							baseName + INVERSE_RELATION_SUFFIX,
							constant.getType(), true);
			if (overload) {
				return ((OverloadedLogicalConstant) constant)
						.cloneWrapper(passiveConstant);
			} else {
				return passiveConstant;
			}
		}
	}
	return null;
}
 
Example 6
Source File: SpecificationMapping.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
public LogicalConstant underspecify(LogicalConstant constant) {
	final String baseName = constant.getBaseName();

	// Verify type <?,<?,t>>.
	if (constant.getType().isComplex()
			&& constant.getType().getRange().isComplex()
			&& LogicLanguageServices.getTypeRepository().getTruthValueType()
					.equals(constant.getType().getRange().getRange())
			&& underspecMapping.containsKey(baseName)) {
		return LogicalConstant.create(underspecMapping.get(baseName),
				constant.getType(), true);
	}

	// Verify type <?,t>.
	if (underspecifyPropBank && constant.getType().isComplex()
			&& constant.getType().getRange().equals(LogicLanguageServices
					.getTypeRepository().getTruthValueType())) {
		// If this is a PropBank frame, underspecify.
		if (AMRServices.isPropBankFrame(baseName)) {
			final String lemma = baseName.substring(0,
					baseName.length() - PROPBANK_ROLE_WILDCARD.length());
			if (!AMRServices.getPropBankFrames(lemma).isEmpty()) {
				return LogicalConstant.create(
						lemma + PROPBANK_ROLE_WILDCARD, constant.getType(),
						true);
			}
		}
	}

	return constant;
}
 
Example 7
Source File: CoordinationServices.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a list of arguments, a type and a predicate base name create a
 * literal. The type of the predicate is <type,...,<type,type>...>.
 */
public static Literal createLiteral(String name,
		LogicalExpression[] arguments, Type type) {

	// Create the type of the predicate.
	ComplexType predicateType = LogicLanguageServices.getTypeRepository()
			.getTypeCreateIfNeeded(type, type);
	for (int i = 1; i < arguments.length; i++) {
		predicateType = LogicLanguageServices.getTypeRepository()
				.getTypeCreateIfNeeded(predicateType, type);
	}

	return new Literal(LogicalConstant.create(name, predicateType, true),
			arguments);
}
 
Example 8
Source File: CoordinationServices.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dynamically create c_op predicates, e.g., c_op1:<e,<e,t>>,
 * c_op2:<e,<i,t>> and so on.
 */
public static LogicalConstant createpCOpPredicate(int num, Type argType) {
	final String baseName = INSTANCE.argumentPredicateBaseName + num;
	final Type type = LogicLanguageServices.getTypeRepository()
			.getTypeCreateIfNeeded(
					LogicLanguageServices.getTypeRepository()
							.getTypeCreateIfNeeded(
									LogicLanguageServices
											.getTypeRepository()
											.getTruthValueType(), argType),
					LogicLanguageServices.getTypeRepository()
							.getEntityType());
	return LogicalConstant.create(baseName, type, true);
}
 
Example 9
Source File: CoordinationCX4Rule.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
public CoordinationCX4Rule(
		ICategoryServices<LogicalExpression> categoryServices) {
	super(categoryServices, LABEL);
	this.extractionPlaceholder = LogicalConstant
			.create(LABEL, LogicLanguageServices.getTypeRepository()
					.getEntityType(), true);
}
 
Example 10
Source File: NumeralGenerator.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
public static LogicalConstant getIntegerConstant(String string,
		IntPredicate filter) {
	if (NUMBER.matches(string) && filter.test(Integer.valueOf(string))) {
		return LogicalConstant.create(Integer.valueOf(string).toString(),
				LogicLanguageServices.getNumeralType(), true);
	} else {
		return null;
	}
}
 
Example 11
Source File: GetStructure.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visit(Variable variable) {
	if (variable instanceof SkolemId) {
		tempReturn = LogicalConstant.create(anonnymousTag,
				variable.getType(), true);
	} else {
		tempReturn = variable;
	}
}
 
Example 12
Source File: AmrToLogicalExpressionConverter.java    From amr with GNU General Public License v2.0 4 votes vote down vote up
private static LogicalConstant createConstant(String name, Type type) {
	return LogicalConstant.create(LogicalConstant.escapeString(name), type,
			true);
}
 
Example 13
Source File: SloppyAmrClosure.java    From amr with GNU General Public License v2.0 4 votes vote down vote up
private SloppyAmrClosure() {
	// Usage via 'of' method.
	this.dummyTypingPredicate = LogicalConstant.create("UNK",
			AMRServices.getTypingPredicateType(), true);
}
 
Example 14
Source File: GetStructure.java    From spf with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(LogicalConstant logicalConstant) {
	tempReturn = LogicalConstant.create(anonnymousTag,
			logicalConstant.getType(), true);
}
 
Example 15
Source File: AMRServices.java    From amr with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @param i
 *            Create opi predicates.
 * @param predicatType
 *            The type of the generated predicate.
 */
public static LogicalConstant integerToOpPredicate(int i, Type type) {
	return LogicalConstant.create(INSTANCE.opPredicatePrefix + i, type,
			true);
}