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

The following examples show how to use edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant#getBaseName() . 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
/**
 * Extract the "lemma" of a constant.
 */
@Deprecated
public static String lemmatizeConstant(LogicalConstant constant) {
	if (isAmrRelation(constant)) {
		return null;
	}

	final String lemma;
	final Matcher matcher = FRAME_PREDICATE_REGEX
			.matcher(constant.getBaseName());
	if (matcher.matches()) {
		lemma = matcher.group("pred");
	} else {
		lemma = constant.getBaseName();
	}
	return lemma;
}
 
Example 2
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 3
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 4
Source File: SpecificationMapping.java    From amr with GNU General Public License v2.0 5 votes vote down vote up
public Set<LogicalExpression> getAssignments(
		LogicalConstant underspecifiedConstant) {
	final LogicalConstant stripped = OverloadedLogicalConstant
			.getWrapped(underspecifiedConstant);
	final String baseName = stripped.getBaseName();
	final Type type = stripped.getType();
	if (assignmentMapping.containsKey(baseName)) {
		return assignmentMapping.get(baseName).stream()
				.map((name) -> LogicalConstant.create(name, type, true))
				.collect(Collectors.toSet());
	} else if (underspecifyPropBank
			&& baseName.endsWith(PROPBANK_ROLE_WILDCARD)) {
		final String lemma = baseName.substring(0,
				baseName.length() - PROPBANK_ROLE_WILDCARD.length());
		final Set<PropBankFrame> frames = AMRServices
				.getPropBankFrames(lemma);
		if (frames.isEmpty()) {
			return Collections.emptySet();
		}
		return frames.stream()
				.map(frame -> LogicalConstant.create(
						lemma + PROPBANK_ROLE_SEP
								+ String.format("%02d", frame.getId()),
						type, true))
				.collect(Collectors.toSet());
	} else {
		return Collections.emptySet();
	}
}
 
Example 5
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 6
Source File: LogicalExpressionCoordinationServices.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
public LogicalExpressionCoordinationServices(
		LogicalConstant baseConjunctionConstant,
		LogicalConstant baseDisjunctionConstant,
		ICategoryServices<LogicalExpression> categoryServices) {
	this.baseConjunctionConstant = baseConjunctionConstant;
	this.baseDisjunctionConstant = baseDisjunctionConstant;
	this.categoryServices = categoryServices;
	this.baseConjunctionName = baseConjunctionConstant.getBaseName();
	this.baseDisjunctionName = baseDisjunctionConstant.getBaseName();
}
 
Example 7
Source File: GetHeadString.java    From spf with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(LogicalConstant logicalConstant) {
	headString = stripType ? logicalConstant.getBaseName()
			: logicalConstant.getName();
}