Search in sources :

Example 36 with ClassObjectFilter

use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.

the class SubsumptantRestrictionsTest method testVerifierLiteralRestrictionRedundancy1.

@Test
public void testVerifierLiteralRestrictionRedundancy1() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantRestriction1.drl", getClass()), ResourceType.DRL);
    // for ( VerifierError error : verifier.getMissingClasses() ) {
    // System.out.println( error.getMessage() );
    // }
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    Collection<? extends Object> subsumptionList = ((VerifierImpl) verifier).getKnowledgeSession().getObjects(new ClassObjectFilter(Subsumption.class));
    assertEquals(9, subsumptionList.size());
    verifier.dispose();
}
Also used : Subsumption(org.drools.verifier.report.components.Subsumption) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Example 37 with ClassObjectFilter

use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.

the class SubsumptantSubPatternsTest method testSubpatternSubsumption3.

/**
 * Different sources
 *
 * @throws Exception
 */
@Test
public void testSubpatternSubsumption3() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantSubPatterns3.drl", getClass()), ResourceType.DRL);
    // for ( VerifierError error : verifier.getMissingClasses() ) {
    // System.out.println( error.getMessage() );
    // }
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    Collection<? extends Object> subsumptionList = ((VerifierImpl) verifier).getKnowledgeSession().getObjects(new ClassObjectFilter(Subsumption.class));
    int count = 0;
    for (Object object : subsumptionList) {
        // System.out.println( " * " + ((Subsumption) object) );
        if (((VerifierComponent) ((Subsumption) object).getLeft()).getVerifierComponentType().equals(VerifierComponentType.SUB_PATTERN)) {
            count++;
        }
    }
    assertEquals(1, count);
    verifier.dispose();
}
Also used : Subsumption(org.drools.verifier.report.components.Subsumption) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Example 38 with ClassObjectFilter

use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.

the class DecisionTreeTest method testMissingTreeNull.

@Test
public void testMissingTreeNull() 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.NULL_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.0, (Double) tok.get(token, "confidence"), 1e-6);
    assertEquals("null", tok.get(token, "current"));
    assertEquals(0.0, tok.get(token, "totalCount"));
    assertEquals(0, getKSession().getObjects(new ClassObjectFilter(tgt.getFactClass())).size());
    checkGeneratedRules();
}
Also used : TreeModel(org.dmg.pmml.pmml_4_2.descr.TreeModel) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) PMML(org.dmg.pmml.pmml_4_2.descr.PMML) KieSession(org.kie.api.runtime.KieSession) PMML4Compiler(org.drools.pmml.pmml_4_2.PMML4Compiler) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 39 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(1, kSession.getObjects(new ClassObjectFilter(ModelMarker.class)).size());
    assertEquals(9, 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.drools.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) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 40 with ClassObjectFilter

use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.

the class UserDefinedFunctionsTest method testComplexFunctionsNested2.

@Test
public void testComplexFunctionsNested2() throws Exception {
    setKSession(getModelSession(source2, VERBOSE));
    setKbase(getKSession().getKieBase());
    FactType userAge1 = getKbase().getFactType(packageName, "UserAge");
    FactType userAge2 = getKbase().getFactType(packageName, "UserAgeComplex");
    FactHandle h = getKSession().getEntryPoint("in_Age").insert(10.0);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(userAge1, true, false, null, 6270.0);
    checkFirstDataFieldOfTypeStatus(userAge2, true, false, null, 44.1);
    System.out.println("_________________________________________________________________");
    FactType age = getKbase().getFactType(packageName, "Age");
    Object aged = getKSession().getObjects(new ClassObjectFilter(age.getFactClass())).iterator().next();
    getKSession().delete(getKSession().getFactHandle(aged));
    getKSession().fireAllRules();
    assertEquals(0, getKSession().getFactCount());
    getKSession().getEntryPoint("in_Age").insert(20.0);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(userAge1, true, false, null, 9570.0);
    checkFirstDataFieldOfTypeStatus(userAge2, true, false, null, 115.2);
    getKSession().getEntryPoint("in_Age").insert(30.0);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(userAge1, true, false, null, 12870.0);
    checkFirstDataFieldOfTypeStatus(userAge2, true, false, null, 306.3);
    assertEquals(4, getKSession().getFactCount());
    checkGeneratedRules();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) FactHandle(org.kie.api.runtime.rule.FactHandle) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

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