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;
}
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;
}
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);
}
Aggregations