use of com.sri.ai.praise.sgsolver.solver.HOGMQueryRunner in project aic-praise by aic-sri-international.
the class PRAiSE method run.
public static void run(String[] args, Supplier<Theory> theorySupplier) {
try (SGSolverArgs solverArgs = getArgs(args)) {
List<ModelPage> hogModelsToQuery = getHOGModelsToQuery(solverArgs);
for (ModelPage hogModelToQuery : hogModelsToQuery) {
solverArgs.out.print("MODEL NAME = ");
solverArgs.out.println(hogModelToQuery.getName());
solverArgs.out.println("MODEL = ");
solverArgs.out.println(hogModelToQuery.getModel());
HOGMQueryRunner queryRunner = new HOGMQueryRunner(hogModelToQuery.getModel(), hogModelToQuery.getDefaultQueriesToRun());
if (theorySupplier != null) {
queryRunner.setOptionTheory(theorySupplier.get());
}
List<HOGMQueryResult> hogModelQueryResults = queryRunner.query();
hogModelQueryResults.forEach(hogModelQueryResult -> {
solverArgs.out.print("QUERY = ");
solverArgs.out.println(hogModelQueryResult.getQueryString());
solverArgs.out.print(RESULT_PREFIX);
solverArgs.out.println(queryRunner.simplifyAnswer(hogModelQueryResult.getResult(), hogModelQueryResult.getQueryExpression()));
solverArgs.out.print("TOOK = ");
solverArgs.out.println(duration(hogModelQueryResult.getMillisecondsToCompute()) + "\n");
if (hogModelQueryResult.isErrors()) {
hogModelQueryResult.getErrors().forEach(error -> {
solverArgs.out.println("ERROR =" + error.getErrorMessage());
if (error.getThrowable() != null) {
solverArgs.out.println("THROWABLE =");
error.getThrowable().printStackTrace(solverArgs.out);
}
});
}
});
}
} catch (Exception ex) {
System.err.println("Error calling SGSolver");
ex.printStackTrace();
}
}
use of com.sri.ai.praise.sgsolver.solver.HOGMQueryRunner in project aic-praise by aic-sri-international.
the class HOGMQueryTask method call.
@Override
public HOGMQueryResult call() {
final AtomicReference<HOGMQueryResult> result = new AtomicReference<>();
SGSolverDemoController.computeExpressionWithDesiredPrecision(() -> {
hogmQueryRunner = new HOGMQueryRunner(model, query);
List<HOGMQueryResult> queryResults = hogmQueryRunner.query();
if (queryResults.size() == 1) {
HOGMQueryResult queryResult = queryResults.get(0);
if (queryResult.isErrors()) {
result.set(queryResult);
} else {
Expression answer = hogmQueryRunner.simplifyAnswer(queryResult.getResult(), queryResult.getQueryExpression());
result.set(new HOGMQueryResult(queryResult.getQueryString(), queryResult.getQueryExpression(), queryResult.getParsedModel(), answer, queryResult.getMillisecondsToCompute()));
}
}
});
return result.get();
}
Aggregations