本文整理汇总了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;
}
示例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;
}
示例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());
}
示例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;
}
示例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