use of com.sri.ai.grinder.rewriter.core.FirstOf in project aic-expresso by aic-sri-international.
the class SwitchTest method testMerge.
@Test
public void testMerge() {
Switch<String> switch1 = new Switch<>(stringMaker, Util.map("1", new Label("11"), "2", new Label("21")));
Switch<String> switch2 = new Switch<>(stringMaker, Util.map("1", new Label("12"), "3", new Label("31")));
Switch<String> switch3 = new Switch<>(stringMaker, Util.map());
Switch<String> switch4 = new Switch<>(stringMaker, Util.map("4", new Label("41")));
Switch<String> switch5 = new Switch<>(stringMaker, Util.map("3", new Label("32")));
Switch<String> expected = new Switch<>(stringMaker, Util.map("1", new FirstOf(list(new Label("11"), new Label("12"))), "2", new Label("21"), "3", new FirstOf(list(new Label("31"), new Label("32"))), "4", new Label("41")));
Rewriter merged = Switch.mergeSwitchesWithTheSameKeyMakerIntoASingleOne(list(switch1, switch2, switch3, switch4, switch5));
assertEquals(expected, merged);
}
use of com.sri.ai.grinder.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 CombiningTopRewriter(new Switch<String>(stringMaker, Util.map())));
expected = new Switch<String>(stringMaker, Util.map());
merged = TopRewriter.makeTopRewriterFromTopRewritersThatAreEitherFirstOfOrSwitches(initialRewriters);
assertEquals(expected, merged);
initialRewriters = list(new Switch<String>(stringMaker, Util.map()), new CombiningTopRewriter(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.makeTopRewriterFromTopRewritersThatAreEitherFirstOfOrSwitches(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.makeTopRewriterFromTopRewritersThatAreEitherFirstOfOrSwitches(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 CombiningTopRewriter(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 CombiningTopRewriter(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.makeTopRewriterFromTopRewritersThatAreEitherFirstOfOrSwitches(initialRewriters);
assertEquals(expected, merged);
}
use of com.sri.ai.grinder.rewriter.core.FirstOf in project aic-expresso by aic-sri-international.
the class FirstOfTest method runTest.
private void runTest(List<Rewriter> rewriters, Expression initial, Expression expected, Map<Expression, Expression> symbolsAndTypes) {
CompoundTheory theory = new CompoundTheory(new PropositionalTheory(), new DifferenceArithmeticTheory(false, true));
Context context = new TrueContext(theory);
context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(symbolsAndTypes);
Rewriter firstOf = new FirstOf(rewriters);
Expression solution = firstOf.apply(initial, context);
System.out.println("Solution: " + solution);
assertEquals(expected, solution);
}
use of com.sri.ai.grinder.rewriter.core.FirstOf in project aic-expresso by aic-sri-international.
the class SymbolicShell method evaluate.
private static void evaluate(Expression input, ConsoleIterator consoleIterator, Theory theory, Context context) {
Rewriter prettyRewriter = new Exhaustive(new Recursive(new FirstOf(theory.getTopRewriter(), new PrettySimplifier())));
Expression result = theory.evaluate(input, context);
result = prettyRewriter.apply(result, context);
consoleIterator.getOutputWriter().println(result + "\n");
}
Aggregations