use of com.sri.ai.grinder.helper.AssignmentMapsIterator 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.grinder.helper.AssignmentMapsIterator 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.grinder.helper.AssignmentMapsIterator in project aic-expresso by aic-sri-international.
the class SGDPLLTTester method bruteForceModelCounterForVariableGivenInterpreterAndAssignmentToOtherVariables.
private static Expression bruteForceModelCounterForVariableGivenInterpreterAndAssignmentToOtherVariables(Expression variable, Expression conjunction, BruteForceCommonInterpreter interpreter, Theory theory, Context context) {
output("Computing model count by brute force of: " + conjunction);
int modelCount = 0;
Expression testingVariable = variable;
AssignmentMapsIterator testingVariableAssignmentsIterator = new AssignmentMapsIterator(list(testingVariable), context);
for (Map<Expression, Expression> testingVariableAssignment : in(testingVariableAssignmentsIterator)) {
Context extendedContext = Assignment.extendAssignments(testingVariableAssignment, context);
Expression value = interpreter.apply(conjunction, extendedContext);
if (value.equals(TRUE)) {
modelCount++;
}
// output("For " + completeInterpreter.getAssignment() + ",");
// output("value is " + value);
// output("Model count is " + modelCount + "\n");
}
return makeSymbol(modelCount);
}
use of com.sri.ai.grinder.helper.AssignmentMapsIterator in project aic-expresso by aic-sri-international.
the class AssignmentsIteratorTest method test1.
@Test
public void test1() {
Registry registry = new DefaultRegistry();
Type myType = new Categorical("People", 4, 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=people3, Y=oscar}\n" + "{X=people4, Y=oscar}\n" + "{X=oscar, Y=mary}\n" + "{X=mary, Y=mary}\n" + "{X=people3, Y=mary}\n" + "{X=people4, Y=mary}\n" + "{X=oscar, Y=people3}\n" + "{X=mary, Y=people3}\n" + "{X=people3, Y=people3}\n" + "{X=people4, Y=people3}\n" + "{X=oscar, Y=people4}\n" + "{X=mary, Y=people4}\n" + "{X=people3, Y=people4}\n" + "{X=people4, Y=people4}";
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);
}
Aggregations