Search in sources :

Example 1 with EmptyBetaConstraints

use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.

the class BetaNodeBuilder method build.

public BetaNode build() {
    NodeFactory nFactory = buildContext.getComponentFactory().getNodeFactoryService();
    EntryPointNode epn = buildContext.getKnowledgeBase().getRete().getEntryPointNodes().values().iterator().next();
    ObjectTypeNode otn = nFactory.buildObjectTypeNode(buildContext.getNextId(), epn, new ClassObjectType(leftType), buildContext);
    LeftInputAdapterNode leftInput = nFactory.buildLeftInputAdapterNode(buildContext.getNextId(), otn, buildContext);
    ObjectSource rightInput = nFactory.buildObjectTypeNode(buildContext.getNextId(), epn, new ClassObjectType(rightType), buildContext);
    ReteTesterHelper reteTesterHelper = new ReteTesterHelper();
    Pattern pattern = new Pattern(0, new ClassObjectType(leftType));
    // BetaNodeFieldConstraint betaConstraint = null;
    BetaConstraints betaConstraints = null;
    if (constraintFieldName != null) {
        ClassFieldAccessorStore store = (ClassFieldAccessorStore) reteTesterHelper.getStore();
        InternalReadAccessor extractor = store.getReader(leftType, leftFieldName);
        Declaration declr = new Declaration(leftVariableName, extractor, pattern);
        betaConstraints = new SingleBetaConstraints(reteTesterHelper.getBoundVariableConstraint(rightType, constraintFieldName, declr, constraintOperator), buildContext.getKnowledgeBase().getConfiguration());
    } else {
        betaConstraints = new EmptyBetaConstraints();
    }
    switch(nodeType) {
        case NodeTypeEnums.JoinNode:
            return new JoinNode(0, leftInput, rightInput, betaConstraints, buildContext);
        case NodeTypeEnums.NotNode:
            return new NotNode(0, leftInput, rightInput, betaConstraints, buildContext);
        case NodeTypeEnums.ExistsNode:
            return new ExistsNode(0, leftInput, rightInput, betaConstraints, buildContext);
    }
    throw new IllegalStateException("Unable to build Node");
}
Also used : Pattern(org.drools.core.rule.Pattern) SingleBetaConstraints(org.drools.core.common.SingleBetaConstraints) NotNode(org.drools.core.reteoo.NotNode) BetaConstraints(org.drools.core.common.BetaConstraints) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) SingleBetaConstraints(org.drools.core.common.SingleBetaConstraints) ClassObjectType(org.drools.core.base.ClassObjectType) JoinNode(org.drools.core.reteoo.JoinNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) ExistsNode(org.drools.core.reteoo.ExistsNode) EntryPointNode(org.drools.core.reteoo.EntryPointNode) NodeFactory(org.drools.core.reteoo.builder.NodeFactory) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) ObjectSource(org.drools.core.reteoo.ObjectSource) Declaration(org.drools.core.rule.Declaration) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Example 2 with EmptyBetaConstraints

use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.

the class NodeSegmentUnlinkingTest method createBetaNode.

