当前位置: 首页>>代码示例>>Java>>正文


Java Expressions.apply方法代码示例

本文整理汇总了Java中com.sri.ai.expresso.helper.Expressions.apply方法的典型用法代码示例。如果您正苦于以下问题:Java Expressions.apply方法的具体用法?Java Expressions.apply怎么用?Java Expressions.apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sri.ai.expresso.helper.Expressions的用法示例。


在下文中一共展示了Expressions.apply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitFunctionType

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override 
public Expression visitFunctionType(AntlrGrinderParser.FunctionTypeContext ctx) { 
	Object[] arguments  = new Object[2];
	if (ctx.domaintypes.size() == 1) {
		Expression domain = visit(ctx.domaintypes.get(0));					
		arguments[0] = domain;
	}
	else {
		Object[] domainArgs = new Object[ctx.domaintypes.size()];
		for (int i = 0; i < ctx.domaintypes.size(); i++) {
			domainArgs[i] = visit(ctx.domaintypes.get(i));
		}
		Expression tupleType = Expressions.apply(FunctorConstants.TUPLE_TYPE, domainArgs);
		arguments[0] = tupleType;
	}
	arguments[1] = visit(ctx.rangetype);
	Expression result = Expressions.apply(FunctorConstants.FUNCTION_TYPE, arguments);
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:20,代码来源:ExpressionVisitor.java

示例2: simplify

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
static public Expression simplify(Expression expression) {
	Expression result = expression;
	
	Expression first = expression.get(0);
	Expression second = expression.get(1);

	if (Expressions.isNumber(first)) {
		Rational firstValue = first.rationalValue();
		if (Expressions.isNumber(second)) {
			Rational secondValue = second.rationalValue();
			result = Expressions.makeSymbol(firstValue.subtract(secondValue));
		} 
		else if (firstValue.isZero()) {
			result = Expressions.apply("-", second);
		}
	} 
	else if (Expressions.isNumber(second) && second.rationalValue().isZero()) {
		result = first;
	}
		
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:23,代码来源:BinaryMinus.java

示例3: applySimplifier

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override
public Expression applySimplifier(Expression expression, Context context) {
	// We need to override this method because INFINITY and MINUS_INFINITY
	// are not Java constants.
	Expression result;
	if ( ! isExtensional(expression)) {
		result = expression;
	}
	else {
		// takes care of infinity arguments before deferring to super method
		if (expression.getArguments().contains(INFINITY)) {
			result = INFINITY;
		}
		else {
			// remove MINUS_INFINITY if any and defer to super method
			List<Expression> argumentsWithoutMinusInfinity =
					Util.removeNonDestructively(expression.getArguments(), MINUS_INFINITY);
			Expression expressionWithoutMinusInfinity =
					expression.getArguments() == argumentsWithoutMinusInfinity?
							expression : Expressions.apply(expression.getFunctor(), argumentsWithoutMinusInfinity);
			result = super.apply(expressionWithoutMinusInfinity, context);
		}
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:26,代码来源:Max.java

示例4: simplify

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static Expression simplify(Expression conjunction) {
	Expression result = conjunction;
	if (conjunction.getArguments().contains(Expressions.FALSE)) {
		result = Expressions.FALSE;
	}
	else {
		LinkedHashSet<Expression> distinctArgumentsNotEqualToTrue = new LinkedHashSet<Expression>();
		Util.collect(conjunction.getArguments(), distinctArgumentsNotEqualToTrue, e -> ! e.equals(Expressions.TRUE));
		if (distinctArgumentsNotEqualToTrue.size() != conjunction.getArguments().size()) {
			if (distinctArgumentsNotEqualToTrue.size() == 0) {
				result = Expressions.TRUE;
			}
			else if (distinctArgumentsNotEqualToTrue.size() == 1) {
				result = Util.getFirst(distinctArgumentsNotEqualToTrue);
			}
			else if (distinctArgumentsNotEqualToTrue.size() != conjunction.numberOfArguments()) {
				result = Expressions.apply(FunctorConstants.AND, distinctArgumentsNotEqualToTrue);
			}
		}
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:23,代码来源:And.java

示例5: copyIndexExpressionWithNewIndex

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static Expression copyIndexExpressionWithNewIndex(Expression indexExpression, Expression newIndex) {
	if (newIndex != IndexExpressions.getIndex(indexExpression)) {
		Expression result;
		if (indexExpression.hasFunctor("in")) {
			result = Expressions.apply("in", newIndex, indexExpression.get(1));
		}
		else {
			result = newIndex;
		}
		return result;
	}
	return indexExpression;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:14,代码来源:IndexExpressions.java

示例6: getTypeCardinality

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
/**
 * Returns the cardinality of the type of a given variable in the given registry,
 * looking for <code>| Type |</code>, for <code>Type</code> the type of the variable,
 * in the registry global objects.
 * If the size cannot be determined, returns -1.
 * If the size is infinite, returns -2.
 * @param symbol a variable
 * @param registry the registry
 * @return the cardinality of the type of the variable according to the registry or -1 if it cannot be determined.
 */
public static long getTypeCardinality(Expression symbol, Registry registry) {
	long result = -1;

	Expression variableType = registry.getTypeExpressionOfRegisteredSymbol(symbol);
	if (variableType != null) {
		Expression typeCardinality = Expressions.apply(FunctorConstants.CARDINALITY, variableType);
		Expression typeCardinalityValue = (Expression) registry.getGlobalObject(typeCardinality);
		if (typeCardinalityValue != null) {
			result = typeCardinalityValue.intValueExact();
		}
	}
	
	// If that didn't work, we try find the Type object:
	if (result == -1) {
		variableType = registry.getTypeExpressionOfRegisteredSymbol(symbol);
		if (variableType != null) {
			Type type = registry.getTypeFromTypeExpression(variableType);
			if (type != null) {
				Expression sizeExpression = type.cardinality();
				if (sizeExpression.equals(apply(CARDINALITY, type.getName()))) {
					result = -1;
				}
				else if (sizeExpression.equals(Expressions.INFINITY)) {
					result = -2;
				}
				else {
					result = sizeExpression.intValue();
				}
			}
		}
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:45,代码来源:GrinderUtil.java

示例7: add

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override
public Expression add(Expression value1, Expression value2, Context context) {
	Expression result;
	if (value1.getValue() instanceof Number && value2.getValue() instanceof Number) {
		Rational rationalValue1 = value1.rationalValue();
		Rational rationalValue2 = value2.rationalValue();
		if (rationalValue1.compareTo(rationalValue2) > 0) {
			result = value1;
		}
		else {
			result = value2;
		}
	}
	else if (value1.equals(INFINITY) || value2.equals(INFINITY)) {
		result = INFINITY;
	}
	else if (isMinusInfinity(value1)) {
		result = value2;
	}
	else if (isMinusInfinity(value2)) {
		result = value1;
	}
	else {
		result = Expressions.apply(MAX, value1, value2);
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:28,代码来源:Max.java

示例8: makeIntersection

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static Expression makeIntersection(Expression... sets) {
	if (sets.length == 0) {
		throw new IllegalArgumentException("No set arguments passed to construct intersection with.");
	}
	
	Expression result;
	if (sets.length == 1) {
		result = sets[0];			
	}
	else {
		result = Expressions.apply(FunctorConstants.INTERSECTION, (Object []) sets);
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:15,代码来源:Sets.java

示例9: make

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
/**
 * Makes a disequality of two expressions, returning Expressions.FALSE if
 * the expressions are identical.
 */
public static Expression make(Object expression1Object,
		Object expression2Object) {
	Expression expression1 = Expressions.wrap(expression1Object);
	Expression expression2 = Expressions.wrap(expression2Object);
	if (expression1.equals(expression2)) {
		return Expressions.FALSE;
	}
	return Expressions.apply(DISEQUALITY, expression1, expression2);
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:14,代码来源:Disequality.java

示例10: getAtomNegation

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
/**
 * Inverts <code>=</code> to <code>!=</code> and vice-versa,
 * and adds <code>not</code> to other atoms.
 */
@Override
public Expression getAtomNegation(Expression atom, Context context) {
	Expression result;
	if (atom.hasFunctor(EQUALITY)) {
		result = Expressions.apply(DISEQUALITY, atom.get(0), atom.get(1));
	}
	else if (atom.hasFunctor(DISEQUALITY)) {
		result = Expressions.apply(EQUALITY, atom.get(0), atom.get(1));
	}
	else {
		result = not(atom);
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:19,代码来源:AbstractTheoryWithBinaryAtomsIncludingEquality.java

示例11: simplify

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static Expression simplify(Expression expression, Context context) {
	Expression result = expression;
	
	if (Expressions.hasFunctor(expression, FunctorConstants.IN) && expression.numberOfArguments() == 2) {
		Expression t   = expression.get(0);
		Expression set = expression.get(1);
		if (Sets.isExtensionalSet(set)) {
			// if empty set
			if (set.numberOfArguments() == 0) {
				result = Expressions.FALSE;
			}
			else if (set.numberOfArguments() == 1) {
				// (t = t<sub>1</sub>)
				result = Equality.make(t, set.get(0));
			}
			else { // > 1 element to test
				// (t = t<sub>1</sub>)
				Expression tEqualsT1         = Equality.make(t, set.get(0));
				// {t<sub>2</sub>,&hellip;,t<sub>n</sub>}
				Expression tailSet           = ExtensionalSets.makeOfSameTypeAs(set, set.getArguments().subList(1, set.numberOfArguments()));
				// t &isin; {t<sub>2</sub>,&hellip;,t<sub>n</sub>}
				Expression tElementOfTailSet = Expressions.apply(FunctorConstants.IN, t, tailSet);
				// (t = t<sub>1</sub>) &or; t &isin; {t<sub>2</sub>,&hellip;,t<sub>n</sub>}
				result = Or.make(tEqualsT1, tElementOfTailSet);
			}
		}
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:31,代码来源:ElementOfExtensionalSetSimplifier.java

示例12: make

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
/** Make a "not" application on given expression. */
public static Expression make(Expression expression) {
	if (expression.equals(Expressions.TRUE)) {
		return Expressions.FALSE;
	}
	if (expression.equals(Expressions.FALSE)) {
		return Expressions.TRUE;
	}
	return Expressions.apply("not", expression);
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:11,代码来源:Not.java

示例13: makeFunctionApplication

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
protected Expression makeFunctionApplication(String functorName, FunctionType functionType) {
	// Generate arguments for the application
	List<Expression> args = new ArrayList<>();
	for (Type argType : functionType.getArgumentTypes()) {
		// If constants supported, use at random
		if (argType.isSampleUniquelyNamedConstantSupported() && getRandom().nextBoolean()) {
			args.add(argType.sampleUniquelyNamedConstant(getRandom()));
		}
		else {
			// Otherwise retrieve a term variable matching that type and use it
			String termVariable = pickTestingVariableAtRandom(getTermVariableNamesAndTypesForTesting(), argType, variableName -> true);
			Type   termType     = getTermVariableNamesAndTypesForTesting().get(termVariable);
			if (termType instanceof FunctionType) {
				// Allow for nested function applications
				args.add(makeFunctionApplication(termVariable, (FunctionType) termType));
			}
			else {
				// Otherwise just assign the variable for the term.
				args.add(parse(termVariable));
			}
		}
	}
			
	Expression result = Expressions.apply(functorName, args.toArray(new Object[args.size()]));
			
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:28,代码来源:BruteForceFunctionTheoryTestingSupport.java

示例14: make

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static Expression make(Expression argument) {
	if (argument.getValue() instanceof Number) {
		return Expressions.makeSymbol(argument.rationalValue().negate());
	}
	return Expressions.apply(FunctorConstants.MINUS, argument);
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:7,代码来源:UnaryMinus.java

示例15: reassembleComparisonWithIsolatedNegativeVariable

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
private static Expression reassembleComparisonWithIsolatedNegativeVariable(Expression variable, Expression numericalComparison, ArrayList<Expression> side) {
	Expression sideSummation = Plus.make(side);
	Expression result = Expressions.apply(numericalComparison.getFunctor(), sideSummation, variable);
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:6,代码来源:DifferenceArithmeticUtil.java


注:本文中的com.sri.ai.expresso.helper.Expressions.apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。