Search in sources :

Example 6 with KnowledgeBaseImpl

use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.

the class SegmentPropagationTest method createContext.

public BuildContext createContext() {
    RuleBaseConfiguration conf = new RuleBaseConfiguration();
    KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", conf);
    BuildContext buildContext = new BuildContext(rbase);
    RuleImpl rule = new RuleImpl("rule1").setPackage("org.pkg1");
    InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.pkg1");
    pkg.getDialectRuntimeRegistry().setDialectData("mvel", new MVELDialectRuntimeData());
    pkg.addRule(rule);
    buildContext.setRule(rule);
    return buildContext;
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) BuildContext(org.drools.core.reteoo.builder.BuildContext) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 7 with KnowledgeBaseImpl

use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.

the class ReteooBuilderPerformanceTest method getReteBuilders.

private static ReteooBuilder[] getReteBuilders(int count) {
    System.out.println("Creating " + count + " ReteBuilder's");
    ReteooBuilder[] reteBuilders = new ReteooBuilder[count];
    RuleBaseConfiguration conf = new RuleBaseConfiguration();
    for (int i = 0; i < reteBuilders.length; i++) {
        reteBuilders[i] = new ReteooBuilder(new KnowledgeBaseImpl("id1", conf));
    }
    return reteBuilders;
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) ReteooBuilder(org.drools.core.reteoo.ReteooBuilder) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl)

Example 8 with KnowledgeBaseImpl

use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.

the class ApplyPmmlModelCommand method execute.

@Override
public PMML4Result execute(Context context) {
    PMML4Result resultHolder = new PMML4Result(requestData.getCorrelationId());
    RequestContextImpl ctx = (RequestContextImpl) context;
    KieBase kbase = ((RegistryContext) context).lookup(KieBase.class);
    if (kbase == null) {
        System.out.println("KieBase not found in context!");
        return null;
    } else {
        KieContainer kcont = ((KnowledgeBaseImpl) kbase).getKieContainer();
        kcont.getKieBaseNames().forEach(n -> {
            System.out.println(n);
        });
        kbase.getKiePackages().forEach(kp -> {
            System.out.println("Package: " + kp.getName());
        });
    }
    return null;
// RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
// DataSource<PMMLRequestData> data = executor.newDataSource("request", this.requestData);
// DataSource<PMML4Result> resultData = executor.newDataSource("results", resultHolder);
// System.out.println("Setting result: "+resultHolder);
// ctx.lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, resultHolder);
// return resultHolder;
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) RequestContextImpl(org.drools.core.command.RequestContextImpl) RegistryContext(org.drools.core.command.impl.RegistryContext) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) KieContainer(org.kie.api.runtime.KieContainer)

Example 9 with KnowledgeBaseImpl

use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.

the class Misc2Test method testFromEPDontRequireLeftInput.

@Test
public void testFromEPDontRequireLeftInput() {
    // DROOLS-1014
    String drl = "rule R when\n" + "    $s1 : String() from entry-point \"xxx\"\n" + "then\n" + "end\n";
    KieBase kbase = new KieHelper().addContent(drl, ResourceType.DRL).build();
    Rete rete = ((KnowledgeBaseImpl) kbase).getRete();
    LeftInputAdapterNode liaNode = null;
    for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
        Class<?> otnType = ((ClassObjectType) otn.getObjectType()).getClassType();
        if (String.class == otnType) {
            assertEquals(1, otn.getObjectSinkPropagator().size());
        } else if (InitialFact.class.isAssignableFrom(otnType)) {
            assertEquals(0, otn.getObjectSinkPropagator().size());
        } else {
            fail("There shouldn't be other OTNs");
        }
    }
}
Also used : Rete(org.drools.core.reteoo.Rete) ClassObjectType(org.drools.core.base.ClassObjectType) KieBase(org.kie.api.KieBase) InitialFact(org.drools.core.InitialFact) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) KieHelper(org.kie.internal.utils.KieHelper) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) Test(org.junit.Test)

Example 10 with KnowledgeBaseImpl

use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.

the class NodePositionInPathTest method test.

