Search in sources :

Example 91 with FactType

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

the class LinearNormalizedFieldsTest method testDerivedTypesLinearNormOutliers.

@Test
public void testDerivedTypesLinearNormOutliers() 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");
    // value is an outlier
    getKSession().getEntryPoint("in_Age").insert(-100);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, -100);
    checkFirstDataFieldOfTypeStatus(age1, true, false, null, 0.0);
    checkFirstDataFieldOfTypeStatus(age2, true, true, null, 0.0);
    checkFirstDataFieldOfTypeStatus(age3, true, false, null, -1.25);
    refreshKSession();
    // value is an outlier
    getKSession().getEntryPoint("in_Age").insert(1000);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(age, true, false, null, 1000);
    checkFirstDataFieldOfTypeStatus(age1, true, false, null, 2.0);
    checkFirstDataFieldOfTypeStatus(age2, true, true, null, 0.0);
    checkFirstDataFieldOfTypeStatus(age3, true, false, null, 12.5);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 92 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.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 93 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.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 94 with FactType

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

the class AgendaFilterTest method newCancelFact.

private Object newCancelFact(KieSession ksession, boolean cancel) {
    FactType type = ksession.getKieBase().getFactType("org.jboss.qa.brms.agendafilter", "CancelFact");
    Object instance = null;
    try {
        instance = type.newInstance();
        type.set(instance, "cancel", cancel);
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    }
    return instance;
}
Also used : FactType(org.kie.api.definition.type.FactType)

Example 95 with FactType

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

the class IndexingTest method testRange2.

@Test(timeout = 10000)
public void testRange2() throws Exception {
    String rule = "package org.drools.compiler.test\n" + "declare A\n" + "    a: int\n" + "end\n" + "declare B\n" + "    b: int\n" + "end\n" + "declare C\n" + "    c: int\n" + "end\n" + "rule R1 when\n" + "   A( $a : a )\n" + "   B( $b : b )\n" + "   exists C( c > $a && < $b )\n" + "then\n" + "   System.out.println( $a + \", \" + $b );\n" + "end";
    KieBase kbase = loadKnowledgeBaseFromString(rule);
    KieSession ksession = kbase.newKieSession();
    FactType aType = kbase.getFactType("org.drools.compiler.test", "A");
    FactType bType = kbase.getFactType("org.drools.compiler.test", "B");
    FactType cType = kbase.getFactType("org.drools.compiler.test", "C");
    Object a1 = aType.newInstance();
    aType.set(a1, "a", 5);
    ksession.insert(a1);
    Object a2 = aType.newInstance();
    aType.set(a2, "a", 11);
    ksession.insert(a2);
    Object b1 = bType.newInstance();
    bType.set(b1, "b", 10);
    ksession.insert(b1);
    Object b2 = bType.newInstance();
    bType.set(b2, "b", 6);
    ksession.insert(b2);
    Object c = cType.newInstance();
    cType.set(c, "c", 7);
    ksession.insert(c);
    ksession.fireAllRules();
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) 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