Search in sources :

Example 56 with FactType

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

the class DecisionTreeTest method testSimpleTree.

@Test
public void testSimpleTree() throws Exception {
    setKSession(getModelSession(source1, VERBOSE));
    setKbase(getKSession().getKieBase());
    KieSession kSession = getKSession();
    // kSession.addEventListener( new org.drools.event.rule.DebugAgendaEventListener() );
    // init model
    kSession.fireAllRules();
    FactType tgt = kSession.getKieBase().getFactType(packageName, "Fld5");
    kSession.getEntryPoint("in_Fld1").insert(30.0);
    kSession.getEntryPoint("in_Fld2").insert(60.0);
    kSession.getEntryPoint("in_Fld3").insert("false");
    kSession.getEntryPoint("in_Fld4").insert("optA");
    kSession.fireAllRules();
    checkFirstDataFieldOfTypeStatus(tgt, true, false, "Missing", "tgtY");
    checkGeneratedRules();
}
Also used : KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 57 with FactType

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

the class DecisionTreeTest method getToken.

protected Object getToken(KieSession kSession) {
    FactType tok = kSession.getKieBase().getFactType(PMML4Helper.pmmlDefaultPackageName(), "TreeToken");
    assertNotNull(tok);
    Collection c = kSession.getObjects(new ClassObjectFilter(tok.getFactClass()));
    assertEquals(1, c.size());
    return c.iterator().next();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) Collection(java.util.Collection) FactType(org.kie.api.definition.type.FactType)

Example 58 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.drools.pmml.pmml_4_2.test", "Out1");
    FactType out2 = getKbase().getFactType("org.drools.pmml.pmml_4_2.test", "Out2");
    FactType nump = getKbase().getFactType("org.drools.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.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 59 with FactType

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

the class ScorecardTest method testScorecard.

@Test
public void testScorecard() throws Exception {
    setKSession(getModelSession(source1, VERBOSE));
    setKbase(getKSession().getKieBase());
    KieSession kSession = getKSession();
    // init model
    kSession.fireAllRules();
    kSession.getEntryPoint("in_Age").insert(33.0);
    kSession.getEntryPoint("in_Occupation").insert("SKYDIVER");
    kSession.getEntryPoint("in_ResidenceState").insert("KN");
    kSession.getEntryPoint("in_ValidLicense").insert(true);
    // init model
    kSession.fireAllRules();
    FactType scoreCardType = getKbase().getFactType(PMML4Helper.pmmlDefaultPackageName(), "ScoreCard");
    assertNotNull(scoreCardType);
    assertEquals(1, kSession.getObjects(new ClassObjectFilter(scoreCardType.getFactClass())).size());
    Object scoreCard = kSession.getObjects(new ClassObjectFilter(scoreCardType.getFactClass())).iterator().next();
    System.out.print(reportWMObjects(kSession));
    assertEquals("SampleScore", scoreCardType.get(scoreCard, "modelName"));
    assertEquals(41.345, scoreCardType.get(scoreCard, "score"));
    Object x = scoreCardType.get(scoreCard, "ranking");
    assertTrue(x instanceof LinkedHashMap);
    LinkedHashMap map = (LinkedHashMap) x;
    assertTrue(map.containsKey("LX00"));
    assertTrue(map.containsKey("RES"));
    assertTrue(map.containsKey("CX2"));
    assertEquals(-1.0, map.get("LX00"));
    assertEquals(-10.0, map.get("RES"));
    assertEquals(-30.0, map.get("CX2"));
    Iterator iter = map.keySet().iterator();
    assertEquals("LX00", iter.next());
    assertEquals("RES", iter.next());
    assertEquals("CX2", iter.next());
    checkGeneratedRules();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) Iterator(java.util.Iterator) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) LinkedHashMap(java.util.LinkedHashMap) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 60 with FactType

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

the class AliasedFieldsTest method testAlias.

@Test
public void testAlias() throws Exception {
    FactType alias = getKbase().getFactType(packageName, "AliasAge");
    FactType aliasmm = getKbase().getFactType(packageName, "AliasAgeMM");
    assertNotNull(alias);
    assertNotNull(aliasmm);
    getKSession().getEntryPoint("in_Age").insert(33);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(alias, true, false, null, 33);
    refreshKSession();
    getKSession().getEntryPoint("in_Age").insert(-1);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(alias, true, true, null, -1);
    checkFirstDataFieldOfTypeStatus(aliasmm, true, false, null, 99);
    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