use of de.prob.prolog.term.CompoundPrologTerm 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.CompoundPrologTerm 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);
}
}
use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.
the class ExecuteUntilCommand method processResult.
@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
ListPrologTerm trace = BindingGenerator.getList(bindings.get(TRACE_VARIABLE));
result = bindings.get(RESULT_VARIABLE);
for (PrologTerm term : trace) {
CompoundPrologTerm t = BindingGenerator.getCompoundTerm(term, 4);
Transition operation = Transition.createTransitionFromCompoundPrologTerm(statespace, t);
resultTrace.add(operation);
}
}
use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.
the class GetStateBasedErrorsCommandTest method testProcessResult.
@Test
public void testProcessResult() {
@SuppressWarnings("unchecked") ISimplifiedROMap<String, PrologTerm> map = mock(ISimplifiedROMap.class);
when(map.get("Errors")).thenReturn(new ListPrologTerm(new CompoundPrologTerm("error", new CompoundPrologTerm("foo"), new CompoundPrologTerm("bar"), new CompoundPrologTerm("baz"))));
GetStateBasedErrorsCommand command = new GetStateBasedErrorsCommand("state");
command.processResult(map);
Collection<StateError> coll = command.getResult();
StateError se = coll.iterator().next();
assertEquals("foo", se.getEvent());
assertEquals("bar", se.getShortDescription());
assertEquals("baz", se.getLongDescription());
}
use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.
the class GetStateBasedErrorsCommandTest method testWriteCommand.
@Test
public void testWriteCommand() {
StructuredPrologOutput prologTermOutput = new StructuredPrologOutput();
GetStateBasedErrorsCommand command = new GetStateBasedErrorsCommand("42");
command.writeCommand(prologTermOutput);
prologTermOutput.fullstop().flush();
Collection<PrologTerm> sentences = prologTermOutput.getSentences();
PrologTerm next = sentences.iterator().next();
assertNotNull(next);
assertTrue(next instanceof CompoundPrologTerm);
CompoundPrologTerm t = (CompoundPrologTerm) next;
assertEquals("get_state_errors", t.getFunctor());
assertEquals(2, t.getArity());
PrologTerm argument = t.getArgument(1);
assertTrue(argument.isNumber());
PrologTerm argument2 = t.getArgument(2);
assertTrue(argument2.isVariable());
}
Aggregations