private BetaNode createBetaNode(int id, int type, LeftTupleSource leftTupleSource) {
    MockObjectSource mockObjectSource = new MockObjectSource(8);
    BetaNode betaNode = null;
    switch(type) {
        case JOIN_NODE:
            {
                betaNode = new JoinNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case EXISTS_NODE:
            {
                betaNode = new ExistsNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case NOT_NODE:
            {
                betaNode = new NotNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
    }
    mockObjectSource.attach(buildContext);
    betaNode.attach(buildContext);
    return betaNode;
}
Also used : PhreakNotNode(org.drools.core.phreak.PhreakNotNode) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints)

Example 3 with EmptyBetaConstraints

use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.

the class NodeSegmentUnlinkingTest method testSingleNodeinSegment.

@Test
public void testSingleNodeinSegment() {
    rule1 = new RuleImpl("rule1");
    rule2 = new RuleImpl("rule2");
    rule3 = new RuleImpl("rule3");
    KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
    BuildContext buildContext = new BuildContext(kBase);
    MockObjectSource mockObjectSource = new MockObjectSource(8);
    MockTupleSource mockTupleSource = new MockTupleSource(9);
    // n2 is only node in it's segment
    ObjectTypeNode otn = new ObjectTypeNode(2, null, new ClassObjectType(String.class), buildContext);
    BetaNode n1 = new JoinNode(10, new LeftInputAdapterNode(3, otn, buildContext), mockObjectSource, new EmptyBetaConstraints(), buildContext);
    BetaNode n2 = new JoinNode(11, n1, mockObjectSource, new EmptyBetaConstraints(), buildContext);
    BetaNode n3 = new JoinNode(12, n1, mockObjectSource, new EmptyBetaConstraints(), buildContext);
    BetaNode n4 = new JoinNode(13, n2, mockObjectSource, new EmptyBetaConstraints(), buildContext);
    BetaNode n5 = new JoinNode(14, n2, mockObjectSource, new EmptyBetaConstraints(), buildContext);
    n1.addAssociation(rule1);
    n1.addAssociation(rule2);
    n1.addAssociation(rule3);
    n2.addAssociation(rule2);
    n2.addAssociation(rule3);
    n3.addAssociation(rule1);
    n4.addAssociation(rule2);
    n5.addAssociation(rule3);
    mockObjectSource.attach(buildContext);
    mockTupleSource.attach(buildContext);
    n1.attach(buildContext);
    n2.attach(buildContext);
    n3.attach(buildContext);
    n4.attach(buildContext);
    n5.attach(buildContext);
    StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
    createSegmentMemory(n2, ksession);
    BetaMemory bm = (BetaMemory) ksession.getNodeMemory(n1);
    assertNull(bm.getSegmentMemory());
    bm = (BetaMemory) ksession.getNodeMemory(n3);
    assertNull(bm.getSegmentMemory());
    bm = (BetaMemory) ksession.getNodeMemory(n4);
    assertNull(bm.getSegmentMemory());
    bm = (BetaMemory) ksession.getNodeMemory(n2);
    assertEquals(1, bm.getNodePosMaskBit());
    assertEquals(1, bm.getSegmentMemory().getAllLinkedMaskTest());
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) KieBaseConfiguration(org.kie.api.KieBaseConfiguration) BuildContext(org.drools.core.reteoo.builder.BuildContext) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) Test(org.junit.Test)

Example 4 with EmptyBetaConstraints

use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.

the class RuleUnlinkingWithSegmentMemoryTest method createNetworkNode.

private NetworkNode createNetworkNode(int id, int type, LeftTupleSource leftTupleSource, RuleImpl rule) {
    MockObjectSource mockObjectSource = new MockObjectSource(8);
    LeftTupleSink networkNode = null;
    switch(type) {
        case JOIN_NODE:
            {
                networkNode = new JoinNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case EXISTS_NODE:
            {
                networkNode = new ExistsNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case NOT_NODE:
            {
                networkNode = new NotNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case RULE_TERMINAL_NODE:
            {
                networkNode = new RuleTerminalNode(id, leftTupleSource, rule, new GroupElement(Type.AND), 0, buildContext);
                break;
            }
    }
    mockObjectSource.attach();
    if (NodeTypeEnums.isLeftTupleSource(networkNode)) {
        ((LeftTupleSource) networkNode).attach(buildContext);
    } else {
        ((RuleTerminalNode) networkNode).attach(buildContext);
    }
    return networkNode;
}
Also used : EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) GroupElement(org.drools.core.rule.GroupElement)

Example 5 with EmptyBetaConstraints

use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.

the class RuleUnlinkingTest method createNetworkNode.

private NetworkNode createNetworkNode(int id, int type, LeftTupleSource leftTupleSource, RuleImpl rule) {
    MockObjectSource mockObjectSource = new MockObjectSource(8);
    LeftTupleSink networkNode = null;
    switch(type) {
        case JOIN_NODE:
            {
                networkNode = new JoinNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case EXISTS_NODE:
            {
                networkNode = new ExistsNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case NOT_NODE:
            {
                networkNode = new NotNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case RULE_TERMINAL_NODE:
            {
                networkNode = new RuleTerminalNode(id, leftTupleSource, rule, new GroupElement(Type.AND), 0, buildContext);
                break;
            }
    }
    mockObjectSource.attach();
    if (NodeTypeEnums.isLeftTupleSource(networkNode)) {
        ((LeftTupleSource) networkNode).attach(buildContext);
    } else {
        ((RuleTerminalNode) networkNode).attach(buildContext);
    }
    return networkNode;
}
Also used : EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) GroupElement(org.drools.core.rule.GroupElement)

Aggregations

EmptyBetaConstraints (org.drools.core.common.EmptyBetaConstraints)5 ClassObjectType (org.drools.core.base.ClassObjectType)2 GroupElement (org.drools.core.rule.GroupElement)2 ClassFieldAccessorStore (org.drools.core.base.ClassFieldAccessorStore)1 BetaConstraints (org.drools.core.common.BetaConstraints)1 SingleBetaConstraints (org.drools.core.common.SingleBetaConstraints)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)1 PhreakNotNode (org.drools.core.phreak.PhreakNotNode)1 EntryPointNode (org.drools.core.reteoo.EntryPointNode)1 ExistsNode (org.drools.core.reteoo.ExistsNode)1 JoinNode (org.drools.core.reteoo.JoinNode)1 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)1 NotNode (org.drools.core.reteoo.NotNode)1 ObjectSource (org.drools.core.reteoo.ObjectSource)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 BuildContext (org.drools.core.reteoo.builder.BuildContext)1 NodeFactory (org.drools.core.reteoo.builder.NodeFactory)1 Declaration (org.drools.core.rule.Declaration)1 Pattern (org.drools.core.rule.Pattern)1