Search in sources :

Example 1 with NoSolutionException

use of alice.tuprolog.NoSolutionException in project Osmand by osmandapp.

the class AbstractPrologCommandPlayer method execute.

@Override
public List<String> execute(List<Struct> listCmd) {
    Struct list = new Struct(listCmd.toArray(new Term[listCmd.size()]));
    // $NON-NLS-1$
    Var result = new Var("RESULT");
    List<String> files = new ArrayList<String>();
    if (prologSystem == null) {
        return files;
    }
    if (log.isInfoEnabled()) {
        log.info("Query speak files " + listCmd);
    }
    SolveInfo res = prologSystem.solve(new Struct(P_RESOLVE, list, result));
    if (res.isSuccess()) {
        try {
            prologSystem.solveEnd();
            Term solution = res.getVarValue(result.getName());
            Iterator<?> listIterator = ((Struct) solution).listIterator();
            while (listIterator.hasNext()) {
                Object term = listIterator.next();
                if (term instanceof Struct) {
                    files.add(((Struct) term).getName());
                }
            }
        } catch (NoSolutionException e) {
        }
    }
    if (log.isInfoEnabled()) {
        log.info("Speak files " + files);
    }
    return files;
}
Also used : NoSolutionException(alice.tuprolog.NoSolutionException) Var(alice.tuprolog.Var) ArrayList(java.util.ArrayList) Term(alice.tuprolog.Term) SolveInfo(alice.tuprolog.SolveInfo) Struct(alice.tuprolog.Struct)

Example 2 with NoSolutionException

use of alice.tuprolog.NoSolutionException in project Osmand by osmandapp.

the class AbstractPrologCommandPlayer method solveSimplePredicate.

protected Term solveSimplePredicate(String predicate) {
    Term val = null;
    // $NON-NLS-1$
    Var v = new Var("MyVariable");
    SolveInfo s = prologSystem.solve(new Struct(predicate, v));
    if (s.isSuccess()) {
        prologSystem.solveEnd();
        try {
            val = s.getVarValue(v.getName());
        } catch (NoSolutionException e) {
        }
    }
    return val;
}
Also used : NoSolutionException(alice.tuprolog.NoSolutionException) Var(alice.tuprolog.Var) Term(alice.tuprolog.Term) SolveInfo(alice.tuprolog.SolveInfo) Struct(alice.tuprolog.Struct)

Aggregations

NoSolutionException (alice.tuprolog.NoSolutionException)2 SolveInfo (alice.tuprolog.SolveInfo)2 Struct (alice.tuprolog.Struct)2 Term (alice.tuprolog.Term)2 Var (alice.tuprolog.Var)2 ArrayList (java.util.ArrayList)1