use of de.prob.prolog.term.PrologTerm in project prob2 by bendisposto.
the class LoadRulesProjectCommand method printLoadTerm.
private void printLoadTerm(IPrologTermOutput pto) {
StructuredPrologOutput parserOutput = new StructuredPrologOutput();
this.project.printProjectAsPrologTerm(parserOutput);
for (PrologTerm term : parserOutput.getSentences()) {
pto.printTerm(term);
}
}
use of de.prob.prolog.term.PrologTerm in project prob2 by bendisposto.
the class LtlCheckingCommand method processResult.
@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
PrologTerm term = bindings.get(VARIABLE_NAME_RESULT);
if (term.hasFunctor("ok", 0)) {
LTLOk res = new LTLOk(ltlFormula);
result = res;
value = res;
} else if (term.hasFunctor("nostart", 0)) {
LTLError res = new LTLError(ltlFormula, "Could not find initialisation. Try to animating the model.");
result = res;
value = res;
} else if (term.hasFunctor("typeerror", 0)) {
LTLError res = new LTLError(ltlFormula, "Type error discovered in formula");
result = res;
value = res;
} else if (term.hasFunctor("incomplete", 0)) {
LTLNotYetFinished res = new LTLNotYetFinished(ltlFormula);
result = res;
value = res;
} else if (term.hasFunctor("counterexample", 3)) {
CompoundPrologTerm cpt = BindingGenerator.getCompoundTerm(term, 3);
List<Transition> counterExample = BindingGenerator.getList(cpt.getArgument(1)).stream().filter(pt -> !pt.hasFunctor("none", 0)).map(pt -> Transition.createTransitionFromCompoundPrologTerm(s, BindingGenerator.getCompoundTerm(pt, 4))).collect(Collectors.toList());
PathType pathType;
int loopEntry;
PrologTerm loopStatus = cpt.getArgument(2);
if (loopStatus.hasFunctor("no_loop", 0)) {
pathType = PathType.REDUCED;
loopEntry = -1;
} else if (loopStatus.hasFunctor("deadlock", 0)) {
pathType = PathType.FINITE;
loopEntry = -1;
} else if (loopStatus.hasFunctor("loop", 1)) {
pathType = PathType.INFINITE;
loopEntry = ((IntegerPrologTerm) loopStatus.getArgument(1)).getValue().intValue();
} else {
throw new UnexpectedLoopStatusException("LTL model check returned unexpected loop status: " + loopStatus);
}
List<Transition> pathToCE = BindingGenerator.getList(cpt.getArgument(3)).stream().map(pt -> Transition.createTransitionFromCompoundPrologTerm(s, BindingGenerator.getCompoundTerm(pt, 4))).collect(Collectors.toList());
LTLCounterExample res = new LTLCounterExample(ltlFormula, pathToCE, counterExample, loopEntry, pathType);
result = res;
value = res;
} else {
throw new UnknownLtlResult("Unknown result from LTL checking: " + term);
}
}
use of de.prob.prolog.term.PrologTerm in project prob2 by bendisposto.
the class CbcSolveCommand method processResult.
@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
PrologTerm idList = bindings.get(IDENTIFIER_LIST);
if (idList instanceof ListPrologTerm) {
for (PrologTerm id : (ListPrologTerm) idList) {
freeVariables.add(id.getFunctor());
}
}
PrologTerm prologTerm = bindings.get(EVALUATE_TERM_VARIABLE);
assert prologTerm instanceof CompoundPrologTerm;
String functor = prologTerm.getFunctor();
if ("time_out".equals(functor)) {
result = new ComputationNotCompletedResult(evalElement.getCode(), "time out");
}
if ("contradiction_found".equals(functor)) {
result = EvalResult.FALSE;
}
if ("solution".equals(functor)) {
ListPrologTerm solutionBindings = BindingGenerator.getList(prologTerm.getArgument(BINDINGS));
if (solutionBindings.isEmpty()) {
result = EvalResult.TRUE;
return;
}
Map<String, String> solutions = new HashMap<>();
for (PrologTerm b : solutionBindings) {
CompoundPrologTerm t = (CompoundPrologTerm) b;
solutions.put(t.getArgument(VAR_NAME).getFunctor(), t.getArgument(PRETTY_PRINT).getFunctor());
}
result = new EvalResult("TRUE", solutions);
}
if ("no_solution_found".equals(functor)) {
result = new ComputationNotCompletedResult(evalElement.getCode(), "no solution found (but one might exist)");
}
}
use of de.prob.prolog.term.PrologTerm in project prob2 by bendisposto.
the class GetOperationByPredicateCommand method processResult.
/**
* This method is called to extract relevant information from ProB's answer.
* The method is called by the Animator class, most likely it is not
* interesting for other classes.
*
* @see de.prob.animator.command.AbstractCommand#writeCommand(de.prob.prolog.output.IPrologTermOutput)
*/
@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
ListPrologTerm list = BindingGenerator.getList(bindings.get(NEW_STATE_ID_VARIABLE));
for (PrologTerm prologTerm : list) {
CompoundPrologTerm cpt = BindingGenerator.getCompoundTerm(prologTerm, 4);
operations.add(Transition.createTransitionFromCompoundPrologTerm(s, cpt));
}
for (PrologTerm prologTerm : BindingGenerator.getList(bindings.get(ERRORS_VARIABLE))) {
this.errors.add(prologTerm.getFunctor());
}
}
use of de.prob.prolog.term.PrologTerm in project prob2 by bendisposto.
the class FindTraceBetweenNodesCommand method processResult.
@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
PrologTerm trace = bindings.get(TRACE);
if (trace instanceof ListPrologTerm) {
for (PrologTerm term : (ListPrologTerm) trace) {
newTransitions.add(Transition.createTransitionFromCompoundPrologTerm(stateSpace, (CompoundPrologTerm) term));
}
} else {
String msg = "Trace was not found. Error was: " + trace.getFunctor();
logger.error(msg);
throw new NoTraceFoundException(msg);
}
}
Aggregations