Search in sources :

Example 1 with DefaultTopRewriter

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

the class SetDNFRewriter method createBaseRewriter.

private static Rewriter createBaseRewriter() {
    // Original Rewriters		
    TopRewriter topRewriter = new DefaultTopRewriter(new IntensionalUnionToUnionsOfIntensionalSetsOfBaseTypeTopRewriter(), // NOTE: added to simplify expressions like `if true then { (2, 2) } else {  }', which are common in this setup
    new BooleanSimplifier(), new UnionEmptySetTopRewriter(), new IntersectionEmptySetTopRewriter(), new IntensionalSetToConditionalTopRewriter(), new IntersectionIntensionalSetsTopRewriter(), new IntersectionExtensionalSetTopRewriter(), new DistributeIntersectionOverUnionTopRewriter());
    // Rewriters based on UAI 2017 Paper
    //		TopRewriter topRewriter = new DefaultTopRewriter(
    //			new TupleEqualityTopRewriter(),                               // Rule 1		
    //			new ElementOfExtensionalSetTopRewriter(),                     // Rule 2
    //			new ElementOfIntensionalUnionTopRewriter(),                   // Rule 3
    //			new IntensionalUnionEqualToEmptySetTopRewriter(),             // Rule 4
    //			new IntersectionEmptySetTopRewriter(),                        // Rule 5			
    //			new UnionEmptySetTopRewriter(),                               // Rule 6			
    //			new SetIntersectExtensionalSetEqualToEmptySetTopRewriter(),   // Rule 7
    //			new IntensionalUnionIntersectionEqualToEmptySetTopRewriter(), // Rule 8
    //			new DistributeIntersectionOverUnionTopRewriter(),             // Rule 9
    //			new UnionOfSetsEqualEmptySetTopRewriter(),                    // Rule 10
    //			new ExtensionalSetEqualEmptySetTopRewriter(),                 // Rule 11
    //			new BooleanSimplifier() // NOTE: added to simplify expressions like `if true then { (2, 2) } else {  }', which are common in this setup
    //			);		
    Rewriter literalExternalizer = new LiteralRewriter(new Recursive(new Exhaustive(topRewriter)));
    Rewriter result = new Exhaustive(new FirstOf(topRewriter, literalExternalizer));
    return result;
}
Also used : DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) Exhaustive(com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive) DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) TupleEqualityTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) BooleanSimplifier(com.sri.ai.grinder.sgdpllt.library.boole.BooleanSimplifier) LiteralRewriter(com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) LiteralRewriter(com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter) DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) TupleEqualityTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) FirstOf(com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf) Recursive(com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)

Example 2 with DefaultTopRewriter

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

the class TopRewriter method merge.

/**
	 * Takes a list of {@link TopRewriter}s,
	 * then determines a list of {@link Switch<T>} rewriters,
	 * each of them the merge of all {@link Switch<T>} rewriters with the same key maker
	 * (from {@link Switch.merge(List<Rewriter>)}.
	 * If this list contains more than one {@link Switch<T>} rewriter,
	 * returns a {@link DefaultTopRewriter} rewriter with them as base rewriters.
	 * If this list contains only one {@link Switch<T>} rewriter, returns it.
	 * @param topRewriters
	 * @param <T> the type of keys in the switch rewriters.
	 * @return
	 */
public static <T> TopRewriter merge(List<? extends TopRewriter> topRewriters) {
    List<Switch<T>> mergedTopRewriters = makeMergedSwitches(topRewriters);
    TopRewriter result;
    if (mergedTopRewriters.size() == 1) {
        result = getFirst(mergedTopRewriters);
    } else {
        result = new DefaultTopRewriter(mergedTopRewriters, true);
    }
    return result;
}
Also used : DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) Switch(com.sri.ai.grinder.sgdpllt.rewriter.core.Switch) DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter)

Example 3 with DefaultTopRewriter

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

DefaultTopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter)3 Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)2 TopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter)2 FirstOf (com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf)2 Switch (com.sri.ai.grinder.sgdpllt.rewriter.core.Switch)2 BooleanSimplifier (com.sri.ai.grinder.sgdpllt.library.boole.BooleanSimplifier)1 LiteralRewriter (com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter)1 Exhaustive (com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive)1 Recursive (com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)1 TupleEqualityTopRewriter (com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter)1 Test (org.junit.Test)1