Search in sources :

Example 11 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.drools.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) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 12 with ClassObjectFilter

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

the class NeuralNetworkTest method testOverride.

@Test
public void testOverride() throws Exception {
    setKSession(getModelSession(source3, VERBOSE));
    setKbase(getKSession().getKieBase());
    getKSession().fireAllRules();
    getKSession().getEntryPoint("in_Feat1").insert(2.2);
    getKSession().fireAllRules();
    getKSession().getEntryPoint("in_Feat2").insert(5);
    getKSession().fireAllRules();
    // System.err.println(reportWMObjects(getKSession()));
    FactType out1 = getKbase().getFactType("org.drools.pmml.pmml_4_2.test", "Out1");
    FactType out2 = getKbase().getFactType("org.drools.pmml.pmml_4_2.test", "Out2");
    FactType nump = getKbase().getFactType("org.drools.pmml.pmml_4_2.test", "Feat2");
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(out1.getFactClass())).size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(out2.getFactClass())).size());
    assertEquals(2, getKSession().getObjects(new ClassObjectFilter(nump.getFactClass())).size());
    getKSession().getEntryPoint("in_Feat1").insert(2.5);
    getKSession().getEntryPoint("in_Feat2").insert(6);
    getKSession().fireAllRules();
    // System.err.println(reportWMObjects(getKSession()));
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(out1.getFactClass())).size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(out2.getFactClass())).size());
    assertEquals(2, getKSession().getObjects(new ClassObjectFilter(nump.getFactClass())).size());
    checkGeneratedRules();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 13 with ClassObjectFilter

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

the class ScorecardTest method testScorecard.

@Test
public void testScorecard() throws Exception {
    setKSession(getModelSession(source1, VERBOSE));
    setKbase(getKSession().getKieBase());
    KieSession kSession = getKSession();
    // init model
    kSession.fireAllRules();
    kSession.getEntryPoint("in_Age").insert(33.0);
    kSession.getEntryPoint("in_Occupation").insert("SKYDIVER");
    kSession.getEntryPoint("in_ResidenceState").insert("KN");
    kSession.getEntryPoint("in_ValidLicense").insert(true);
    // init model
    kSession.fireAllRules();
    FactType scoreCardType = getKbase().getFactType(PMML4Helper.pmmlDefaultPackageName(), "ScoreCard");
    assertNotNull(scoreCardType);
    assertEquals(1, kSession.getObjects(new ClassObjectFilter(scoreCardType.getFactClass())).size());
    Object scoreCard = kSession.getObjects(new ClassObjectFilter(scoreCardType.getFactClass())).iterator().next();
    System.out.print(reportWMObjects(kSession));
    assertEquals("SampleScore", scoreCardType.get(scoreCard, "modelName"));
    assertEquals(41.345, scoreCardType.get(scoreCard, "score"));
    Object x = scoreCardType.get(scoreCard, "ranking");
    assertTrue(x instanceof LinkedHashMap);
    LinkedHashMap map = (LinkedHashMap) x;
    assertTrue(map.containsKey("LX00"));
    assertTrue(map.containsKey("RES"));
    assertTrue(map.containsKey("CX2"));
    assertEquals(-1.0, map.get("LX00"));
    assertEquals(-10.0, map.get("RES"));
    assertEquals(-30.0, map.get("CX2"));
    Iterator iter = map.keySet().iterator();
    assertEquals("LX00", iter.next());
    assertEquals("RES", iter.next());
    assertEquals("CX2", iter.next());
    checkGeneratedRules();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) Iterator(java.util.Iterator) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) LinkedHashMap(java.util.LinkedHashMap) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 14 with ClassObjectFilter

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

the class SubsumptantRestrictionsTest method testVerifierLiteralRestrictionRedundancy3.

@Test
public void testVerifierLiteralRestrictionRedundancy3() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantRestriction3.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(6, 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 15 with ClassObjectFilter

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

the class SubsumptantSubPatternsTest method testSubpatternSubsumption4.

/**
 * Patterns that use from
 *
 * @throws Exception
 */
@Test
@Ignore
public void testSubpatternSubsumption4() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantSubPatterns4.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) Ignore(org.junit.Ignore) 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