Search in sources :

Example 36 with CompoundPrologTerm

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());
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 37 with CompoundPrologTerm

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);
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 38 with CompoundPrologTerm

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);
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) Transition(de.prob.statespace.Transition) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 39 with CompoundPrologTerm

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());
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) StateError(de.prob.animator.domainobjects.StateError) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) Test(org.junit.Test)

Example 40 with CompoundPrologTerm

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());
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) Test(org.junit.Test)

Aggregations

CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)90 PrologTerm (de.prob.prolog.term.PrologTerm)79 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)74 Test (org.junit.Test)62 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)8 StructuredPrologOutput (de.prob.prolog.output.StructuredPrologOutput)7 ClassicalB (de.prob.animator.domainobjects.ClassicalB)6 VariablePrologTerm (de.prob.prolog.term.VariablePrologTerm)6 EventB (de.prob.animator.domainobjects.EventB)5 Transition (de.prob.statespace.Transition)5 ArrayList (java.util.ArrayList)4 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)3 EvalResult (de.prob.animator.domainobjects.EvalResult)3 IEvalElement (de.prob.animator.domainobjects.IEvalElement)3 ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)3 ComputationNotCompletedResult (de.prob.animator.domainobjects.ComputationNotCompletedResult)2 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)2 BigInteger (java.math.BigInteger)2 Collections (java.util.Collections)2 BParser (de.be4.classicalb.core.parser.BParser)1