Search in sources :

Example 6 with ClassObjectFilter

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();
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ByteArrayResource(org.drools.core.io.impl.ByteArrayResource) InternalFactHandle(org.drools.core.common.InternalFactHandle) Person(org.drools.compiler.Person) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) ObjectTypeConfigurationRegistry(org.drools.core.common.ObjectTypeConfigurationRegistry) Test(org.junit.Test)

Example 7 with ClassObjectFilter

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");
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) Iterator(java.util.Iterator)

Example 8 with ClassObjectFilter

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();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) EventFactHandle(org.drools.core.common.EventFactHandle) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 9 with ClassObjectFilter

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();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) Collection(java.util.Collection) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 10 with ClassObjectFilter

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();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) Collection(java.util.Collection) FactType(org.kie.api.definition.type.FactType)

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