use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class AssignmentsIteratorTest method test2.
@Test
public void test2() {
Registry registry = new DefaultRegistry();
Type myType = new Categorical("People", 2, arrayList(makeSymbol("oscar"), makeSymbol("mary")));
Symbol x = makeSymbol("X");
Symbol y = makeSymbol("Y");
String expected = "{X=oscar, Y=oscar}\n" + "{X=mary, Y=oscar}\n" + "{X=oscar, Y=mary}\n" + "{X=mary, Y=mary}";
Symbol myTypeExpression = makeSymbol(myType.getName());
registry = registry.makeNewContextWithAddedType(myType);
registry = registry.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(x, myTypeExpression, y, myTypeExpression));
AssignmentMapsIterator assignmentsIterator = new AssignmentMapsIterator(list(x, y), registry);
String actual = join("\n", assignmentsIterator);
// System.out.println(actual);
assertEquals(expected, actual);
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class AssignmentsIteratorTest method test3.
@Test
public void test3() {
Registry registry = new DefaultRegistry();
Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("oscar"), makeSymbol("mary")));
Type petsType = new Categorical("Pets", 3, arrayList(makeSymbol("fido"), makeSymbol("purrs")));
Symbol x = makeSymbol("X");
Symbol y = makeSymbol("Y");
String expected = "{X=oscar, Y=fido}\n" + "{X=mary, Y=fido}\n" + "{X=people3, Y=fido}\n" + "{X=people4, Y=fido}\n" + "{X=oscar, Y=purrs}\n" + "{X=mary, Y=purrs}\n" + "{X=people3, Y=purrs}\n" + "{X=people4, Y=purrs}\n" + "{X=oscar, Y=pets3}\n" + "{X=mary, Y=pets3}\n" + "{X=people3, Y=pets3}\n" + "{X=people4, Y=pets3}";
Symbol myPeopleTypeExpression = makeSymbol(peopleType.getName());
Symbol myPetsTypeExpression = makeSymbol(petsType.getName());
registry = registry.makeNewContextWithAddedType(peopleType);
registry = registry.makeNewContextWithAddedType(petsType);
registry = registry.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(x, myPeopleTypeExpression, y, myPetsTypeExpression));
AssignmentMapsIterator assignmentsIterator = new AssignmentMapsIterator(list(x, y), registry);
String actual = join("\n", assignmentsIterator);
// System.out.println(actual);
assertEquals(expected, actual);
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class SampleCommonInterpreterTest method testSumOverCategoricalDomain.
@Test
public void testSumOverCategoricalDomain() {
updateContextWithIndexAndType("N", new Categorical("People", 5, parse("p1"), parse("p2"), parse("p3"), parse("p4"), parse("p5")));
// NOTE: random picks p1 and p2
runTest(2, true, "sum({{(on N in People) 2}})", "10");
// NOTE: keep this order of calls as the fixed Random will pick p3 and p4
runTest(2, true, "sum({{(on N in People) if N = p3 then 4 else 2}})", "15");
// NOTE: picks p5 and p5
runTest(2, true, "sum({{(on N in People) 2 : N != p2}})", "8");
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class SampleCommonInterpreterTest method testCategoricalExample1.
@Test
public void testCategoricalExample1() {
updateContextWithIndexAndType("N", new Categorical("Person", 100));
String intensionalSet = "{{(on I in Person) if I != person1 then 20 else 30 : I != person2 }}";
String[][] functionNamesAndExactValues = new String[][] { { "sum", "1990" }, { "max", "30" }, { "product", "950737950171172051122527404032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } };
runSampleCompareToExact(100, true, intensionalSet, functionNamesAndExactValues);
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class LambdaBetaReductionSimplifierTest method testSimpleReduction.
@Test
public void testSimpleReduction() {
Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("ann"), makeSymbol("bob")));
Context context = new TrueContext();
context = context.makeNewContextWithAddedType(peopleType);
Assert.assertEquals(parse("if X = ann then 0 else if X = bob then 0 else 0"), simplifier.apply(parse("(lambda : if X = ann then 0 else if X = bob then 0 else 0)()"), context));
Assert.assertEquals(parse("if ann = ann then 0 else if ann = bob then 0 else 0"), simplifier.apply(parse("(lambda X in People : if X = ann then 0 else if X = bob then 0 else 0)(ann)"), context));
Assert.assertEquals(parse("if ann = ann then 0 else if bob = bob then 0 else 0"), simplifier.apply(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann, bob)"), context));
}
Aggregations