use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class PrologTermGenerator method toPrologTerm.
public static PrologTerm toPrologTerm(final Start node) throws ResultParserException {
PResult topnode = node.getPResult();
PrologTerm term = null;
if (topnode instanceof AYesResult) {
term = toPrologTerm(((AYesResult) topnode).getTerm());
} else if (topnode instanceof ANoResult) {
term = null;
} else if (topnode instanceof AInterruptedResult) {
term = null;
} else if (topnode instanceof AExceptionResult) {
String message = "ProB raised an exception: " + ((AExceptionResult) topnode).getString().getText();
throw new ResultParserException(message, null);
} else
throw new IllegalStateException("Unknown subclass of PResult: " + topnode.getClass().getCanonicalName());
return term;
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class BParser method getASTasFastProlog.
private static String getASTasFastProlog(final BParser parser, final File bfile, final Start tree, final ParsingBehaviour parsingBehaviour, IDefinitionFileProvider contentProvider) throws BCompoundException {
final RecursiveMachineLoader rml = new RecursiveMachineLoader(bfile.getParent(), contentProvider, parsingBehaviour);
rml.loadAllMachines(bfile, tree, parser.getDefinitions());
StructuredPrologOutput structuredPrologOutput = new StructuredPrologOutput();
rml.printAsProlog(structuredPrologOutput);
Collection<PrologTerm> sentences = structuredPrologOutput.getSentences();
StructuredPrologOutput output = new StructuredPrologOutput();
output.openList();
for (PrologTerm term : sentences) {
output.printTerm(term);
}
output.closeList();
output.fullstop();
FastReadTransformer transformer = new FastReadTransformer(output);
return transformer.write();
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class BindingGenerator method createBinding.
private static Map<String, PrologTerm> createBinding(final ListPrologTerm list) {
Map<String, PrologTerm> result;
result = new HashMap<String, PrologTerm>();
for (int i = 0; i < list.size(); i++) {
PrologTerm element = list.get(i);
if (element.isTerm()) {
CompoundPrologTerm binding = (CompoundPrologTerm) element;
if (binding.getArity() == 2 && "=".equals(binding.getFunctor())) {
extractBinding(result, binding);
} else
throw new IllegalArgumentException("Expected binding (=/2), but was " + binding.getFunctor() + "/" + String.valueOf(binding.getArity()));
} else
throw new IllegalArgumentException("Expected binding but was not a term");
}
return Collections.unmodifiableMap(result);
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class BindingGenerator method extractBinding.
private static void extractBinding(final Map<String, PrologTerm> result, final CompoundPrologTerm binding) {
PrologTerm varterm = binding.getArgument(1);
if (varterm.isAtom()) {
String name = ((CompoundPrologTerm) varterm).getFunctor();
PrologTerm value = binding.getArgument(2);
result.put(name, value);
} else
throw new IllegalArgumentException("Expected atomic variable name, but found " + varterm.toString());
}
use of de.prob.prolog.term.PrologTerm in project prob2 by bendisposto.
the class CSPAssertionsCommand method processResult.
@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
ListPrologTerm prologTermResults = BindingGenerator.getList(bindings.get(RESULT_VARIABLE));
ListPrologTerm prologTermResultTraces = BindingGenerator.getList(bindings.get(RESULT_TRACES_VARIABLE));
for (PrologTerm term : prologTermResults) {
if (term != null) {
results.add(term.getFunctor());
}
}
for (PrologTerm term : prologTermResultTraces) {
if (term instanceof ListPrologTerm) {
resultTraces.add(BindingGenerator.getList(term));
}
}
}
Aggregations