use of de.prob.prolog.term.CompoundPrologTerm in project probparsers by bendisposto.
the class PrologGeneratorTest method testForAllImplication.
@Test
public void testForAllImplication() throws Exception {
final PrologTerm id = new CompoundPrologTerm("xyz");
// ap(dpred(blubb))
final PrologTerm pred = new CompoundPrologTerm("blubb");
final PrologTerm dpred = new CompoundPrologTerm("dpred", pred);
final PrologTerm ap = new CompoundPrologTerm("ap", dpred);
// G [x]
final PrologTerm transPred = new CompoundPrologTerm("x");
final PrologTerm wrapped2 = new CompoundPrologTerm("dtrans", transPred);
final PrologTerm action = new CompoundPrologTerm("action", wrapped2);
final PrologTerm glob = new CompoundPrologTerm("globally", action);
final PrologTerm expected = new CompoundPrologTerm("forall", id, ap, glob);
check("!xyz. ( {blubb} => G [x])", expected);
}
use of de.prob.prolog.term.CompoundPrologTerm in project probparsers by bendisposto.
the class PrologGeneratorTest method testHistorically.
@Test
public void testHistorically() throws Exception {
final PrologTerm expected = new CompoundPrologTerm("historically", TERM_TRUE);
check("H true ", expected);
}
use of de.prob.prolog.term.CompoundPrologTerm in project probparsers by bendisposto.
the class PrologGeneratorTest method testComplex2.
@Test
public void testComplex2() throws Exception {
final PrologTerm pred1 = new CompoundPrologTerm("xxx");
final PrologTerm wrapped1 = new CompoundPrologTerm("dpred", pred1);
final PrologTerm ap1 = new CompoundPrologTerm("ap", wrapped1);
final PrologTerm pred2 = new CompoundPrologTerm("blubb");
final PrologTerm wrapped2 = new CompoundPrologTerm("dpred", pred2);
final PrologTerm ap2 = new CompoundPrologTerm("ap", wrapped2);
final PrologTerm fin = new CompoundPrologTerm("finally", ap2);
final PrologTerm glob = new CompoundPrologTerm("globally", fin);
final PrologTerm imp = new CompoundPrologTerm("implies", ap1, glob);
final PrologTerm expected = new CompoundPrologTerm("not", imp);
check("not({xxx} => GF {blubb})", expected);
}
use of de.prob.prolog.term.CompoundPrologTerm in project probparsers by bendisposto.
the class StructuredPrologOutput method closeTerm.
public IPrologTermOutput closeTerm() {
PrologTerm[] elements = getArguments();
final String functor = currentFunctor;
popFromStack();
addArgument(new CompoundPrologTerm(functor, elements));
return this;
}
use of de.prob.prolog.term.CompoundPrologTerm in project probparsers by bendisposto.
the class PrologTermGenerator method toPrologTerm.
private static PrologTerm toPrologTerm(final PTerm node) {
PrologTerm term;
if (node instanceof ANumberTerm) {
String text = ((ANumberTerm) node).getNumber().getText();
term = new IntegerPrologTerm(new BigInteger(text));
} else if (node instanceof AAtomTerm) {
String text = ((AAtomTerm) node).getName().getText();
if ("[]".equals(text)) {
term = new ListPrologTerm(EMPTY_PROLOG_LIST);
} else {
text = removeQuotes(text);
term = new CompoundPrologTerm(text);
}
} else if (node instanceof ATerm) {
ATerm aterm = (ATerm) node;
int listSize = getListSize(node);
if (listSize >= 0) {
PrologTerm[] list = new PrologTerm[listSize];
fillListWithElements(list, aterm);
term = new ListPrologTerm(list);
} else {
String functor = removeQuotes(aterm.getFunctor().getText());
PrologTerm[] params = evalParameters((AParams) aterm.getParams());
term = new CompoundPrologTerm(functor, params);
}
} else if (node instanceof AVariableTerm) {
String text = removeQuotes(((AVariableTerm) node).getVariable().getText());
term = new VariablePrologTerm(text);
} else
throw new IllegalStateException("Unexpected subclass of PTerm: " + node.getClass().getCanonicalName());
return term;
}
Aggregations