use of com.sri.ai.grinder.helper.FunctionSignature in project aic-expresso by aic-sri-international.
the class AntlrGrinderParserTest method testSet.
@Test
public void testSet() {
String string;
string = "{ ( on ) p(X, X) : true }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", AntlrGrinderParserTest.makeScopingSyntaxTree(new ArrayList<Expression>()), Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("p", "X", "X"), Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, "true")));
string = "{ ( on ) X : true }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", AntlrGrinderParserTest.makeScopingSyntaxTree(new ArrayList<Expression>()), "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, "true")));
string = "{ a : true}";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", null, "a", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, "true")));
string = "{ foo }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . }", "foo"));
string = "{ (on foo) bar }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", "foo"), "bar", null));
string = "{ (on x in y) z }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("in", "x", "y")), "z", null));
string = "{ foo : bar }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", null, "foo", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, "bar")));
string = "{f(X) : false}";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", null, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("f", "X"), Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, "false")));
List<FunctionSignature> functionSignatures = list(new FunctionSignature("p/1"));
pushParserFunctionSignatures(functionSignatures);
string = "{ [if p(a) then 1 else 0] : true }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", null, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTreesWithRandomPredicatesSignatures(functionSignatures, "[ . ]", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.IF_THEN_ELSE, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("p", "a"), "1", "0")), Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, "true")));
popParserFunctionSignatures();
string = "{ (on foo, fooz) bar }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, "foo", "fooz")), "bar", null));
string = "{ (on foo, fooz) bar : barz }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, "foo", "fooz")), "bar", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, "barz")));
string = "{ foo, bar, foo + bar }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, "foo", "bar", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("+", "foo", "bar"))));
string = "{ (on X in x(1..10, People)) X : X != (0, john) }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("in", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.INTEGER_INTERVAL, "1", "10"), "People")))), "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("!=", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "0", "john")))));
string = "{{ (on X in x(1..10, People)) X : X != (0, john) }}";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{{ . . . }}", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("in", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.INTEGER_INTERVAL, "1", "10"), "People")))), "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("!=", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "0", "john")))));
string = "{ (on X in (1..10 x People)) X : X != (0, john) }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("in", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.INTEGER_INTERVAL, "1", "10"), "People")))), "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("!=", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "0", "john")))));
string = "{{ (on X in (1..10 x People)) X : X != (0, john) }}";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{{ . . . }}", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("in", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.INTEGER_INTERVAL, "1", "10"), "People")))), "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("!=", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "0", "john")))));
string = "{ (on X in (1..10 x (People x Pets))) X : X != (0, (john, tom)) }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("in", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.INTEGER_INTERVAL, "1", "10"), Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, "People", "Pets"))))), "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("!=", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "0", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "john", "tom"))))));
string = "{{ (on X in (1..10 x (People x Pets))) X : X != (0, (john, tom)) }}";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{{ . . . }}", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("in", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.INTEGER_INTERVAL, "1", "10"), Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, "People", "Pets"))))), "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("!=", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "0", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "john", "tom"))))));
string = "{ (on X in (1..10 x (People x Pets x Homes))) X : X != (0, (john, tom, mgm)) }";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . . . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("in", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.INTEGER_INTERVAL, "1", "10"), Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, "People", "Pets", "Homes"))))), "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("!=", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "0", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "john", "tom", "mgm"))))));
string = "{{ (on X in (1..10 x (People x Pets x Homes))) X : X != (0, (john, tom, mgm)) }}";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{{ . . . }}", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("( on . )", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("in", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.INTEGER_INTERVAL, "1", "10"), Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.TUPLE_TYPE, "People", "Pets", "Homes"))))), "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("!=", "X", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "0", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Tuple.TUPLE_LABEL, "john", "tom", "mgm"))))));
string = "{}";
test(string, Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees("{ . }", Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(FunctorConstants.KLEENE_LIST)));
// Test illegal strings.
string = "{ foo";
testFail(string);
string = "{ (on foo1, foo2, foo3, foo4) bar1 : bar2 : bar3";
testFail(string);
string = "{ (on foo1, foo2, foo3, foo4) bar1 : bar2 : bar3 }";
testFail(string);
string = "{ (on foo1, foo2, foo3, foo4 bar1 : bar2 : bar3 }";
testFail(string);
string = "{";
testFail(string);
string = "{ , }";
testFail(string);
string = "{ foo, }";
testFail(string);
}
Aggregations