Search in sources :

Example 6 with FirstOf

use of com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf in project aic-expresso by aic-sri-international.

the class SwitchTest method topRewriterTest.

@Test
public void topRewriterTest() {
    List<TopRewriter> initialRewriters;
    Rewriter expected;
    Rewriter merged;
    initialRewriters = list(new Switch<String>(stringMaker, Util.map()), new DefaultTopRewriter(new Switch<String>(stringMaker, Util.map())));
    expected = new Switch<String>(stringMaker, Util.map());
    merged = TopRewriter.merge(initialRewriters);
    assertEquals(expected, merged);
    initialRewriters = list(new Switch<String>(stringMaker, Util.map()), new DefaultTopRewriter(new Switch<String>(stringMaker, Util.map()), new Switch<Object>(syntacticFormTypeMaker, Util.map())), new Switch<Object>(syntacticFormTypeMaker, Util.map()));
    expected = new FirstOf(new Switch<String>(stringMaker, Util.map()), new Switch<Object>(syntacticFormTypeMaker, Util.map()));
    merged = TopRewriter.merge(initialRewriters);
    assertEquals(expected, merged);
    initialRewriters = list(new Switch<String>(stringMaker, Util.map("1", new FirstOf(new Label("11"), new Label("12")), "2", new Label("21"), "3", new Label("31"), "4", new Label("41"))));
    expected = new Switch<String>(stringMaker, Util.map("1", new FirstOf(new Label("11"), new Label("12")), "2", new Label("21"), "3", new Label("31"), "4", new Label("41")));
    merged = TopRewriter.merge(initialRewriters);
    assertEquals(expected, merged);
    initialRewriters = list(new Switch<String>(stringMaker, Util.map("1", new FirstOf(new Label("11"), new Label("12")), "2", new Label("21"), "3", new FirstOf(new Label("31")), "4", new Label("41"))), new DefaultTopRewriter(new Switch<String>(stringMaker, Util.map("1", new FirstOf(new Label("12"), /* again */
    new Label("13")), "2", new FirstOf(new Label("22"), new Label("23")), "3", new Label("31"), /* again */
    "4", new Label("42"))), new Switch<Object>(syntacticFormTypeMaker, Util.map("Symbol", new FirstOf(new Label("S1"), new Label("S2")), "Function application", new FirstOf(new Label("F1"), new Label("F2")), "Lambda expression", new Label("L1")))), new Switch<Object>(syntacticFormTypeMaker, Util.map("Symbol", new FirstOf(new Label("S2"), new Label("S3")), "Function application", new Label("F2"), "Lambda expression", new FirstOf(new Label("L2"), new Label("L3")))));
    expected = new DefaultTopRewriter(new Switch<String>(stringMaker, Util.map("1", new FirstOf(new Label("11"), new Label("12"), new Label("13")), "2", new FirstOf(new Label("21"), new Label("22"), new Label("23")), "3", new Label("31"), "4", new FirstOf(list(new Label("41"), new Label("42"))))), new Switch<Object>(syntacticFormTypeMaker, Util.map("Symbol", new FirstOf(new Label("S1"), new Label("S2"), new Label("S3")), "Function application", new FirstOf(new Label("F1"), new Label("F2")), "Lambda expression", new FirstOf(new Label("L1"), new Label("L2"), new Label("L3")))));
    merged = TopRewriter.merge(initialRewriters);
    assertEquals(expected, merged);
}
Also used : DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) Switch(com.sri.ai.grinder.sgdpllt.rewriter.core.Switch) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) FirstOf(com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf) Test(org.junit.Test)

Aggregations

Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)6 FirstOf (com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf)6 TopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter)5 LiteralRewriter (com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter)3 DefaultTopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter)3 Exhaustive (com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive)3 Recursive (com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)3 ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)2 Switch (com.sri.ai.grinder.sgdpllt.rewriter.core.Switch)2 Test (org.junit.Test)2 Expression (com.sri.ai.expresso.api.Expression)1 Context (com.sri.ai.grinder.sgdpllt.api.Context)1 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)1 BooleanSimplifier (com.sri.ai.grinder.sgdpllt.library.boole.BooleanSimplifier)1 ForAllRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ForAllRewriter)1 ThereExistsRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ThereExistsRewriter)1 MaxRewriter (com.sri.ai.grinder.sgdpllt.library.number.MaxRewriter)1 ProductRewriter (com.sri.ai.grinder.sgdpllt.library.number.ProductRewriter)1 SummationRewriter (com.sri.ai.grinder.sgdpllt.library.number.SummationRewriter)1 CardinalityTopRewriter (com.sri.ai.grinder.sgdpllt.library.set.CardinalityTopRewriter)1