use of org.kie.api.definition.type.FactType in project drools by kiegroup.
the class DataDictionaryTest method testDataTypes.
@Test
public void testDataTypes() throws Exception {
setKSession(getModelSession(source, VERBOSE));
setKbase(getKSession().getKieBase());
FactType gender = getKbase().getFactType(packageName, "Gender");
FactType noclaims = getKbase().getFactType(packageName, "NoOfClaims");
FactType scrambled = getKbase().getFactType(packageName, "Scrambled");
FactType domicile = getKbase().getFactType(packageName, "Domicile");
FactType agecar = getKbase().getFactType(packageName, "AgeOfCar");
FactType amklaims = getKbase().getFactType(packageName, "AmountOfClaims");
Object g = gender.newInstance();
assertEquals("org.drools.pmml.pmml_4_2.test.Gender", g.getClass().getName());
gender.set(g, "value", "M");
assertEquals("M", gender.get(g, "value"));
Object n = noclaims.newInstance();
assertEquals("org.drools.pmml.pmml_4_2.test.NoOfClaims", n.getClass().getName());
noclaims.set(n, "value", "> 3");
assertEquals("> 3", noclaims.get(n, "value"));
Object s = scrambled.newInstance();
assertEquals("org.drools.pmml.pmml_4_2.test.Scrambled", s.getClass().getName());
scrambled.set(s, "value", 1);
assertEquals(1, scrambled.get(s, "value"));
Object d = domicile.newInstance();
assertEquals("org.drools.pmml.pmml_4_2.test.Domicile", d.getClass().getName());
domicile.set(d, "value", "SomeWhere");
assertEquals("SomeWhere", domicile.get(d, "value"));
Object a = agecar.newInstance();
assertEquals("org.drools.pmml.pmml_4_2.test.AgeOfCar", a.getClass().getName());
agecar.set(a, "value", 24.3);
assertEquals(24.3, agecar.get(a, "value"));
Object k = amklaims.newInstance();
assertEquals("org.drools.pmml.pmml_4_2.test.AmountOfClaims", k.getClass().getName());
amklaims.set(k, "value", 9);
assertEquals(9, amklaims.get(k, "value"));
try {
agecar.set(a, "value", "Not a String field");
Assert.fail();
} catch (ClassCastException cce) {
assertEquals(24.3, agecar.get(a, "value"));
}
Assert.assertFalse((Boolean) agecar.get(a, "valid"));
agecar.set(a, "valid", true);
Assert.assertTrue((Boolean) agecar.get(a, "valid"));
Assert.assertFalse((Boolean) agecar.get(a, "missing"));
agecar.set(a, "missing", true);
Assert.assertTrue((Boolean) agecar.get(a, "missing"));
// assertFalse((Boolean) agecar.get(a, "cyclic"));
// agecar.set(a,"cyclic",true);
// assertTrue((Boolean) agecar.get(a,"cyclic"));
checkGeneratedRules();
}
use of org.kie.api.definition.type.FactType in project drools by kiegroup.
the class ClusteringTest method testCenterBasedClustering.
@Test
public void testCenterBasedClustering() throws Exception {
setKSession(getModelSession(source1, VERBOSE));
setKbase(getKSession().getKieBase());
KieSession kSession = getKSession();
// init model
kSession.fireAllRules();
kSession.getEntryPoint("in_Fld0").insert("y");
kSession.getEntryPoint("in_Fld1").insert(2.0);
kSession.getEntryPoint("in_Fld2").insert(-1.0);
kSession.fireAllRules();
FactType mu = kSession.getKieBase().getFactType(packageName, "DistanceMembership");
Collection mus = kSession.getObjects(new ClassObjectFilter(mu.getFactClass()));
assertTrue(mus.size() > 0);
for (Object x : mus) {
Integer ix = (Integer) mu.get(x, "index");
String lab = (String) mu.get(x, "label");
Double m = (Double) mu.get(x, "mu");
if (ix == 0) {
assertEquals("Klust1", lab);
assertEquals(41.1, m, 0.001);
} else if (ix == 1) {
assertEquals("Klust2", lab);
assertEquals(14704.428, m, 0.001);
}
}
checkGeneratedRules();
}
use of org.kie.api.definition.type.FactType in project drools by kiegroup.
the class DecisionTreeTest method testMissingTreeLastChoice.
@Test
public void testMissingTreeLastChoice() throws Exception {
PMML4Compiler compiler = new PMML4Compiler();
PMML pmml = compiler.loadModel(PMML, ResourceFactory.newClassPathResource(source2).getInputStream());
for (Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels()) {
if (o instanceof TreeModel) {
TreeModel tree = (TreeModel) o;
tree.setMissingValueStrategy(MISSINGVALUESTRATEGY.LAST_PREDICTION);
}
}
String theory = compiler.generateTheory(pmml);
if (VERBOSE) {
System.out.println(theory);
}
KieSession kSession = getSession(theory);
setKSession(kSession);
setKbase(getKSession().getKieBase());
// init model
kSession.fireAllRules();
FactType tgt = kSession.getKieBase().getFactType(packageName, "Fld9");
FactType tok = kSession.getKieBase().getFactType(PMML4Helper.pmmlDefaultPackageName(), "TreeToken");
kSession.getEntryPoint("in_Fld1").insert(-1.0);
kSession.getEntryPoint("in_Fld2").insert(-1.0);
kSession.getEntryPoint("in_Fld3").insert("optA");
kSession.fireAllRules();
Object token = getToken(kSession);
assertEquals(0.8, (Double) tok.get(token, "confidence"), 1e-6);
assertEquals("null", tok.get(token, "current"));
assertEquals(50.0, tok.get(token, "totalCount"));
checkFirstDataFieldOfTypeStatus(tgt, true, false, "Missing", "tgtX");
checkGeneratedRules();
}
use of org.kie.api.definition.type.FactType in project drools by kiegroup.
the class DecisionTreeTest method testSimpleTreeOutput.
@Test
public void testSimpleTreeOutput() throws Exception {
setKSession(getModelSession(source2, VERBOSE));
setKbase(getKSession().getKieBase());
KieSession kSession = getKSession();
// init model
kSession.fireAllRules();
FactType tgt = kSession.getKieBase().getFactType(packageName, "Fld9");
FactType tok = kSession.getKieBase().getFactType(PMML4Helper.pmmlDefaultPackageName(), "TreeToken");
kSession.getEntryPoint("in_Fld1").insert(-1.0);
kSession.getEntryPoint("in_Fld2").insert(-1.0);
kSession.getEntryPoint("in_Fld3").insert("optA");
kSession.fireAllRules();
Object token = getToken(kSession);
assertEquals(0.8, tok.get(token, "confidence"));
assertEquals("null", tok.get(token, "current"));
assertEquals(50.0, tok.get(token, "totalCount"));
checkFirstDataFieldOfTypeStatus(tgt, true, false, "Missing", "tgtX");
checkFirstDataFieldOfTypeStatus(kSession.getKieBase().getFactType(packageName, "OutClass"), true, false, "Missing", "tgtX");
checkFirstDataFieldOfTypeStatus(kSession.getKieBase().getFactType(packageName, "OutProb"), true, false, "Missing", 0.8);
checkGeneratedRules();
}
use of org.kie.api.definition.type.FactType in project drools by kiegroup.
the class DecisionTreeTest method testMissingTreeWeighted2.
@Test
public void testMissingTreeWeighted2() throws Exception {
setKSession(getModelSession(source2, VERBOSE));
setKbase(getKSession().getKieBase());
KieSession kSession = getKSession();
// init model
kSession.fireAllRules();
FactType tgt = kSession.getKieBase().getFactType(packageName, "Fld9");
FactType tok = kSession.getKieBase().getFactType(PMML4Helper.pmmlDefaultPackageName(), "TreeToken");
kSession.getEntryPoint("in_Fld1").insert(-1.0);
kSession.getEntryPoint("in_Fld2").insert(-1.0);
kSession.getEntryPoint("in_Fld3").insert("miss");
kSession.fireAllRules();
Object token = getToken(kSession);
assertEquals(0.6, tok.get(token, "confidence"));
assertEquals("null", tok.get(token, "current"));
assertEquals(100.0, tok.get(token, "totalCount"));
checkFirstDataFieldOfTypeStatus(tgt, true, false, "Missing", "tgtX");
checkGeneratedRules();
}
Aggregations