Search in sources :

Example 91 with PrologTerm

use of de.prob.prolog.term.PrologTerm 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 92 with PrologTerm

use of de.prob.prolog.term.PrologTerm 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 93 with PrologTerm

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

the class GetEnableMatrixCommand method processResult.

// yes('.'(=('Matrix','.'(enable_rel(new,del,enable_edges(ok,ok,false,false)),[])),[]))
// enable_edges(Enable,KeepEnabled,Disable,KeepDisabled)
@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    ListPrologTerm elements = (ListPrologTerm) bindings.get(MATRIX_VAR);
    matrix.clear();
    for (PrologTerm term : elements) {
        EventPair key = new EventPair(term.getArgument(1).getFunctor(), term.getArgument(2).getFunctor());
        matrix.put(key, new EnableMatixEntry(term.getArgument(3)));
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Example 94 with PrologTerm

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

the class GetMachineOperationInfos method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    for (PrologTerm prologTerm : BindingGenerator.getList(bindings, RESULT_VARIABLE)) {
        final String opName = prologTerm.getArgument(1).getFunctor();
        final List<String> outputParameterNames = ((ListPrologTerm) prologTerm.getArgument(2)).stream().map(PrologTerm::getFunctor).collect(Collectors.toList());
        final List<String> parameterNames = ((ListPrologTerm) prologTerm.getArgument(3)).stream().map(PrologTerm::getFunctor).collect(Collectors.toList());
        operationInfos.add(new OperationInfo(opName, parameterNames, outputParameterNames));
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Example 95 with PrologTerm

use of de.prob.prolog.term.PrologTerm 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)

Aggregations

PrologTerm (de.prob.prolog.term.PrologTerm)103 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)86 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)85 Test (org.junit.Test)64 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)11 StructuredPrologOutput (de.prob.prolog.output.StructuredPrologOutput)10 VariablePrologTerm (de.prob.prolog.term.VariablePrologTerm)8 Transition (de.prob.statespace.Transition)5 IEvalElement (de.prob.animator.domainobjects.IEvalElement)4 ArrayList (java.util.ArrayList)4 CheckBooleanPropertyCommand (de.prob.animator.command.CheckBooleanPropertyCommand)3 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)3 EvalResult (de.prob.animator.domainobjects.EvalResult)3 ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)3 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)3 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)2 LtlParseException (de.be4.ltl.core.parser.LtlParseException)2 ClassicalB (de.prob.animator.domainobjects.ClassicalB)2 ComputationNotCompletedResult (de.prob.animator.domainobjects.ComputationNotCompletedResult)2 StateError (de.prob.animator.domainobjects.StateError)2