當前位置: 首頁>>代碼示例>>Java>>正文


Java ScopeMapping類代碼示例

本文整理匯總了Java中edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping的典型用法代碼示例。如果您正苦於以下問題:Java ScopeMapping類的具體用法?Java ScopeMapping怎麽用?Java ScopeMapping使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ScopeMapping類屬於edu.cornell.cs.nlp.spf.mr.lambda.mapping包,在下文中一共展示了ScopeMapping類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doEquals

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Override
protected boolean doEquals(LogicalExpression exp,
		ScopeMapping<Variable, Variable> mapping) {
	if (!(exp instanceof Variable) || exp instanceof SkolemId) {
		return false;
	}

	final Variable mapValue = mapping.peek(this);
	if (mapValue == exp && mapping.peekValue(mapValue) == this) {
		// Comparison through mapping of variables.
		return true;
	} else if (!mapping.containsValue((Variable) exp)) {
		// Case both are not mapped, do instance comparison for free
		// variables.
		return exp == this;
	} else {
		// Not equal.
		return false;
	}
}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:21,代碼來源:Variable.java

示例2: equals

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Override
public boolean equals(LogicalExpression exp,
		ScopeMapping<Variable, Variable> mapping) {
	if (!(exp instanceof SkolemId)) {
		return false;
	}

	final Variable mappedValue = mapping.peek(this);
	if (mappedValue == exp && mapping.peekValue(mappedValue) == this) {
		return true;
	} else if (exp instanceof SkolemIdInstanceWrapper) {
		return exp.equals(this, mapping);
	} else if (!mapping.containsValue((SkolemId) exp)) {
		mapping.push(this, (SkolemId) exp);
		return true;
	} else {
		return false;
	}
}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:20,代碼來源:SkolemId.java

示例3: testCreateArg4

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@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));

}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:18,代碼來源:GetApplicationArgumentTest.java

示例4: read

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
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);
}
 
開發者ID:sivareddyg,項目名稱:UDepLambda,代碼行數:11,代碼來源:SimpleLogicalExpressionReader.java

示例5: read

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Override
public Variable read(String string,
		ScopeMapping<String, LogicalExpression> mapping,
		TypeRepository typeRepository, ITypeComparator typeComparator,
		LogicalExpressionReader reader) {

	try {
		final Pair<String, Variable> defintion = readVariableDefintion(
				string, typeRepository);
		if (defintion != null && !mapping.containsKey(string)) {
			mapping.push(defintion.first(), defintion.second());
			return defintion.second();
		} else if (defintion != null) {
			throw new LogicalExpressionRuntimeException(
					"Re-define a global variable: " + string);
		} else {
			// Case variable reference.
			if (mapping.containsKey(string)) {
				return (Variable) mapping.peek(string);
			} else {
				throw new LogicalExpressionRuntimeException(
						"Undefined variable reference: " + string);
			}
		}
	} catch (final RuntimeException e) {
		LOG.error("Variable error: %s", string);
		throw e;
	}

}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:31,代碼來源:Variable.java

示例6: read

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Override
public Literal read(String string,
		ScopeMapping<String, LogicalExpression> mapping,
		TypeRepository typeRepository, ITypeComparator typeComparator,
		LogicalExpressionReader reader) {
	try {
		final LispReader lispReader = new LispReader(new StringReader(
				string));

		// First is the literal predicate. Get its signature and verify
		// it
		// exists
		final String predicateString = lispReader.next();
		final LogicalExpression predicate = reader.read(
				predicateString, mapping, typeRepository,
				typeComparator);

		// The rest of the elements are the arguments
		final List<LogicalExpression> arguments = new ArrayList<LogicalExpression>();
		while (lispReader.hasNext()) {
			final String stringElement = lispReader.next();
			final LogicalExpression argument = reader.read(
					stringElement, mapping, typeRepository,
					typeComparator);
			arguments.add(argument);
		}

		// Create the literal, all checks are done within the
		// constructor
		return new Literal(predicate,
				arguments.toArray(new LogicalExpression[arguments
						.size()]), typeComparator, typeRepository);
	} catch (final RuntimeException e) {
		LOG.error("Literal syntax error: %s", string);
		throw e;
	}
}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:38,代碼來源:Literal.java

示例7: doEquals

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Override
protected boolean doEquals(LogicalExpression exp,
		ScopeMapping<Variable, Variable> mapping) {
	if (this == exp) {
		// Since skolem IDs from this literal may be used in other parts of
		// the logical form, we need to create a mapping of them. As the
		// instances are identical, we can just update the mapping by
		// creating a mapping from each SkolemId to itself.
		if (!freeVariables.isEmpty()) {
			for (final Variable freeVariable : freeVariables) {
				if (freeVariable instanceof SkolemId) {
					mapping.push(freeVariable, freeVariable);
				}
			}
		}
		return true;
	}
	if (getClass() != exp.getClass()) {
		return false;
	}
	final Lambda other = (Lambda) exp;
	if (!type.equals(other.type)) {
		return false;
	}

	if (argument.getType().equals(other.argument.getType())) {
		// If the types are equal and both are not null, add the mapping for
		// the comparison of the body.
		mapping.push(argument, other.argument);
	} else {
		return false;
	}

	final boolean ret = body.equals(other.body, mapping);

	// Remove mapping.
	mapping.pop(argument);

	return ret;
}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:41,代碼來源:Lambda.java

