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


Java Expressions.isFunctionApplicationWithArguments方法代码示例

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


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

示例1: isFunctionOnIntensionalSetWithSingleIndex

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
private static boolean isFunctionOnIntensionalSetWithSingleIndex(Object functor, Expression expression) {
	boolean result = false;
	if (((functor == null && Expressions.isFunctionApplicationWithArguments(expression)) || expression.hasFunctor(functor)) 
			&& expression.numberOfArguments() == 1) {
		Expression expressionArg1 = expression.get(0);
		if (Sets.isIntensionalSet(expressionArg1)) {
			IntensionalSet intensionalSet           = (IntensionalSet) expressionArg1;
			IndexExpressionsSet indexExpressionsSet = intensionalSet.getIndexExpressions();
			List<Expression> indices                = IndexExpressions.getIndices(indexExpressionsSet);			
			if (indices.size() == 1) {
				result = true;
			}
		}
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:17,代码来源:InversionSimplifier.java

示例2: UnificationStepSolver

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public UnificationStepSolver(Expression expression1, Expression expression2) {
	if (expression1.equals(expression2)) { // Check for simple literal equality up front.
		precomputedResult = new StepSolver.Solution<Boolean>(Boolean.TRUE);
	}
	else if (Expressions.isFunctionApplicationWithArguments(expression1) &&
			 Expressions.isFunctionApplicationWithArguments(expression2) &&
			 expression1.numberOfArguments() == expression2.numberOfArguments() &&
			 expression1.getFunctor().equals(expression2.getFunctor())) {
		unificationEqualitiesToTest = Util.zipWith(
				(matchingArgFrom1, matchingArgFrom2) -> Equality.make(matchingArgFrom1, matchingArgFrom2),
				expression1.getArguments(), expression2.getArguments());
	}
	else if (Expressions.isSymbol(expression1) && Expressions.isSymbol(expression2)) {
		unificationEqualitiesToTest = Arrays.asList(Equality.make(expression1, expression2));
	}
	else {
		precomputedResult = new StepSolver.Solution<Boolean>(Boolean.FALSE);
	}
	
	if (unificationEqualitiesToTest != null) {
		unknownSolutionIndexesForUnificationEqualities = 
				IntStream.range(0, unificationEqualitiesToTest.size())
					.boxed()
					.collect(Collectors.toList());
	}
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:27,代码来源:UnificationStepSolver.java

示例3: computeSize

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
private Rational computeSize(Expression functionOnIntensionalSet, Rational resultSoFar, Context context) {
	IntensionalSet      intensionalSet      = (IntensionalSet)functionOnIntensionalSet.get(0);
	IndexExpressionsSet indexExpressionsSet = intensionalSet.getIndexExpressions();		
	List<Expression> indices                = IndexExpressions.getIndices(indexExpressionsSet);
	if (indices.size() != 1) {
		throw new UnsupportedOperationException("Currently only support singular indices");
	}
	Expression index              = indices.get(0);
	Context intensionalSetContext = context.extendWith(indexExpressionsSet);
	Type type                     = GrinderUtil.getTypeOfExpression(index, intensionalSetContext);
	
	Rational result = resultSoFar.multiply(type.cardinality().rationalValue());
	
	Expression head = intensionalSet.getHead();
	if (Expressions.isFunctionApplicationWithArguments(head) && Sets.isIntensionalSet(head.get(0))) {
		result = computeSize(head, result, intensionalSetContext);
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:20,代码来源:InversionPerformanceEvaluationTest.java

示例4: getRandomFunctions

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
void getRandomFunctions(Expression expr, List<Pair<Expression, Map<Expression, ConstantDeclaration>>> randomFunctionsWithScope, Map<Expression, ConstantDeclaration> currentScope) {
	if (this.isDeclaredRandomFunctor(expr.getFunctorOrSymbol())) {
		randomFunctionsWithScope.add(new Pair<>(expr, currentScope));
	}
	
	if (Expressions.isFunctionApplicationWithArguments(expr)) {
		expr.getArguments().forEach(arg -> getRandomFunctions(arg, randomFunctionsWithScope, currentScope));
	}
	else if (isQuantifiedExpression(expr)) {
		Map<Expression, ConstantDeclaration> quantifierScope = new LinkedHashMap<>(currentScope);
		quantifierScope.putAll(getQuantifiedExpressionScope(expr));
		
		Expression bodyExpression = getQuantifiedExpressionBody(expr);
		if (bodyExpression != null) {
			getRandomFunctions(bodyExpression, randomFunctionsWithScope, quantifierScope);
		}
	}
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:19,代码来源:HOGModel.java

示例5: getConstantFunctions

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
void getConstantFunctions(Expression expr, List<Pair<Expression, Map<Expression, ConstantDeclaration>>> constantFunctionsWithScope, Map<Expression, ConstantDeclaration> currentScope) {
	if (this.isDeclaredConstantFunctor(expr.getFunctorOrSymbol(), currentScope)) {
		constantFunctionsWithScope.add(new Pair<>(expr, currentScope));
	}
	
	if (Expressions.isFunctionApplicationWithArguments(expr)) {
		expr.getArguments().forEach(arg -> getConstantFunctions(arg, constantFunctionsWithScope, currentScope));
	}
	else if (isQuantifiedExpression(expr)) {
		Map<Expression, ConstantDeclaration> quantifierScope = new LinkedHashMap<>(currentScope);
		quantifierScope.putAll(getQuantifiedExpressionScope(expr));
		
		Expression bodyExpression = getQuantifiedExpressionBody(expr);
		if (bodyExpression != null) {
			getConstantFunctions(bodyExpression, constantFunctionsWithScope, quantifierScope);
		}
	}
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:19,代码来源:HOGModel.java

示例6: getNonConstantRandomFunctions

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
void getNonConstantRandomFunctions(Expression expr, List<Pair<Expression, Map<Expression, ConstantDeclaration>>> nonConstantRandomFunctionsWithScope, Map<Expression, ConstantDeclaration> currentScope) {
	if (Expressions.isFunctionApplicationWithArguments(expr) &&
		!isDeclaredConstantFunctor(expr.getFunctorOrSymbol(), currentScope) &&
		!isDeclaredRandomFunctor(expr.getFunctorOrSymbol())) {
		nonConstantRandomFunctionsWithScope.add(new Pair<>(expr, currentScope));
	}
	
	if (Expressions.isFunctionApplicationWithArguments(expr)) {
		expr.getArguments().forEach(arg -> getNonConstantRandomFunctions(arg, nonConstantRandomFunctionsWithScope, currentScope));
	}
	else if (isQuantifiedExpression(expr)) {
		Map<Expression, ConstantDeclaration> quantifierScope = new LinkedHashMap<>(currentScope);
		quantifierScope.putAll(getQuantifiedExpressionScope(expr));
		
		Expression bodyExpression = getQuantifiedExpressionBody(expr);
		if (bodyExpression != null) {
			getNonConstantRandomFunctions(bodyExpression, nonConstantRandomFunctionsWithScope, quantifierScope);
		}
	}
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:21,代码来源:HOGModel.java

示例7: getQuantifiers

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
void getQuantifiers(Expression expr, List<Pair<Expression, Map<Expression, ConstantDeclaration>>> quantifiersWithScope, Map<Expression, ConstantDeclaration> currentScope) {
	if (isQuantifiedExpression(expr)) {
		Map<Expression, ConstantDeclaration> quantifierScope = new LinkedHashMap<>(currentScope);
		quantifierScope.putAll(getQuantifiedExpressionScope(expr));
		
		quantifiersWithScope.add(new Pair<>(expr, quantifierScope));
		
		Expression bodyExpression = getQuantifiedExpressionBody(expr);
		if (bodyExpression != null) {
			getQuantifiers(bodyExpression, quantifiersWithScope, quantifierScope);
		}
	}
	
	if (Expressions.isFunctionApplicationWithArguments(expr)) {
		expr.getArguments().forEach(arg -> getQuantifiers(arg, quantifiersWithScope, currentScope));
	}
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:18,代码来源:HOGModel.java

示例8: updateQuantifiers

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
Expression updateQuantifiers(Expression expr, Map<Expression, ConstantDeclaration> currentScope) {
	Expression result = expr;
	if (isQuantifiedExpression(expr)) {				
		Expression bodyExpression = getQuantifiedExpressionBody(expr);
		if (bodyExpression != null) {
			Map<Expression, ConstantDeclaration> quantifierScope = new LinkedHashMap<>(currentScope);
			quantifierScope.putAll(getQuantifiedExpressionScope(expr));
			Expression updatedBodyExpression = updateQuantifiers(bodyExpression, quantifierScope);
			
			TermCategoryType updatedBodyTermCategoryType = determineTermCategoryType(updatedBodyExpression);
			if (updatedBodyTermCategoryType == TermCategoryType.NUMERIC) {
				Expression intensionalMultiSet = IntensionalSet.intensionalMultiSet(((QuantifiedExpression)expr).getIndexExpressions(), updatedBodyExpression, Expressions.TRUE);
				result = Expressions.apply(FunctorConstants.PRODUCT, intensionalMultiSet);
			}					
			else if (bodyExpression != updatedBodyExpression) 
			{	
				if (ForAll.isForAll(expr)) {
					result = ForAll.make(ForAll.getIndexExpression(expr), updatedBodyExpression);
				}
				else { // Otherwise is existential
					result = ThereExists.make(ThereExists.getIndexExpression(expr), updatedBodyExpression);
				}
			}
		}
	}
	else if (Expressions.isFunctionApplicationWithArguments(expr)) {
		List<Expression> updatedArgs = expr.getArguments().stream()
				.map(arg -> updateQuantifiers(arg, currentScope))
				.collect(Collectors.toList());
		
		if (!sameInstancesInSameIterableOrder(expr.getArguments(), updatedArgs)) {
			result = Expressions.apply(expr.getFunctor(), updatedArgs);
		}
		
		TermCategoryType resultTermCategoryType = determineTermCategoryType(result);
		if (resultTermCategoryType == TermCategoryType.INVALID) {
			if (IfThenElse.isIfThenElse(result)) {
				Expression asRule = attemptMakeRule(result);
				if (asRule != null) {
					result = asRule;
				}
			}
		}
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:48,代码来源:HOGModel.java

示例9: ground

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static void ground(FactorsAndTypes factorsAndTypes, List<Expression> evidence, Listener listener) {
	if (factorsAndTypes.getMapFromNonUniquelyNamedConstantNameToTypeName().size() > 0) {
		throw new IllegalArgumentException("Constants cannot be grounded");
	}
	Map<Expression, Triple<Expression, Integer, List<Expression>>> randomVariableNameToTypeSizeAndUniqueConstants = createRandomVariableNameToTypeSizeAndUniqueConstantsMap(factorsAndTypes);
	Map<Expression, Integer> randomVariableIndexes = new LinkedHashMap<>();
	AtomicInteger atomicVariableIndex = new AtomicInteger(-1);
	listener.numberGroundVariables(randomVariableNameToTypeSizeAndUniqueConstants.size());
	randomVariableNameToTypeSizeAndUniqueConstants.entrySet().forEach(entry -> {
		randomVariableIndexes.put(entry.getKey(), atomicVariableIndex.addAndGet(1));
		listener.groundVariableCardinality(atomicVariableIndex.get(), entry.getValue().second);
	});
	
	Map<Expression, List<Expression>> typeToValues = createTypeToValuesMap(factorsAndTypes, randomVariableNameToTypeSizeAndUniqueConstants);
	Map<String, String> newUniqueConstantToTypeMap = createGroundedUniqueConstantToTypeMap(typeToValues);
    
	InferenceForFactorGraphAndEvidence inferencer = makeInferencer(factorsAndTypes, newUniqueConstantToTypeMap);
	
	Context context = inferencer.makeContextWithTypeInformation();
	
	listener.numberFactors(factorsAndTypes.getFactors().size());
	int factorIndex = 0;
	for (Expression factor : factorsAndTypes.getFactors()) {
    	ArrayList<Expression> randomVariablesInFactor = new ArrayList<>(Expressions.getSubExpressionsSatisfying(factor, randomVariableNameToTypeSizeAndUniqueConstants::containsKey));
    	if (randomVariablesInFactor.size() == 0) {
    		throw new IllegalArgumentException("Factor contains no random variables: "+factor);
    	}
    	
    	int[] participantVariableIndexes = new int[randomVariablesInFactor.size()];
    	for (int i = 0; i < randomVariablesInFactor.size(); i++) {
    		Expression randomVariable = randomVariablesInFactor.get(i);
    		participantVariableIndexes[i] = randomVariableIndexes.get(randomVariable);
    	}
    	listener.factorParticipants(factorIndex, participantVariableIndexes);

    	if (!useContextSensitiveGrounding) {
    		fullGrounding(
    				factor,
    				randomVariablesInFactor,
    				listener,
    				randomVariableNameToTypeSizeAndUniqueConstants,
    				typeToValues,
    				inferencer,
    				context);
    	}
    	else {
    		contextSensitiveGrounding(
    				factor,
    				randomVariablesInFactor,
    				listener,
    				randomVariableNameToTypeSizeAndUniqueConstants,
    				typeToValues,
    				inferencer,
    				context);
    	}

    	factorIndex++;
	}
	
	// Handle the evidence
	for (Expression evidenceAssignment : evidence) {
		if (Expressions.isFunctionApplicationWithArguments(evidenceAssignment)) {
			// TODO - add support for 'not <variable>' and 'variable = value' and 'value = variable'
			throw new UnsupportedOperationException("Function application of evidence currently not supported: "+evidenceAssignment);
		}
		else if (Expressions.isSymbol(evidenceAssignment)) {
			int evidenceVariableIndex = randomVariableIndexes.get(evidenceAssignment);
			int evidenceValueIndex    = typeToValues.get(randomVariableNameToTypeSizeAndUniqueConstants.get(evidenceAssignment).first).indexOf(Expressions.TRUE);
			listener.evidence(evidenceVariableIndex, evidenceValueIndex);
		}
	}
	
	listener.groundingComplete();
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:75,代码来源:HOGModelGrounding.java


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