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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations