use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.
the class TraitTest method testTMSConsistencyWithNonTraitableBeans.
@Test(timeout = 10000)
public void testTMSConsistencyWithNonTraitableBeans() {
String s1 = "package org.drools.test;\n" + "import org.drools.compiler.Person; \n" + "import org.drools.core.factmodel.traits.Traitable; \n" + "" + "declare Person @Traitable end \n" + "" + "rule \"Init\"\n" + "when\n" + "then\n" + " insertLogical( new Person( \"x\", 18 ) );\n" + "end\n" + "\n" + "declare trait Student\n" + " age : int\n" + " name : String\n" + "end\n" + "\n" + "rule \"Trait\"\n" + "when\n" + " $p : Person( )\n" + "then\n" + " don( $p, Student.class, true );\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ByteArrayResource(s1.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = kbase.newKieSession();
TraitFactory.setMode(mode, ksession.getKieBase());
ksession.fireAllRules();
FactHandle personHandle = ksession.getFactHandles(new ClassObjectFilter(Person.class)).iterator().next();
InternalFactHandle h = ((InternalFactHandle) personHandle);
ObjectTypeConfigurationRegistry reg = h.getEntryPoint().getObjectTypeConfigurationRegistry();
ObjectTypeConf conf = reg.getObjectTypeConf(h.getEntryPoint().getEntryPoint(), ((InternalFactHandle) personHandle).getObject());
assertTrue(conf.isTMSEnabled());
ksession.dispose();
}
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");
}
use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.
the class ConstrainedDataDictionaryTest method testProperties.
@Test
public void testProperties() throws Exception {
getKSession().getEntryPoint("in_Vallued").insert(1);
getKSession().getEntryPoint("in_Intervalled").insert(8.3);
getKSession().getEntryPoint("in_Cat").insert("aa");
getKSession().getEntryPoint("in_Sort").insert(1);
getKSession().fireAllRules();
Collection<EventFactHandle> fact1 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Vallued").getFactClass()));
assertEquals(1, fact1.size());
// assertEquals(true, getKbase().getFactType(packageName, "Vallued").get(fact1.iterator().next().getObject(), "continuous"));
Collection<EventFactHandle> fact2 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Intervalled").getFactClass()));
assertEquals(1, fact2.size());
// assertEquals(true, getKbase().getFactType(packageName,"Intervalled").get(fact2.iterator().next().getObject(),"continuous"));
Collection<EventFactHandle> fact3 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Cat").getFactClass()));
assertEquals(1, fact3.size());
// assertEquals(true, getKbase().getFactType(packageName,"Cat").get(fact3.iterator().next().getObject(),"categorical"));
Collection<EventFactHandle> fact4 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Sort").getFactClass()));
assertEquals(1, fact4.size());
// assertEquals(true, getKbase().getFactType(packageName,"Sort").get(fact4.iterator().next().getObject(),"ordinal"));
checkGeneratedRules();
}
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();
}
use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.
the class DecisionTreeTest method getToken.
protected Object getToken(KieSession kSession) {
FactType tok = kSession.getKieBase().getFactType(PMML4Helper.pmmlDefaultPackageName(), "TreeToken");
assertNotNull(tok);
Collection c = kSession.getObjects(new ClassObjectFilter(tok.getFactClass()));
assertEquals(1, c.size());
return c.iterator().next();
}
Aggregations