@Test
public void test() {
    String drl = "rule R1 when\n" + "    Integer()\n" + "    exists( Integer() and Integer() )\n" + "    String()\n" + "then\n" + "end\n" + "rule R2 when\n" + "    Integer()\n" + "    exists( Integer() and String() )\n" + "then\n" + "end\n";
    KieBase kbase = new KieHelper().addContent(drl, ResourceType.DRL).build();
    ReteDumper.dumpRete(((InternalKnowledgeBase) kbase));
    Rete rete = ((KnowledgeBaseImpl) kbase).getRete();
    LeftInputAdapterNode liaNode = null;
    for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
        Class<?> otnType = ((ClassObjectType) otn.getObjectType()).getClassType();
        if (Integer.class == otnType) {
            liaNode = (LeftInputAdapterNode) otn.getObjectSinkPropagator().getSinks()[0];
        }
    }
    assertEquals(0, liaNode.getPositionInPath());
    LeftTupleSink[] liaSinks = liaNode.getSinkPropagator().getSinks();
    BetaNode join1 = (BetaNode) liaSinks[0];
    assertEquals(1, join1.getPositionInPath());
    ExistsNode ex1 = (ExistsNode) liaSinks[1];
    assertEquals(1, ex1.getPositionInPath());
    BetaNode join2 = (BetaNode) ex1.getSinkPropagator().getSinks()[0];
    assertEquals(2, join2.getPositionInPath());
    RuleTerminalNode rtn1 = (RuleTerminalNode) join2.getSinkPropagator().getSinks()[0];
    assertEquals(3, rtn1.getPositionInPath());
    ExistsNode ex2 = (ExistsNode) liaSinks[2];
    assertEquals(1, ex2.getPositionInPath());
    RuleTerminalNode rtn2 = (RuleTerminalNode) ex2.getSinkPropagator().getSinks()[0];
    assertEquals(2, rtn2.getPositionInPath());
    BetaNode join3 = (BetaNode) join1.getSinkPropagator().getSinks()[0];
    assertEquals(2, join3.getPositionInPath());
    RightInputAdapterNode ria1 = (RightInputAdapterNode) join3.getSinkPropagator().getSinks()[0];
    assertEquals(3, ria1.getPositionInPath());
    BetaNode join4 = (BetaNode) join1.getSinkPropagator().getSinks()[1];
    assertEquals(2, join4.getPositionInPath());
    RightInputAdapterNode ria2 = (RightInputAdapterNode) join4.getSinkPropagator().getSinks()[0];
    assertEquals(3, ria2.getPositionInPath());
    LeftTupleNode[] rtn1PathNodes = rtn1.getPathNodes();
    assertEquals(4, rtn1PathNodes.length);
    checkNodePosition(rtn1PathNodes, liaNode);
    checkNodePosition(rtn1PathNodes, ex1);
    checkNodePosition(rtn1PathNodes, join2);
    checkNodePosition(rtn1PathNodes, rtn1);
    LeftTupleNode[] rtn2PathNodes = rtn2.getPathNodes();
    assertEquals(3, rtn2PathNodes.length);
    checkNodePosition(rtn2PathNodes, liaNode);
    checkNodePosition(rtn2PathNodes, ex2);
    checkNodePosition(rtn2PathNodes, rtn2);
    LeftTupleNode[] ria1PathNodes = ria1.getPathNodes();
    assertEquals(4, ria1PathNodes.length);
    checkNodePosition(ria1PathNodes, liaNode);
    checkNodePosition(ria1PathNodes, join1);
    checkNodePosition(ria1PathNodes, join3);
    checkNodePosition(ria1PathNodes, ria1);
    LeftTupleNode[] ria2PathNodes = ria2.getPathNodes();
    assertEquals(4, ria2PathNodes.length);
    checkNodePosition(ria2PathNodes, liaNode);
    checkNodePosition(ria2PathNodes, join1);
    checkNodePosition(ria2PathNodes, join4);
    checkNodePosition(ria2PathNodes, ria2);
}
Also used : Rete(org.drools.core.reteoo.Rete) BetaNode(org.drools.core.reteoo.BetaNode) ClassObjectType(org.drools.core.base.ClassObjectType) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LeftTupleSink(org.drools.core.reteoo.LeftTupleSink) KieHelper(org.kie.internal.utils.KieHelper) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) ExistsNode(org.drools.core.reteoo.ExistsNode) KieBase(org.kie.api.KieBase) LeftTupleNode(org.drools.core.reteoo.LeftTupleNode) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) RightInputAdapterNode(org.drools.core.reteoo.RightInputAdapterNode) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Aggregations

KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)45 Test (org.junit.Test)31 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)12 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)11 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)11 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)10 Resource (org.kie.api.io.Resource)10 LogicalTypeInconsistencyException (org.drools.core.factmodel.traits.LogicalTypeInconsistencyException)9 TraitFactory (org.drools.core.factmodel.traits.TraitFactory)9 TraitProxy (org.drools.core.factmodel.traits.TraitProxy)9 TraitableBean (org.drools.core.factmodel.traits.TraitableBean)9 ClassPathResource (org.drools.core.io.impl.ClassPathResource)9 KieBase (org.kie.api.KieBase)9 FactType (org.kie.api.definition.type.FactType)9 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)8 KieSession (org.kie.api.runtime.KieSession)8 RuleBaseConfiguration (org.drools.core.RuleBaseConfiguration)6 WorkingMemory (org.drools.core.WorkingMemory)6 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)6 KieHelper (org.kie.internal.utils.KieHelper)6