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());
}
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);
}
}
}
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());
}
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());
}
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);
}
}
}
Aggregations