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);
}
}
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());
}
}
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;
}
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());
}
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);
}
Aggregations