示例8: read

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Override
public LogicalConstant read(String string,
		ScopeMapping<String, LogicalExpression> mapping,
		TypeRepository typeRepository, ITypeComparator typeComparator,
		LogicalExpressionReader reader) {
	return LogicalConstant.read(string, typeRepository);
}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:8,代碼來源:LogicalConstant.java

示例9: equals

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Override
public boolean equals(LogicalExpression exp,
		ScopeMapping<Variable, Variable> mapping) {
	if (exp instanceof SkolemIdInstanceWrapper) {
		return base == ((SkolemIdInstanceWrapper) exp).base;
	} else {
		return base == exp;
	}
}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:10,代碼來源:SkolemIdInstanceWrapper.java

示例10: read

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
/** {@see #read(String)} */
private LogicalExpression read(String string,
		TypeRepository typeRepository, ITypeComparator typeComparator) {
	// Flatten the string. Replace all white space sequences with a single
	// space.
	final String flatString = WHITE_SPACE_REPLACER.replace(string);
	try {
		return LambdaWrapped.of(read(flatString,
				new ScopeMapping<String, LogicalExpression>(),
				typeRepository, typeComparator));
	} catch (final RuntimeException e) {
		LOG.error("Logical expression syntax error: %s", flatString);
		throw e;
	}
}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:16,代碼來源:LogicalExpressionReader.java

示例11: read

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Override
public SkolemId read(String string,
		ScopeMapping<String, LogicalExpression> mapping,
		TypeRepository typeRepository, ITypeComparator typeComparator,
		LogicalExpressionReader reader) {
	if (!mapping.containsKey(string)) {
		mapping.push(string, new SkolemId());
	}
	return (SkolemId) mapping.peek(string);
}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:11,代碼來源:SkolemId.java

示例12: testCreateArg1

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Test
public void testCreateArg1() {
	final LogicalExpression resultSubExp = TestServices
			.getCategoryServices().readSemantics("boo:e");
	final Variable applicationArg = new Variable(
			LogicLanguageServices.getTypeRepository().getEntityType());
	Assert.assertEquals(resultSubExp,
			GetApplicationArgument.createArgument(resultSubExp,
					applicationArg, applicationArg,
					new ScopeMapping<Variable, Variable>()));

}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:13,代碼來源:GetApplicationArgumentTest.java

示例13: testCreateArg2

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Test
public void testCreateArg2() {
	final LogicalExpression resultSubExp = TestServices
			.getCategoryServices().readSemantics("boo:t");
	final Variable applicationArg = new Variable(
			LogicLanguageServices.getTypeRepository().getEntityType());
	Assert.assertEquals(null,
			GetApplicationArgument.createArgument(resultSubExp,
					applicationArg, applicationArg,
					new ScopeMapping<Variable, Variable>()));

}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:13,代碼來源:GetApplicationArgumentTest.java

示例14: testCreateArg3

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Test
public void testCreateArg3() {
	final LogicalExpression resultSubExp = TestServices
			.getCategoryServices().readSemantics("(pred:<e,t> boo:e)");
	final LogicalExpression function = TestServices.getCategoryServices()
			.readSemantics("(lambda $0:<e,t> ($0 boo:e))");
	final Variable applicationArg = ((Lambda) function).getArgument();
	final LogicalExpression expected = TestServices.getCategoryServices()
			.readSemantics("pred:<e,t>");
	Assert.assertEquals(expected,
			GetApplicationArgument.createArgument(resultSubExp,
					((Lambda) function).getBody(), applicationArg,
					new ScopeMapping<Variable, Variable>()));

}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:16,代碼來源:GetApplicationArgumentTest.java

示例15: read

import edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping; //導入依賴的package包/類
@Override
public Lambda read(String string,
		ScopeMapping<String, LogicalExpression> mapping,
		TypeRepository typeRepository, ITypeComparator typeComparator,
		LogicalExpressionReader reader) {

	try {
		final LispReader lispReader = new LispReader(new StringReader(
				string));

		// The first argument is the 'lambda' keyword. We just ignore
		// it.
		lispReader.next();

		// The second argument is the variable definition.
		final Pair<String, Variable> variableDef = Variable
				.readVariableDefintion(lispReader.next(),
						typeRepository);

		if (variableDef == null) {
			throw new LogicalExpressionRuntimeException(
					"Invalid lambda argument: " + string);
		}

		// Update the scope mapping.
		mapping.push(variableDef.first(), variableDef.second());

		// The next argument is the body expression.
		final LogicalExpression lambdaBody = reader.read(
				lispReader.next(), mapping, typeRepository,
				typeComparator);

		// Verify that we don't have any more elements.
		if (lispReader.hasNext()) {
			throw new LogicalExpressionRuntimeException(String.format(
					"Invalid lambda expression: %s", string));
		}

		// Remove the variable from the mapping.
		if (mapping.pop(variableDef.first()) == null) {
			throw new LogicalExpressionRuntimeException(
					"Failed to remove variable from mapping. Something werid is happening: "
							+ string);
		}

		return new Lambda(variableDef.second(), lambdaBody);
	} catch (final RuntimeException e) {
		LOG.error("Lambda syntax error: %s", string);
		throw e;
	}

}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:53,代碼來源:Lambda.java


注:本文中的edu.cornell.cs.nlp.spf.mr.lambda.mapping.ScopeMapping類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。