Search in sources :

Example 36 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas.

@Test
public void testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
    // using different testing variables and types to test distribution of testing information
    // to sub constraint theories.
    Categorical booleanType = BOOLEAN_TYPE;
    Categorical dogsType = new Categorical("Dogs", 4, arrayList(parse("fido"), parse("rex")));
    IntegerInterval oneTwoThree = new IntegerInterval(1, 3);
    Map<String, Type> variablesAndTypes = map("F", booleanType, "G", booleanType, "R", dogsType, "S", dogsType, "T", oneTwoThree, "U", oneTwoThree);
    theoryTestingSupport.setVariableNamesAndTypesForTesting(variablesAndTypes);
    runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
Also used : EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) Categorical(com.sri.ai.expresso.type.Categorical) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) Test(org.junit.Test)

Example 37 with Categorical

use of com.sri.ai.expresso.type.Categorical 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);
}
Also used : AssignmentMapsIterator(com.sri.ai.grinder.helper.AssignmentMapsIterator) Type(com.sri.ai.expresso.api.Type) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) Symbol(com.sri.ai.expresso.api.Symbol) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Registry(com.sri.ai.grinder.api.Registry) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 38 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class SampleCommonInterpreterTest method testCategoricalExample2.

@Test
public void testCategoricalExample2() {
    updateContextWithIndexAndType("N", new Categorical("Person", 1000000));
    String intensionalSet = "{{(on I in Person) if I != person1 then 20 else 30 : I != person2 }}";
    String[][] functionNamesAndExactValues = new String[][] { // 42sec brute, 1186ms sample
    { "sum", "19999990" }, // 26sec brute,  762ms sample
    { "max", "30" }, // 25sec brute,  703ms sample
    { "product", "7.425492171971923688023442712229336E+1301028" } };
    runSampleCompareToExact(1, true, intensionalSet, functionNamesAndExactValues);
}
Also used : Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 39 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class MeasureTest method testThrowsUnsupportedGreaterThan1Index.

@Test(expected = UnsupportedOperationException.class)
public void testThrowsUnsupportedGreaterThan1Index() {
    updateContextWithIndexAndType("N", new Categorical("People", 5, parse("p1"), parse("p2"), parse("p3"), parse("p4"), parse("p5")));
    measure("{{(on I in People, J in People) (I, J) : true}}");
}
Also used : Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Aggregations

Categorical (com.sri.ai.expresso.type.Categorical)39 Test (org.junit.Test)30 Type (com.sri.ai.expresso.api.Type)19 Expression (com.sri.ai.expresso.api.Expression)13 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)10 FunctionType (com.sri.ai.expresso.type.FunctionType)6 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)5 RealInterval (com.sri.ai.expresso.type.RealInterval)5 TupleType (com.sri.ai.expresso.type.TupleType)5 Symbol (com.sri.ai.expresso.api.Symbol)4 IntegerExpressoType (com.sri.ai.expresso.type.IntegerExpressoType)4 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)4 Registry (com.sri.ai.grinder.api.Registry)4 Context (com.sri.ai.grinder.api.Context)3 DefaultRegistry (com.sri.ai.grinder.core.DefaultRegistry)3 TrueContext (com.sri.ai.grinder.core.TrueContext)3 Beta (com.google.common.annotations.Beta)2 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)2 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)2 AssignmentMapsIterator (com.sri.ai.grinder.helper.AssignmentMapsIterator)2