Search in sources :

Example 1 with BeliefSystem

use of org.drools.core.beliefsystem.BeliefSystem in project drools by kiegroup.

the class TruthMaintenanceSystem method addLogicalDependency.

public InternalFactHandle addLogicalDependency(final InternalFactHandle handle, final Object object, final Object value, final Activation activation, final PropagationContext context, final RuleImpl rule, final ObjectTypeConf typeConf, final boolean read) {
    BeliefSystem beliefSystem = defaultBeliefSystem;
    if (value != null && value instanceof Mode & !(value instanceof SimpleMode)) {
        Mode mode = (Mode) value;
        beliefSystem = (BeliefSystem) mode.getBeliefSystem();
    }
    BeliefSet beliefSet = handle.getEqualityKey().getBeliefSet();
    if (beliefSet == null) {
        if (context.getType() == PropagationContext.Type.MODIFICATION) {
        // if this was a  update, chances  are its trying  to retract a logical assertion
        }
        beliefSet = beliefSystem.newBeliefSet(handle);
        handle.getEqualityKey().setBeliefSet(beliefSet);
    }
    final LogicalDependency node = beliefSystem.newLogicalDependency(activation, beliefSet, object, value);
    activation.getRule().setHasLogicalDependency(true);
    activation.addLogicalDependency(node);
    if (read) {
        // used when deserialising
        beliefSystem.read(node, beliefSet, context, typeConf);
    } else {
        beliefSet = beliefSystem.insert(node, beliefSet, context, typeConf);
    }
    return beliefSet.getFactHandle();
}
Also used : Mode(org.kie.api.internal.runtime.beliefs.Mode) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode) BeliefSystem(org.drools.core.beliefsystem.BeliefSystem) BeliefSet(org.drools.core.beliefsystem.BeliefSet) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode)

Example 2 with BeliefSystem

use of org.drools.core.beliefsystem.BeliefSystem in project drools by kiegroup.

the class DefaultKnowledgeHelper method bolster.

public InternalFactHandle bolster(final Object object, final Object value) {
    if (object == null || !activation.isMatched()) {
        return null;
    }
    InternalFactHandle handle = getFactHandleFromWM(object);
    NamedEntryPoint ep = (NamedEntryPoint) workingMemory.getEntryPoint(EntryPointId.DEFAULT.getEntryPointId());
    ObjectTypeConf otc = ep.getObjectTypeConfigurationRegistry().getObjectTypeConf(ep.getEntryPoint(), object);
    BeliefSystem beliefSystem;
    if (value == null) {
        beliefSystem = workingMemory.getTruthMaintenanceSystem().getBeliefSystem();
    } else {
        if (value instanceof Mode) {
            Mode m = (Mode) value;
            beliefSystem = (BeliefSystem) m.getBeliefSystem();
        } else {
            beliefSystem = workingMemory.getTruthMaintenanceSystem().getBeliefSystem();
        }
    }
    BeliefSet beliefSet = null;
    if (handle == null) {
        handle = workingMemory.getKnowledgeBase().getConfiguration().getComponentFactory().getFactHandleFactoryService().newFactHandle(object, otc, workingMemory, ep);
    }
    if (handle.getEqualityKey() == null) {
        handle.setEqualityKey(new EqualityKey(handle, EqualityKey.STATED));
    } else {
        beliefSet = handle.getEqualityKey().getBeliefSet();
    }
    if (beliefSet == null) {
        beliefSet = beliefSystem.newBeliefSet(handle);
        handle.getEqualityKey().setBeliefSet(beliefSet);
    }
    return beliefSystem.insert(beliefSystem.asMode(value), activation.getRule(), activation, object, beliefSet, activation.getPropagationContext(), otc).getFactHandle();
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) EqualityKey(org.drools.core.common.EqualityKey) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode) Mode(org.kie.api.internal.runtime.beliefs.Mode) BeliefSystem(org.drools.core.beliefsystem.BeliefSystem) BeliefSet(org.drools.core.beliefsystem.BeliefSet) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Aggregations

BeliefSet (org.drools.core.beliefsystem.BeliefSet)2 BeliefSystem (org.drools.core.beliefsystem.BeliefSystem)2 SimpleMode (org.drools.core.beliefsystem.simple.SimpleMode)2 Mode (org.kie.api.internal.runtime.beliefs.Mode)2 EqualityKey (org.drools.core.common.EqualityKey)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)1