Search in sources :

Example 81 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.

the class ExpandedFormula method init.

public void init(final CompoundPrologTerm cpt) {
    name = cpt.getArgument(1).getFunctor();
    fields.put("name", escapeUnicode(name));
    // Value
    PrologTerm v = cpt.getArgument(2);
    value = getValue(v);
    fields.put("value", value instanceof String ? escapeUnicode((String) value) : value);
    fields.put("hasError", hasError);
    // Children
    id = cpt.getArgument(3).getFunctor();
    fields.put("id", id);
    ListPrologTerm list = BindingGenerator.getList(cpt.getArgument(4));
    if (!list.isEmpty()) {
        children = new ArrayList<>();
        List<Object> childrenFields = new ArrayList<>();
        for (PrologTerm prologTerm : list) {
            ExpandedFormula expandedFormula = new ExpandedFormula(BindingGenerator.getCompoundTerm(prologTerm, 4));
            children.add(expandedFormula);
            childrenFields.add(expandedFormula.getFields());
        }
        fields.put("children", childrenFields);
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) ArrayList(java.util.ArrayList) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Example 82 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.

the class GetCurrentPreferencesCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    ListPrologTerm prefs = BindingGenerator.getList(bindings.get(PREFERENCES_VARIABLE));
    for (PrologTerm prologTerm : prefs) {
        CompoundPrologTerm cpt = BindingGenerator.getCompoundTerm(prologTerm, 2);
        preferences.put(cpt.getArgument(1).getFunctor(), cpt.getArgument(2).getFunctor());
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Example 83 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.

the class TestHelper method mkAtomMock.

public static ISimplifiedROMap<String, PrologTerm> mkAtomMock(final String... strings) {
    @SuppressWarnings("unchecked") ISimplifiedROMap<String, PrologTerm> map = mock(ISimplifiedROMap.class);
    for (int i = 0; i < strings.length; i += 2) {
        String key = strings[i];
        String value = strings[i + 1];
        when(map.get(key)).thenReturn(new CompoundPrologTerm(value));
    }
    return map;
}
Also used : CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 84 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.

the class LoadBProjectCommandTest method testWriteCommand.

@Test
public void testWriteCommand() throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    URL resource = classLoader.getResource("examples/scheduler.mch");
    File f = new File(resource.toURI());
    StructuredPrologOutput prologTermOutput = new StructuredPrologOutput();
    ClassicalBFactory factory = new ClassicalBFactory(null);
    BParser bparser = new BParser();
    Start ast = factory.parseFile(f, bparser);
    RecursiveMachineLoader rml = factory.parseAllMachines(ast, f.getParent(), f, bparser.getContentProvider(), bparser);
    LoadBProjectCommand command = new LoadBProjectCommand(rml, f);
    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("load_classical_b_from_list_of_facts", t.getFunctor());
    assertEquals(2, t.getArity());
    PrologTerm argument = t.getArgument(2);
    assertTrue(argument.isList());
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) ClassicalBFactory(de.prob.scripting.ClassicalBFactory) Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) File(java.io.File) URL(java.net.URL) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

Example 85 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.

the class GetStateBasedErrorsCommandTest method testErrorProcessResult2.

@Test(expected = ResultParserException.class)
public void testErrorProcessResult2() {
    @SuppressWarnings("unchecked") ISimplifiedROMap<String, PrologTerm> map = mock(ISimplifiedROMap.class);
    when(map.get("Errors")).thenReturn(new CompoundPrologTerm("foobar"));
    GetStateBasedErrorsCommand command = new GetStateBasedErrorsCommand("state");
    command.processResult(map);
}
Also used : 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