Search in sources :

Example 1 with HOGMQueryRunner

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();
    }
}
Also used : ModelPage(com.sri.ai.praise.model.common.io.ModelPage) HOGMQueryRunner(com.sri.ai.praise.sgsolver.solver.HOGMQueryRunner) HOGMQueryResult(com.sri.ai.praise.sgsolver.solver.HOGMQueryResult) OptionException(joptsimple.OptionException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with HOGMQueryRunner

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();
}
Also used : Expression(com.sri.ai.expresso.api.Expression) HOGMQueryRunner(com.sri.ai.praise.sgsolver.solver.HOGMQueryRunner) AtomicReference(java.util.concurrent.atomic.AtomicReference) HOGMQueryResult(com.sri.ai.praise.sgsolver.solver.HOGMQueryResult)

Aggregations

HOGMQueryResult (com.sri.ai.praise.sgsolver.solver.HOGMQueryResult)2 HOGMQueryRunner (com.sri.ai.praise.sgsolver.solver.HOGMQueryRunner)2 Expression (com.sri.ai.expresso.api.Expression)1 ModelPage (com.sri.ai.praise.model.common.io.ModelPage)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 OptionException (joptsimple.OptionException)1