Search in sources :

Example 21 with ClassObjectFilter

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");
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) Iterator(java.util.Iterator)

Example 22 with ClassObjectFilter

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();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) EntryPoint(org.kie.api.runtime.rule.EntryPoint) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 23 with ClassObjectFilter

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();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) Collection(java.util.Collection) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 24 with ClassObjectFilter

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();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) ModelMarker(org.kie.pmml.pmml_4_2.ModelMarker) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 25 with ClassObjectFilter

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();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) ModelMarker(org.kie.pmml.pmml_4_2.ModelMarker) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Aggregations

ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)51 Test (org.junit.Test)44 KieSession (org.kie.api.runtime.KieSession)24 FactType (org.kie.api.definition.type.FactType)16 Verifier (org.drools.verifier.Verifier)12 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)12 Subsumption (org.drools.verifier.report.components.Subsumption)11 FactHandle (org.kie.api.runtime.rule.FactHandle)11 KieBase (org.kie.api.KieBase)10 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 DroolsAbstractPMMLTest (org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest)9 KieServices (org.kie.api.KieServices)9 Iterator (java.util.Iterator)7 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)7 Map (java.util.Map)5 KieBuilder (org.kie.api.builder.KieBuilder)5 KieFileSystem (org.kie.api.builder.KieFileSystem)5 KieContainer (org.kie.api.runtime.KieContainer)5 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)5