Search in sources :

Example 51 with CompoundPrologTerm

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

the class ExpandedFormula method getValue.

private Object getValue(final PrologTerm v) {
    String functor = v.getFunctor();
    CompoundPrologTerm cpt = BindingGenerator.getCompoundTerm(v, 1);
    switch(functor) {
        case "p":
            return cpt.getArgument(1).getFunctor().equals("true");
        case "v":
            return UnicodeTranslator.toUnicode(cpt.getArgument(1).getFunctor());
        case "e":
            hasError = true;
            return cpt.getArgument(1).getFunctor();
        default:
            throw new IllegalArgumentException("Received unexpected result from Prolog. " + "Expected is either p, v or e as a functor, but Prolog returned " + functor);
    }
}
Also used : CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm)

Example 52 with CompoundPrologTerm

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

the class UnsatMinimalCoreCommand method processResult.

@Override
public void processResult(ISimplifiedROMap<String, PrologTerm> bindings) {
    CompoundPrologTerm compoundTerm = BindingGenerator.getCompoundTerm(bindings.get(RESULT_VARIABLE), 0);
    String code = compoundTerm.getFunctor();
    if (pred instanceof EventB) {
        core = new EventB(code, FormulaExpand.EXPAND);
    } else {
        core = new ClassicalB(code, FormulaExpand.EXPAND);
    }
}
Also used : EventB(de.prob.animator.domainobjects.EventB) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ClassicalB(de.prob.animator.domainobjects.ClassicalB)

Example 53 with CompoundPrologTerm

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

the class PrimePredicateCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    CompoundPrologTerm compoundTerm = BindingGenerator.getCompoundTerm(bindings.get(PRIMED_PREDICATE_VARIABLE), 0);
    String code = compoundTerm.getFunctor();
    if (evalElement instanceof EventB) {
        result = new EventB(code, FormulaExpand.EXPAND);
    } else {
        result = new ClassicalB(code, FormulaExpand.EXPAND);
    }
}
Also used : EventB(de.prob.animator.domainobjects.EventB) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ClassicalB(de.prob.animator.domainobjects.ClassicalB)

Example 54 with CompoundPrologTerm

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

the class PrologGeneratorTest method testDET.

@Test
public void testDET() throws Exception {
    final PrologTerm transPred1 = new CompoundPrologTerm("bla");
    final PrologTerm wrapped1 = new CompoundPrologTerm("dtrans", transPred1);
    final PrologTerm transPred2 = new CompoundPrologTerm("argg");
    final PrologTerm wrapped2 = new CompoundPrologTerm("dtrans", transPred2);
    final PrologTerm args = new ListPrologTerm(wrapped1, wrapped2);
    final PrologTerm det = new CompoundPrologTerm("det", args);
    final PrologTerm expected = new CompoundPrologTerm("ap", det);
    check("deterministic(bla   , argg)", expected);
}
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) Test(org.junit.Test)

Example 55 with CompoundPrologTerm

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

the class PrologGeneratorTest method testOr.

@Test
public void testOr() throws Exception {
    final PrologTerm expected = new CompoundPrologTerm("or", TERM_TRUE, TERM_FALSE);
    check("true or  false", expected);
}
Also used : CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) 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