use of org.kie.api.definition.type.FactType in project drools by kiegroup.
the class ConstrainedDataDictionaryTest method testContinuousDomainIntervals.
@Test
public void testContinuousDomainIntervals() throws Exception {
FactType ivals = getKbase().getFactType(packageName, "Intervalled");
assertNotNull(ivals);
Object data1 = ivals.newInstance();
ivals.set(data1, "value", -0.4);
Object data2 = ivals.newInstance();
ivals.set(data2, "value", 0.3);
Object data3 = ivals.newInstance();
ivals.set(data3, "value", 1.6);
Object data4 = ivals.newInstance();
ivals.set(data4, "value", 2.0);
Object data5 = ivals.newInstance();
ivals.set(data5, "value", 3.0);
Object data6 = ivals.newInstance();
ivals.set(data6, "value", 8.2);
Object data7 = ivals.newInstance();
ivals.set(data7, "value", 12.4);
Object data8 = ivals.newInstance();
ivals.set(data8, "value", 999.9);
getKSession().insert(data1);
getKSession().insert(data2);
getKSession().insert(data3);
getKSession().insert(data4);
getKSession().insert(data5);
getKSession().insert(data6);
getKSession().insert(data7);
getKSession().insert(data8);
getKSession().fireAllRules();
assertEquals(false, ivals.get(data1, "valid"));
assertEquals(true, ivals.get(data2, "valid"));
assertEquals(false, ivals.get(data3, "valid"));
assertEquals(true, ivals.get(data4, "valid"));
assertEquals(false, ivals.get(data5, "valid"));
assertEquals(false, ivals.get(data6, "valid"));
assertEquals(true, ivals.get(data7, "valid"));
assertEquals(false, ivals.get(data8, "valid"));
checkGeneratedRules();
}
use of org.kie.api.definition.type.FactType in project drools by kiegroup.
the class ConstrainedDataDictionaryTest method testContinuousDomainValues.
@Test
public void testContinuousDomainValues() throws Exception {
FactType vals = getKbase().getFactType(packageName, "Vallued");
assertNotNull(vals);
// FactType defval = getKbase().getFactType(packageName,"DefaultValid");
// assertNotNull(vals);
// FactType definv = getKbase().getFactType(packageName,"DefaultInvalid");
// assertNotNull(vals);
Object data1 = vals.newInstance();
vals.set(data1, "value", 1);
Object data2 = vals.newInstance();
vals.set(data2, "value", 2);
Object data3 = vals.newInstance();
vals.set(data3, "value", 3);
Object data0 = vals.newInstance();
vals.set(data0, "value", 0);
Object data99 = vals.newInstance();
vals.set(data99, "value", -1);
getKSession().insert(data1);
getKSession().insert(data2);
getKSession().insert(data3);
getKSession().insert(data0);
getKSession().insert(data99);
getKSession().fireAllRules();
assertEquals(true, vals.get(data1, "valid"));
assertEquals(false, vals.get(data1, "missing"));
assertEquals(true, vals.get(data2, "valid"));
assertEquals(false, vals.get(data2, "missing"));
assertEquals(false, vals.get(data3, "valid"));
assertEquals(false, vals.get(data3, "missing"));
assertEquals(false, vals.get(data0, "valid"));
assertEquals(true, vals.get(data0, "missing"));
assertEquals(false, vals.get(data99, "valid"));
assertEquals(false, vals.get(data99, "missing"));
checkGeneratedRules();
}
use of org.kie.api.definition.type.FactType in project drools by kiegroup.
the class DataDictionaryTest method testEntryPoints.
@Test
public void testEntryPoints() 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");
assertEquals(7, getKSession().getEntryPoints().size());
EntryPoint gender_ep = getKSession().getEntryPoint("in_Gender");
Assert.assertNotNull(gender_ep);
EntryPoint noclaims_ep = getKSession().getEntryPoint("in_NoOfClaims");
Assert.assertNotNull(noclaims_ep);
EntryPoint scrambled_ep = getKSession().getEntryPoint("in_Scrambled");
Assert.assertNotNull(scrambled_ep);
EntryPoint domicile_ep = getKSession().getEntryPoint("in_Domicile");
Assert.assertNotNull(domicile_ep);
EntryPoint agecar_ep = getKSession().getEntryPoint("in_AgeOfCar");
Assert.assertNotNull(agecar_ep);
EntryPoint amklaims_ep = getKSession().getEntryPoint("in_AmountOfClaims");
Assert.assertNotNull(amklaims_ep);
gender_ep.insert("M");
noclaims_ep.insert("> 4");
scrambled_ep.insert(4);
domicile_ep.insert("way out");
agecar_ep.insert(new Double("3.4"));
amklaims_ep.insert(9);
getKSession().fireAllRules();
assertEquals(6, getKSession().getObjects().size());
assertEquals(1, getKSession().getObjects(new ClassObjectFilter(gender.getFactClass())).size());
assertEquals(1, getKSession().getObjects(new ClassObjectFilter(noclaims.getFactClass())).size());
assertEquals(1, getKSession().getObjects(new ClassObjectFilter(scrambled.getFactClass())).size());
assertEquals(1, getKSession().getObjects(new ClassObjectFilter(domicile.getFactClass())).size());
assertEquals(1, getKSession().getObjects(new ClassObjectFilter(agecar.getFactClass())).size());
assertEquals(1, getKSession().getObjects(new ClassObjectFilter(amklaims.getFactClass())).size());
checkFirstDataFieldOfTypeStatus(amklaims, true, false, null, 9);
checkFirstDataFieldOfTypeStatus(domicile, false, false, null, "way out");
checkGeneratedRules();
}
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.kie.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.kie.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.kie.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.kie.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.kie.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.kie.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();
}
Aggregations