use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.
the class DroolsAbstractPMMLTest method getFieldValue.
public Object getFieldValue(FactType type) {
Class<?> klass = type.getFactClass();
Iterator iter = getKSession().getObjects(new ClassObjectFilter(klass)).iterator();
Object obj = iter.next();
return type.get(obj, "value");
}
use of org.kie.api.runtime.ClassObjectFilter 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.runtime.ClassObjectFilter 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.runtime.ClassObjectFilter in project drools by kiegroup.
the class MultipleModelTest method testIncrementalBuilding.
@Test
public void testIncrementalBuilding() throws Exception {
ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId("org.test", "test", "1.0.0-SNAPSHOT");
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieBuilder kb = ks.newKieBuilder(kfs);
kfs.generateAndWritePomXML(releaseId1);
kfs.write(ResourceFactory.newClassPathResource(source1).setResourceType(ResourceType.PMML));
kb.buildAll();
KieContainer kc = ks.newKieContainer(releaseId1);
KieSession kSession = kc.newKieSession();
setKbase(kSession.getKieBase());
kSession.fireAllRules();
kfs.write(ResourceFactory.newClassPathResource(source2).setResourceType(ResourceType.PMML));
IncrementalResults results = ((InternalKieBuilder) kb).incrementalBuild();
kc.updateToVersion(releaseId1);
kSession.fireAllRules();
assertEquals(2, kSession.getObjects(new ClassObjectFilter(ModelMarker.class)).size());
assertEquals(11, kSession.getObjects(new ClassObjectFilter(kSession.getKieBase().getFactType(packageName, "Synapse").getFactClass())).size());
kSession.dispose();
checkGeneratedRules();
}
use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.
the class MultipleModelTest method testCompositeBuilding.
@Test
public void testCompositeBuilding() throws Exception {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newClassPathResource(source1).setResourceType(ResourceType.PMML));
kfs.write(ResourceFactory.newClassPathResource(source2).setResourceType(ResourceType.PMML));
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
KieSession kSession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
setKbase(kSession.getKieBase());
kSession.fireAllRules();
assertEquals(2, kSession.getObjects(new ClassObjectFilter(ModelMarker.class)).size());
assertEquals(11, kSession.getObjects(new ClassObjectFilter(kSession.getKieBase().getFactType(packageName, "Synapse").getFactClass())).size());
kSession.dispose();
checkGeneratedRules();
}
Aggregations