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