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


Java Expressions.parse方法代碼示例

本文整理匯總了Java中com.sri.ai.expresso.helper.Expressions.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java Expressions.parse方法的具體用法?Java Expressions.parse怎麽用?Java Expressions.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sri.ai.expresso.helper.Expressions的用法示例。


在下文中一共展示了Expressions.parse方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: simplifyAnswer

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
public Expression simplifyAnswer(Expression answer, Expression forQuery) {
	Expression result  = answer;
	Context    context = getQueryContext();
	if (HOGMSortDeclaration.IN_BUILT_BOOLEAN.getName().equals(GrinderUtil.getTypeExpressionOfExpression(forQuery, context))) {
		result = result.replaceAllOccurrences(forQuery, Expressions.TRUE, context);
		result = simplifyWithinQueryContext(result);
		answer = Expressions.parse(result.toString()); // This ensures numeric values have the correct precision
	}
	return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-praise,代碼行數:11,代碼來源:HOGMQueryRunner.java

示例2: solve

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
@Override
public SolverResult solve(String solveRequestId,
		ModelLanguage modelLanguage, String model, String evidenceQuery) throws Exception {

	if (modelLanguage != ModelLanguage.HOGMv1) {
		throw new UnsupportedOperationException(
				modelLanguage.name() + " is currently not supported by this solver.");
	}

	SGSolverCallResult prResult = prCallSGSolverCLI(model, evidenceQuery);

	Expression probabilityEvidence = null;	
	if (prResult.resultExpression != null) {
		Expression queryExpr = Expressions.parse(evidenceQuery);
		Expression resultExpr = Expressions.parse(prResult.resultExpression);
		// Simplify if possible
		if (IfThenElse.isIfThenElse(resultExpr)) {
			Expression condition = IfThenElse.condition(resultExpr);
			if (condition.equals(queryExpr)) {
				probabilityEvidence = IfThenElse.thenBranch(resultExpr);
			} else if (Not.isNegation(condition) && condition.get(0).equals(queryExpr)) {
				probabilityEvidence = IfThenElse.elseBranch(resultExpr);
			}
		} else if (resultExpr.equals(queryExpr)) {
			probabilityEvidence = Expressions.ONE;
		} else if (Not.isNegation(resultExpr)) {
			if (resultExpr.get(0).equals(queryExpr)) {
				probabilityEvidence = Expressions.ZERO;
			}
		}
		// If unable to simplify just return the result as computed (i.e. likely symbolic).
		if (probabilityEvidence == null) {
			probabilityEvidence = resultExpr;
		}
	}

	SolverResult result = new SolverResult(0,
			prResult.sgSolverProcessTookMS, probabilityEvidence);
	return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-praise,代碼行數:41,代碼來源:PRAiSESolver.java

示例3: LazySampledFunction

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
public LazySampledFunction(FunctionType functionType, Random random) {
	this.functionType = functionType;
	this.random       = random;
	
	this.innerExpression = Expressions.parse(functionType.toString());
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:7,代碼來源:LazySampledFunction.java

示例4: constructGenericTableExpressionUsingEqualities

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
/**
 * Returns an {@link Expression} equivalent to a given {@link FunctionTable} but in the form of a decision tree
 * (so hopefully more compact) using equalities.
 * @param functionTable
 * @param solverListener if not null, invoked on solver used for compilation, before and after compilation is performed; returned solver from "before" invocation is used (it may be the same one used as argument, of course).
 * @return
 */
public static Expression constructGenericTableExpressionUsingEqualities(FunctionTable functionTable, Function<MultiQuantifierEliminator, MultiQuantifierEliminator> solverListener) {
	StringBuilder table = new StringBuilder();
	CartesianProductEnumeration<Integer> cartesianProduct = new CartesianProductEnumeration<>(cardinalityValues(functionTable));
	int counter = 0;
	while (cartesianProduct.hasMoreElements()) {
		counter++;
		List<Integer> values = cartesianProduct.nextElement();
		Double entryValue = functionTable.entryFor(values);
		if (counter == cartesianProduct.size().intValue()) {
			// i.e. final value
			table.append(entryValue);
		}
		else {
			table.append("if ");
			for (int i = 0; i < values.size(); i++) {
				if (i > 0) {
					table.append(" and ");
				}
				String value = genericConstantValueForVariable(values.get(i), i, functionTable.cardinality(i));
				if (value.equals("true")) {
					table.append(genericVariableName(i));
				}
				else if (value.equals("false")) {
					table.append("not "+genericVariableName(i));
				}
				else {
					table.append(genericVariableName(i));
					table.append(" = ");
					table.append(value);
				}
			}
			table.append(" then ");
			table.append(entryValue);
			table.append(" else ");
		}
	}

	Expression  inputExpression  = Expressions.parse(table.toString());
	Function<Integer, Integer> cardinalityOfIthVariable = i -> functionTable.cardinality(i);

	Map<String, String> mapFromCategoricalTypeNameToSizeString   = new LinkedHashMap<>();
	Map<String, String> mapFromVariableNameToTypeName = new LinkedHashMap<>();
	Map<String, String> mapFromUniquelyNamedConstantToTypeName = new LinkedHashMap<>();
	for (int i = 0; i < functionTable.numberVariables(); i++) {
		String typeName = genericTypeNameForVariable(i, cardinalityOfIthVariable.apply(i));
		mapFromCategoricalTypeNameToSizeString.put(typeName, "" + cardinalityOfIthVariable.apply(i));
		mapFromVariableNameToTypeName.put(genericVariableName(i), typeName);
		for (int j = 0; j != functionTable.cardinality(i); j++) {
			String jThConstant = genericConstantValueForVariable(j, i, functionTable.cardinality(i));
			mapFromUniquelyNamedConstantToTypeName.put(jThConstant, typeName);
		}
	}
	
	com.sri.ai.grinder.api.Theory theory = new EqualityTheory(true, true);

	Expression result = Compilation.compile(inputExpression, theory, mapFromVariableNameToTypeName, mapFromUniquelyNamedConstantToTypeName, mapFromCategoricalTypeNameToSizeString, list(), solverListener);
	
	return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-praise,代碼行數:67,代碼來源:UAIUtil.java

示例5: getLocalValue

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
public Expression getLocalValue() {
	if (localValue == null) {
		localValue = Expressions.parse(value);
	}
	return localValue;
}
 
開發者ID:aic-sri-international,項目名稱:aic-distributed-sgdpll,代碼行數:7,代碼來源:ContextDependentExpressionSolution.java


注:本文中的com.sri.ai.expresso.helper.Expressions.parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。