Search in sources :

Example 81 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class NeuralNetworkTest method testIris.

@Test
public void testIris() throws Exception {
    setKSession(getModelSession(source2, VERBOSE));
    setKbase(getKSession().getKieBase());
    // init model
    getKSession().fireAllRules();
    Assert.assertEquals(21, getNumAssertedSynapses());
    getKSession().getEntryPoint("in_PetalLen").insert(2.2);
    getKSession().getEntryPoint("in_PetalWid").insert(4.1);
    getKSession().getEntryPoint("in_SepalLen").insert(2.3);
    getKSession().getEntryPoint("in_SepalWid").insert(1.8);
    getKSession().fireAllRules();
    // System.err.println(reportWMObjects(getKSession()));
    FactType t7 = getKbase().getFactType(packageName, "Test_MLP_7");
    FactType t8 = getKbase().getFactType(packageName, "Test_MLP_8");
    FactType t9 = getKbase().getFactType(packageName, "Test_MLP_9");
    FactType s1 = getKbase().getFactType(packageName, "Cspecies_virginica");
    Assert.assertEquals(0.001, truncN(getDoubleFieldValue(t7), 3), 1e-4);
    Assert.assertEquals(0.282, truncN(getDoubleFieldValue(t8), 3), 1e-4);
    Assert.assertEquals(0.716, truncN(getDoubleFieldValue(t9), 3), 1e-4);
    // Assert.assertEquals("virginica",
    // getFieldValue("Cspecies_virginica", "Test_MLP"));
    // Assert.assertEquals("Test_setosa",
    // getFieldValue("Cspecies_setosa", "Test_MLP"));
    // Assert.assertEquals("Test_versicolor",
    // getFieldValue("Cspecies_versicolor", "Test_MLP"));
    checkFirstDataFieldOfTypeStatus(getKbase().getFactType(packageName, "SpecSetosa"), true, false, "Test_MLP", 0.001111);
    checkFirstDataFieldOfTypeStatus(getKbase().getFactType(packageName, "SpecVirgin"), true, false, "Test_MLP", 0.716639);
    checkFirstDataFieldOfTypeStatus(getKbase().getFactType(packageName, "SpecVersic"), true, false, "Test_MLP", 0.282249);
    checkFirstDataFieldOfTypeStatus(getKbase().getFactType(packageName, "SpecOut"), true, false, "Test_MLP", "virginica");
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 82 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class NeuralNetworkTest method testOverride.

@Test
public void testOverride() throws Exception {
    setKSession(getModelSession(source3, VERBOSE));
    setKbase(getKSession().getKieBase());
    getKSession().fireAllRules();
    getKSession().getEntryPoint("in_Feat1").insert(2.2);
    getKSession().fireAllRules();
    getKSession().getEntryPoint("in_Feat2").insert(5);
    getKSession().fireAllRules();
    // System.err.println(reportWMObjects(getKSession()));
    FactType out1 = getKbase().getFactType("org.kie.pmml.pmml_4_2.test", "Out1");
    FactType out2 = getKbase().getFactType("org.kie.pmml.pmml_4_2.test", "Out2");
    FactType nump = getKbase().getFactType("org.kie.pmml.pmml_4_2.test", "Feat2");
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(out1.getFactClass())).size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(out2.getFactClass())).size());
    assertEquals(2, getKSession().getObjects(new ClassObjectFilter(nump.getFactClass())).size());
    getKSession().getEntryPoint("in_Feat1").insert(2.5);
    getKSession().getEntryPoint("in_Feat2").insert(6);
    getKSession().fireAllRules();
    // System.err.println(reportWMObjects(getKSession()));
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(out1.getFactClass())).size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(out2.getFactClass())).size());
    assertEquals(2, getKSession().getObjects(new ClassObjectFilter(nump.getFactClass())).size());
    checkGeneratedRules();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 83 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class UserDefinedFunctionsTest method testFunctions0Overwrite.

@Test
public void testFunctions0Overwrite() throws Exception {
    setKSession(getModelSession(source0, VERBOSE));
    setKbase(getKSession().getKieBase());
    FactType userAge1 = getKbase().getFactType(packageName, "UserAge");
    getKSession().getEntryPoint("in_Age").insert(8.4);
    getKSession().fireAllRules();
    getKSession().getEntryPoint("in_Age").insert(2.2);
    getKSession().fireAllRules();
    System.out.println(reportWMObjects(getKSession()));
    checkFirstDataFieldOfTypeStatus(userAge1, true, false, null, 22.0);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 84 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class UserDefinedFunctionsTest method testFunctions3.

@Test
public void testFunctions3() throws Exception {
    setKSession(getModelSession(source3, VERBOSE));
    setKbase(getKSession().getKieBase());
    FactType userAge3 = getKbase().getFactType(packageName, "UserAge3");
    getKSession().getEntryPoint("in_Age").insert(10);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(userAge3, true, false, null, 10);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 85 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class UserDefinedFunctionsTest method testFunctions1.

@Test
public void testFunctions1() throws Exception {
    setKSession(getModelSession(source3, true));
    setKbase(getKSession().getKieBase());
    FactType userAge1 = getKbase().getFactType(packageName, "UserAge1");
    getKSession().getEntryPoint("in_Age").insert(10);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(userAge1, true, false, null, 22.0);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Aggregations

FactType (org.kie.api.definition.type.FactType)208 Test (org.junit.Test)193 KieSession (org.kie.api.runtime.KieSession)114 KieBase (org.kie.api.KieBase)63 DroolsAbstractPMMLTest (org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest)45 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)31 ArrayList (java.util.ArrayList)28 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)27 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)27 KieServices (org.kie.api.KieServices)22 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)18 Resource (org.kie.api.io.Resource)17 KieBuilder (org.kie.api.builder.KieBuilder)16 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)16 KieFileSystem (org.kie.api.builder.KieFileSystem)15 KieContainer (org.kie.api.runtime.KieContainer)15 List (java.util.List)10 Results (org.kie.api.builder.Results)10 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)9 LogicalTypeInconsistencyException (org.drools.core.factmodel.traits.LogicalTypeInconsistencyException)9