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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations