Search in sources :

Example 61 with FactType

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

the class DiscretizeFieldsTest method testDiscretize.

@Test
public void testDiscretize() throws Exception {
    FactType age = getKbase().getFactType(packageName, "Age");
    FactType cat = getKbase().getFactType(packageName, "AgeCategories");
    assertNotNull(getKSession().getEntryPoint("in_Age"));
    getKSession().getEntryPoint("in_Age").insert(-1);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, true, null, -1);
    checkFirstDataFieldOfTypeStatus(cat, true, false, null, "infant");
    this.refreshKSession();
    getKSession().getEntryPoint("in_Age").insert(1);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, 1);
    checkFirstDataFieldOfTypeStatus(cat, true, false, null, "infant");
    this.refreshKSession();
    getKSession().getEntryPoint("in_Age").insert(9);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, 9);
    checkFirstDataFieldOfTypeStatus(cat, true, false, null, "young");
    this.refreshKSession();
    getKSession().getEntryPoint("in_Age").insert(30);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, 30);
    checkFirstDataFieldOfTypeStatus(cat, true, false, null, "mature");
    this.refreshKSession();
    getKSession().getEntryPoint("in_Age").insert(90);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, 90);
    checkFirstDataFieldOfTypeStatus(cat, true, false, null, "ancient");
    this.refreshKSession();
    getKSession().getEntryPoint("in_Age").insert(3000);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, 3000);
    checkFirstDataFieldOfTypeStatus(cat, true, false, null, "ancient");
    this.refreshKSession();
    getKSession().getEntryPoint("in_Age").insert(19);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, 19);
    checkFirstDataFieldOfTypeStatus(cat, true, false, null, "ancient");
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 62 with FactType

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

the class LinearNormalizedFieldsTest method testDerivedTypesLinearNormInterpolation.

@Test
public void testDerivedTypesLinearNormInterpolation() throws Exception {
    // new PMML4Wrapper().getPmml().getTransformationDictionary().getDerivedField().get(0).getNormContinuous().getOutliers().value()
    FactType age = getKbase().getFactType(packageName, "Age");
    FactType age1 = getKbase().getFactType(packageName, "Age_norm");
    getKSession().getEntryPoint("in_Age").insert(30);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, 30);
    checkFirstDataFieldOfTypeStatus(age1, true, false, null, 0.375);
    refreshKSession();
    getKSession().getEntryPoint("in_Age").insert(90);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, 90);
    checkFirstDataFieldOfTypeStatus(age1, true, false, null, 1.5);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 63 with FactType

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

the class LinearNormalizedFieldsTest method testDerivedTypesLinearNormMapMissing.

@Test
public void testDerivedTypesLinearNormMapMissing() throws Exception {
    // new PMML4Wrapper().getPmml().getTransformationDictionary().getDerivedField().get(0).getNormContinuous().getOutliers().value()
    FactType age = getKbase().getFactType(packageName, "Age");
    FactType age1 = getKbase().getFactType(packageName, "Age_norm");
    FactType age2 = getKbase().getFactType(packageName, "Age_norm2");
    FactType age3 = getKbase().getFactType(packageName, "Age_norm3");
    assertNotNull(getKSession().getEntryPoint("in_Age"));
    assertNull(getKSession().getEntryPoint("in_Age_mis"));
    assertNull(getKSession().getEntryPoint("in_Age_norm"));
    // value is "missing" for age, so should be mapped by the mapMissingTo policy
    getKSession().getEntryPoint("in_Age").insert(-1);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, true, null, -1);
    checkFirstDataFieldOfTypeStatus(age1, true, false, null, 0.0);
    checkFirstDataFieldOfTypeStatus(age2, true, false, null, -931.0);
    checkFirstDataFieldOfTypeStatus(age3, true, false, null, 789.0);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 64 with FactType

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

the class NormDiscreteFieldsTest method testNormDiscrete.

@Test
public void testNormDiscrete() throws Exception {
    FactType fld = getKbase().getFactType(packageName, "CatField");
    FactType val1 = getKbase().getFactType(packageName, "IsValue1");
    FactType val2 = getKbase().getFactType(packageName, "IsValue2");
    assertNotNull(getKSession().getEntryPoint("in_CatField"));
    // value is "missing" for age, so should be mapped by the mapMissingTo policy
    getKSession().getEntryPoint("in_CatField").insert("Value1");
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(fld, true, false, null, "Value1");
    checkFirstDataFieldOfTypeStatus(val1, true, false, null, 1.0);
    checkFirstDataFieldOfTypeStatus(val2, true, false, null, 0.0);
    refreshKSession();
    getKSession().getEntryPoint("in_CatField").insert("Value2");
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(fld, true, false, null, "Value2");
    checkFirstDataFieldOfTypeStatus(val1, true, false, null, 0.0);
    checkFirstDataFieldOfTypeStatus(val2, true, false, null, 1.0);
    refreshKSession();
    getKSession().getEntryPoint("in_CatField").insert("Value3");
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(fld, true, false, null, "Value3");
    checkFirstDataFieldOfTypeStatus(val1, true, false, null, 0.0);
    checkFirstDataFieldOfTypeStatus(val2, true, false, null, 0.0);
    refreshKSession();
    getKSession().getEntryPoint("in_CatField").insert("Value0");
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(fld, false, true, null, "Value0");
    checkFirstDataFieldOfTypeStatus(val1, true, false, null, 2.0);
    checkFirstDataFieldOfTypeStatus(val2, true, false, null, 2.0);
    refreshKSession();
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 65 with FactType

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

the class UserDefinedFunctionsTest method testFunctionsNested.

@Test
public void testFunctionsNested() throws Exception {
    setKSession(getModelSession(source1, VERBOSE));
    setKbase(getKSession().getKieBase());
    FactType userAge1 = getKbase().getFactType(packageName, "UserAge");
    getKSession().getEntryPoint("in_Age").insert(10.0);
    getKSession().fireAllRules();
    System.out.println(reportWMObjects(getKSession()));
    checkFirstDataFieldOfTypeStatus(userAge1, true, false, null, 130.0);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.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