Search in sources :

Example 6 with EqualityKey

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

the class DefeasibilityTest method testDefeasibleEntailmentWithStrictOverride.

@Test(timeout = 10000)
public void testDefeasibleEntailmentWithStrictOverride() {
    KieSession kSession = getSession("org/drools/compiler/beliefsystem/defeasible/strictOverride.drl");
    kSession.fireAllRules();
    TruthMaintenanceSystem tms = ((NamedEntryPoint) kSession.getEntryPoint("DEFAULT")).getTruthMaintenanceSystem();
    FactType Ctype = kSession.getKieBase().getFactType("org.drools.defeasible", "C");
    FactType Xtype = kSession.getKieBase().getFactType("org.drools.defeasible", "X");
    ObjectHashMap keys = tms.getEqualityKeyMap();
    Iterator iter = keys.iterator();
    ObjectHashMap.ObjectEntry entry;
    while ((entry = (ObjectHashMap.ObjectEntry) iter.next()) != null) {
        EqualityKey key = (EqualityKey) entry.getValue();
        Class factClass = key.getFactHandle().getObject().getClass();
        if (factClass == Ctype.getFactClass()) {
            checkStatus(key, 1, DefeasibilityStatus.DEFINITELY);
        } else if (factClass == Xtype.getFactClass()) {
            checkStatus(key, 1, DefeasibilityStatus.DEFINITELY);
        } else {
            fail("Unrecognized object has been logically justified : " + factClass);
        }
    }
    assertEquals(5, kSession.getObjects().size());
}
Also used : TruthMaintenanceSystem(org.drools.core.common.TruthMaintenanceSystem) EqualityKey(org.drools.core.common.EqualityKey) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) Iterator(org.drools.core.util.Iterator) ObjectHashMap(org.drools.core.util.ObjectHashMap) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Example 7 with EqualityKey

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

the class DefeasibilityTest method testRemoveDefiniteJustifier.

@Test(timeout = 10000)
public void testRemoveDefiniteJustifier() {
    KieSession kSession = getSession("org/drools/compiler/beliefsystem/defeasible/strictRetract.drl");
    FactHandle h = kSession.insert("go");
    kSession.fireAllRules();
    TruthMaintenanceSystem tms = ((NamedEntryPoint) kSession.getEntryPoint("DEFAULT")).getTruthMaintenanceSystem();
    FactType Ctype = kSession.getKieBase().getFactType("org.drools.defeasible", "C");
    FactType Atype = kSession.getKieBase().getFactType("org.drools.defeasible", "A");
    ObjectHashMap keys = tms.getEqualityKeyMap();
    Iterator iter = keys.iterator();
    ObjectHashMap.ObjectEntry entry;
    while ((entry = (ObjectHashMap.ObjectEntry) iter.next()) != null) {
        EqualityKey key = (EqualityKey) entry.getValue();
        Class factClass = key.getFactHandle().getObject().getClass();
        if (factClass == Ctype.getFactClass()) {
            checkStatus(key, 1, DefeasibilityStatus.DEFINITELY);
        } else if (factClass == Atype.getFactClass()) {
            checkStatus(key, 1, DefeasibilityStatus.DEFINITELY);
        } else {
            fail("Unrecognized object has been logically justified : " + factClass);
        }
    }
    kSession.retract(h);
    kSession.fireAllRules();
    keys = tms.getEqualityKeyMap();
    iter = keys.iterator();
    while ((entry = (ObjectHashMap.ObjectEntry) iter.next()) != null) {
        EqualityKey key = (EqualityKey) entry.getValue();
        Class factClass = key.getFactHandle().getObject().getClass();
        if (factClass == Ctype.getFactClass()) {
            checkStatus(key, 1, DefeasibilityStatus.DEFEASIBLY);
        } else {
            fail("Unrecognized object has been logically justified : " + factClass);
        }
    }
}
Also used : TruthMaintenanceSystem(org.drools.core.common.TruthMaintenanceSystem) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) EqualityKey(org.drools.core.common.EqualityKey) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) Iterator(org.drools.core.util.Iterator) ObjectHashMap(org.drools.core.util.ObjectHashMap) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Example 8 with EqualityKey

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

the class DefeasibilityTest method defeasibleEntailmentMultiActivation.

@Test(timeout = 10000)
public void defeasibleEntailmentMultiActivation() {
    KieSession kSession = getSession("org/drools/compiler/beliefsystem/defeasible/defeat.drl");
    kSession.fireAllRules();
    TruthMaintenanceSystem tms = ((NamedEntryPoint) kSession.getEntryPoint("DEFAULT")).getTruthMaintenanceSystem();
    FactType Xtype = kSession.getKieBase().getFactType("org.drools.defeasible", "X");
    ObjectHashMap keys = tms.getEqualityKeyMap();
    Iterator iter = keys.iterator();
    ObjectHashMap.ObjectEntry entry;
    while ((entry = (ObjectHashMap.ObjectEntry) iter.next()) != null) {
        EqualityKey key = (EqualityKey) entry.getValue();
        Class factClass = key.getFactHandle().getObject().getClass();
        if (factClass == Xtype.getFactClass()) {
            checkStatus(key, 3, DefeasibilityStatus.UNDECIDABLY);
        } else {
            fail("Unrecognized object has been logically justified : " + factClass);
        }
    }
    assertEquals(3, kSession.getObjects().size());
}
Also used : TruthMaintenanceSystem(org.drools.core.common.TruthMaintenanceSystem) EqualityKey(org.drools.core.common.EqualityKey) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) Iterator(org.drools.core.util.Iterator) ObjectHashMap(org.drools.core.util.ObjectHashMap) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Example 9 with EqualityKey

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

