Search in sources :

Example 6 with TopRewriter

use of com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter 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

TopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter)6 Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)3 TupleEqualityTopRewriter (com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter)3 Test (org.junit.Test)3 DefaultTopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter)2 Exhaustive (com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive)2 FirstOf (com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf)2 Recursive (com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)2 TupleGetSetTopRewriter (com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleGetSetTopRewriter)2 Expression (com.sri.ai.expresso.api.Expression)1 BooleanSimplifier (com.sri.ai.grinder.sgdpllt.library.boole.BooleanSimplifier)1 ForAllRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ForAllRewriter)1 LiteralRewriter (com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter)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 Switch (com.sri.ai.grinder.sgdpllt.rewriter.core.Switch)1 RedirectingRewriter (com.sri.ai.grinder.sgdpllt.rewriter.help.RedirectingRewriter)1