the class DefeasibilityTest method testStrictEntailment.

@Test(timeout = 10000)
public void testStrictEntailment() {
    KieSession kSession = getSession("org/drools/compiler/beliefsystem/defeasible/strict.drl");
    kSession.fireAllRules();
    TruthMaintenanceSystem tms = ((NamedEntryPoint) kSession.getEntryPoint("DEFAULT")).getTruthMaintenanceSystem();
    FactType Ctype = kSession.getKieBase().getFactType("org.drools.defeasible", "C");
    FactType Dtype = kSession.getKieBase().getFactType("org.drools.defeasible", "D");
    ObjectHashMap keys = tms.getEqualityKeyMap();
    Iterator iter = keys.iterator();
    ObjectHashMap.ObjectEntry entry;
    while ((entry = (ObjectHashMap.ObjectEntry) iter.next()) != null) {
        EqualityKey key = (EqualityKey) entry.getValue();
        Class factClass = key.getFactHandle().getObject().getClass();
        if (factClass == Ctype.getFactClass()) {
            checkStatus(key, 2, DefeasibilityStatus.DEFINITELY);
        } else if (factClass == Dtype.getFactClass()) {
            checkStatus(key, 1, DefeasibilityStatus.DEFINITELY);
        } else {
            fail("Unrecognized object has been logically justified : " + factClass);
        }
    }
    assertEquals(5, kSession.getObjects().size());
}
Also used : TruthMaintenanceSystem(org.drools.core.common.TruthMaintenanceSystem) EqualityKey(org.drools.core.common.EqualityKey) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) Iterator(org.drools.core.util.Iterator) ObjectHashMap(org.drools.core.util.ObjectHashMap) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Example 10 with EqualityKey

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

the class DefeasibilityTest method testRemoveDefeasibleJustifier.

@Test(timeout = 10000)
public void testRemoveDefeasibleJustifier() {
    KieSession kSession = getSession("org/drools/compiler/beliefsystem/defeasible/defeaterRetract.drl");
    FactHandle h = kSession.insert("go");
    kSession.fireAllRules();
    TruthMaintenanceSystem tms = ((NamedEntryPoint) kSession.getEntryPoint("DEFAULT")).getTruthMaintenanceSystem();
    FactType Ctype = kSession.getKieBase().getFactType("org.drools.defeasible", "C");
    FactType Atype = kSession.getKieBase().getFactType("org.drools.defeasible", "A");
    ObjectHashMap keys = tms.getEqualityKeyMap();
    Iterator iter = keys.iterator();
    ObjectHashMap.ObjectEntry entry;
    while ((entry = (ObjectHashMap.ObjectEntry) iter.next()) != null) {
        EqualityKey key = (EqualityKey) entry.getValue();
        Class factClass = key.getFactHandle().getObject().getClass();
        if (factClass == Ctype.getFactClass()) {
            checkStatus(key, 1, DefeasibilityStatus.DEFINITELY);
        } else if (factClass == Atype.getFactClass()) {
            checkStatus(key, 1, DefeasibilityStatus.DEFINITELY);
        } else {
            fail("Unrecognized object has been logically justified : " + factClass);
        }
    }
    kSession.retract(h);
    kSession.fireAllRules();
    keys = tms.getEqualityKeyMap();
    iter = keys.iterator();
    while ((entry = (ObjectHashMap.ObjectEntry) iter.next()) != null) {
        EqualityKey key = (EqualityKey) entry.getValue();
        Class factClass = key.getFactHandle().getObject().getClass();
        if (factClass == Ctype.getFactClass()) {
            checkStatus(key, 1, DefeasibilityStatus.DEFINITELY);
        } else {
            fail("Unrecognized object has been logically justified : " + factClass);
        }
    }
}
Also used : TruthMaintenanceSystem(org.drools.core.common.TruthMaintenanceSystem) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) EqualityKey(org.drools.core.common.EqualityKey) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) Iterator(org.drools.core.util.Iterator) ObjectHashMap(org.drools.core.util.ObjectHashMap) KieSession(org.kie.api.runtime.KieSession) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Aggregations

EqualityKey (org.drools.core.common.EqualityKey)21 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)17 Test (org.junit.Test)16 TruthMaintenanceSystem (org.drools.core.common.TruthMaintenanceSystem)15 KieSession (org.kie.api.runtime.KieSession)15 ObjectHashMap (org.drools.core.util.ObjectHashMap)14 Iterator (org.drools.core.util.Iterator)10 FactType (org.kie.api.definition.type.FactType)10 ArrayList (java.util.ArrayList)9 InternalFactHandle (org.drools.core.common.InternalFactHandle)9 FactHandle (org.kie.api.runtime.rule.FactHandle)7 List (java.util.List)5 Ignore (org.junit.Ignore)4 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)3 ObjectEntry (org.drools.core.util.ObjectHashMap.ObjectEntry)3 Person (org.drools.compiler.Person)2 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)2 KieBase (org.kie.api.KieBase)2 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)2 HashSet (java.util.HashSet)1