[jboss-svn-commits] JBL Code SVN: r18952 - in labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools: base and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Mar 13 21:07:11 EDT 2008


Author: dsotty
Date: 2008-03-13 21:07:10 -0400 (Thu, 13 Mar 2008)
New Revision: 18952

Modified:
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/RuleBase.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/WorkingMemory.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/BaseEvaluator.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/ClassObjectType.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/evaluators/Operator.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/EqualityKey.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/facttemplates/FactTemplateObjectType.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/AndConstraint.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/OrConstraint.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/AlphaNodeFieldConstraint.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java
   labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/ObjectType.java
Log:


Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/RuleBase.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/RuleBase.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/RuleBase.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -22,6 +22,8 @@
 
 import org.drools.rule.Package;
 
+import uncertainty.factory.IDegreeFactory;
+
 /**
  * Active collection of <code>Rule</code>s.
  * 
@@ -41,6 +43,18 @@
     public static final int RETEOO = 1;
 
     StatelessSession newStatelessSession();
+    
+    
+    
+    /**
+     * The rules work for some kind of uncertainty model, so 
+     * the rules bring a factory which provides the coherent 
+     * instances. 
+     * 
+     * @return 
+     */
+    public IDegreeFactory getTruthFactory();
+    
 
     /**
      * Create a new <code>WorkingMemory</code> session for this

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/WorkingMemory.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/WorkingMemory.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/WorkingMemory.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -17,16 +17,21 @@
  */
 
 import java.util.Collection;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
 
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
 import org.drools.process.instance.ProcessInstance;
 import org.drools.process.instance.WorkItemManager;
 import org.drools.spi.AgendaFilter;
 import org.drools.spi.AgendaGroup;
 import org.drools.spi.AsyncExceptionHandler;
+import org.drools.spi.Constraint;
 import org.drools.spi.GlobalResolver;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 /**
  * A knowledge session for a <code>RuleBase</code>.
  * 
@@ -217,7 +222,36 @@
      */
     FactHandle insert(Object object) throws FactException;
     
+    
     /**
+     * Assert a fact stating certain properties.
+     * 
+     * @param object
+     *            The fact object.
+     * 
+     * @return The new fact-handle associated with the object.
+     * 
+     * @throws FactException
+     *             If a RuntimeException error occurs.
+     */
+    FactHandle insert(Object object, Hashtable<Constraint, IUncertainDegree> prems) throws FactException;
+    
+    
+    
+    /**
+     * Assert a fact stating certain properties.
+     * Logical assertion allows information to be combined with the existing one
+     * @param object
+     *            The fact object.
+     * 
+     * @return The new fact-handle associated with the object.
+     * 
+     * @throws FactException
+     *             If a RuntimeException error occurs.
+     */
+    FactHandle insertLogical(Object object, Hashtable<Constraint, IUncertainDegree> prems) throws FactException;
+    
+    /**
      * Assert a fact with inherent duration.
      * 
      * @param object

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/BaseEvaluator.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/BaseEvaluator.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/BaseEvaluator.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -24,12 +24,17 @@
 import org.drools.spi.Extractor;
 import org.drools.spi.FieldValue;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
 
 /**
  * BaseEvaluator is an Object Comparator that is operator aware
  * 
+ * 
+ * TODO : In uncertain mode, a false evaluation actually returns Unknown. This is not conceptually clean
+ * 
+ * 
  * @author mproctor
  * 
  */
@@ -77,7 +82,10 @@
     }
 
     public int hashCode() {
-        return (this.getValueType().hashCode()) ^ (this.getOperator().hashCode()) ^ (this.getClass().hashCode());
+    	int ans = (this.getValueType().hashCode()) ^ (this.getOperator().hashCode()) ^ (this.getClass().hashCode());
+//    	System.out.println("BaseEvaluator returns hashcode from "+this.getValueType().hashCode() + " " + this.getOperator().hashCode() + " "+this.getClass().hashCode());
+//    	System.out.println("Ans is "+ans);
+        return ans;
     }
 
     
@@ -85,7 +93,8 @@
             Extractor extractor,
             Object object1,
             FieldValue value) {
-        return evaluate(workingMemory,extractor,object1,value) ? new Degree(1) : new Degree(0);
+    	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
+        return evaluate(workingMemory,extractor,object1,value) ? factory.True() : factory.Unknown();
     }
 
     public IUncertainDegree evaluateUnc(InternalWorkingMemory workingMemory,
@@ -93,19 +102,22 @@
             Object left,
             Extractor rightExtractor,
             Object right) {
-        return evaluate(workingMemory,leftExtractor,left,rightExtractor,right) ? new Degree(1) : new Degree(0);
+    	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
+        return evaluate(workingMemory,leftExtractor,left,rightExtractor,right) ? factory.True() : factory.Unknown();
     }
 
     public IUncertainDegree evaluateCachedLeftUnc(InternalWorkingMemory workingMemory,
             VariableContextEntry context,
             Object object1) {
-        return evaluateCachedLeft(workingMemory,context,object1) ? new Degree(1) : new Degree(0);
+    	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
+        return evaluateCachedLeft(workingMemory,context,object1) ? factory.True() : factory.Unknown();
     }
 
     public IUncertainDegree evaluateCachedRightUnc(InternalWorkingMemory workingMemory,
             VariableContextEntry context,
             Object object2) {
-        return evaluateCachedRight(workingMemory,context,object2) ? new Degree(1) : new Degree(0);
+    	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
+        return evaluateCachedRight(workingMemory,context,object2) ? factory.True() : factory.Unknown();
     }
     
     

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/ClassObjectType.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/ClassObjectType.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/ClassObjectType.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -18,6 +18,7 @@
 
 import org.drools.spi.ObjectType;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
 
@@ -170,7 +171,7 @@
 
     
     /**
-     * Ontological ???? based connection between classes
+     * TODO: Ontological ???? based connection between classes
      * As this is a method stub, it returns TRUE if the objects
      * belong to the same class and 0.9-TRUE if the object is a subclass of the given
      * 
@@ -178,20 +179,20 @@
      * @author Sotty
      * 
      */
-    public IUncertainDegree isCompatibleWith(Object object) {
+    public IUncertainDegree isCompatibleWith(Object object, IDegreeFactory factory) {
         if ( object == null) {
-            return new Degree(0);
+            return factory.False();
         }
         
         Class clazz = object instanceof ShadowProxy ? object.getClass().getSuperclass() : object.getClass();
         if ( this == object || clazz == objectTypeClass) {
-            return new Degree(1);
+            return factory.True();
         }
         if (this.objectTypeClass.isAssignableFrom(object.getClass())) {
             System.out.println("Deprec: ClassObjectTypeFilter : Object is not a 'full' member of type, lose degree ");
-            return new Degree(0.66);
+            return factory.buildDegree(0.66);
         }
-        return new Degree(0);        
+        return factory.False();        
     }
 
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -16,17 +16,23 @@
  * limitations under the License.
  */
 
+import java.util.Hashtable;
+
 import org.drools.FactException;
 import org.drools.FactHandle;
 import org.drools.WorkingMemory;
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
 import org.drools.common.InternalWorkingMemoryActions;
 import org.drools.rule.Declaration;
 import org.drools.rule.GroupElement;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
+import org.drools.spi.Constraint;
 import org.drools.spi.KnowledgeHelper;
 import org.drools.spi.Tuple;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 public class DefaultKnowledgeHelper
     implements
     KnowledgeHelper {
@@ -126,6 +132,23 @@
 								   this.activation );
 	}
 
+    
+
+    public void insertLogical(Object object,
+			Hashtable<Constraint, IUncertainDegree> logicalPremises)
+			throws FactException {
+        System.out.println("DefaultKnwHelper: Insert Logical with prems");
+		this.workingMemory.insertLogical( object,								   
+								   0,
+								   false,								  
+								   this.rule,
+								   this.activation,
+								   logicalPremises );
+
+		
+	}
+    
+    
     public void update(final FactHandle handle,
                        final Object newObject) throws FactException {
         // only update if this fact exists in the wm
@@ -246,4 +269,8 @@
     public void halt() {
         this.workingMemory.halt();
     }
+
+	
+
+	
 }

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -16,21 +16,26 @@
  * limitations under the License.
  */
 
+import java.util.Hashtable;
 import java.util.List;
 
 import org.drools.FactException;
 import org.drools.FactHandle;
 import org.drools.QueryResults;
 import org.drools.WorkingMemory;
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
 import org.drools.common.InternalWorkingMemoryActions;
 import org.drools.rule.Declaration;
 import org.drools.rule.GroupElement;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
 import org.drools.spi.AgendaGroup;
+import org.drools.spi.Constraint;
 import org.drools.spi.KnowledgeHelper;
 import org.drools.spi.Tuple;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 public class SequentialKnowledgeHelper
     implements
     KnowledgeHelper {
@@ -91,6 +96,12 @@
     						  final long duration,
             				  final boolean dynamic) throws FactException {
     }
+    
+    
+    public void insertLogical(Object object,
+			Hashtable<Constraint, IUncertainDegree> logicalPremises)
+			throws FactException {				
+	}  
 
     public void update(final FactHandle handle,
                        final Object newObject) throws FactException {
@@ -178,5 +189,7 @@
     
     public void halt() {
         this.workingMemory.halt();
-    }    
+    }
+
+	  
 }

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -34,6 +34,7 @@
 import org.drools.spi.FieldValue;
 import org.drools.util.DateUtils;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
 
@@ -1451,57 +1452,64 @@
         public IUncertainDegree evaluateUnc(InternalWorkingMemory workingMemory,
                 final Extractor extractor,
                 final Object object1, final FieldValue object2) {
+        	
+        	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory(); 
             if ( extractor.isNullValue( workingMemory, object1 ) ) {
-                return Degree.fromBoolean(object2.isNull());
+                return factory.fromBoolean(object2.isNull());
             } else if ( object2.isNull() ) {
-                return new Degree(0);
+                return factory.False();
             }
 
-            return eval(extractor.getIntValue( workingMemory, object1 ), object2.getIntValue());
+            return eval(extractor.getIntValue( workingMemory, object1 ), object2.getIntValue() , factory);
         }
 
         public IUncertainDegree evaluateCachedRightUnc(InternalWorkingMemory workingMemory,
                 final VariableContextEntry context, final Object left) {
+        	
+        	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
             if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
-                return Degree.fromBoolean(context.isRightNull());
+                return factory.fromBoolean(context.isRightNull());
             } else if ( context.isRightNull() ) {
-                return new Degree(0);
+                return factory.False();
             }
 
-            return eval(context.declaration.getExtractor().getIntValue( workingMemory, left ) , ((LongVariableContextEntry) context).right); 
+            return eval(context.declaration.getExtractor().getIntValue( workingMemory, left ) , ((LongVariableContextEntry) context).right , factory); 
         }
 
         public IUncertainDegree evaluateCachedLeftUnc(InternalWorkingMemory workingMemory,
                 final VariableContextEntry context, final Object object2) {
+        	
+        	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
             if ( context.extractor.isNullValue( workingMemory, object2 )) {
-                return Degree.fromBoolean(context.isLeftNull());
+                return factory.fromBoolean(context.isLeftNull());
             } else if ( context.isLeftNull() ) {
-                return new Degree(0);
+                return factory.False();
             }
 
-            return eval(context.extractor.getIntValue( workingMemory, object2 ),((LongVariableContextEntry) context).left);
+            return eval(context.extractor.getIntValue( workingMemory, object2 ),((LongVariableContextEntry) context).left , factory);
         }
 
         public IUncertainDegree evaluateUnc(InternalWorkingMemory workingMemory,
                 final Extractor extractor1,
                 final Object object1,
-                final Extractor extractor2, final Object object2) {            
+                final Extractor extractor2, final Object object2) {
+        	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
             if (extractor1.isNullValue( workingMemory, object1 )) {
-                return Degree.fromBoolean(extractor2.isNullValue( workingMemory, object2 ));
+                return factory.fromBoolean(extractor2.isNullValue( workingMemory, object2 ));
             } else if (extractor2.isNullValue( workingMemory, object2 )) {
-                return new Degree(0);
+                return factory.False();
             }
 
-            return eval(extractor1.getIntValue( workingMemory, object1 ),extractor2.getIntValue( workingMemory, object2 ));
+            return eval(extractor1.getIntValue( workingMemory, object1 ),extractor2.getIntValue( workingMemory, object2 ) , factory);
         }
         
-        private IUncertainDegree eval(long i1, long i2) {            
+        private IUncertainDegree eval(long i1, long i2, IDegreeFactory factory) {            
             double den = (Math.abs(i1)+Math.abs(i2));
             double num = Math.abs(i1-i2);               
             
             double ans = (den == 0) ? 1 : 1 - num / den;
                 
-            return new Degree(ans);
+            return factory.buildDegree(ans);
         }
         
         

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/evaluators/Operator.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/evaluators/Operator.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/base/evaluators/Operator.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -106,7 +106,9 @@
     @Override
     public int hashCode() {
         final int PRIME = 31;
-        int result = super.hashCode();
+        // TODO : CRITICAL MODIFICATION ???
+        //int result = super.hashCode();
+        int result = 1;
         result = PRIME * result + (isNegated ? 1231 : 1237);
         result = PRIME * result + ((operator == null) ? 0 : operator.hashCode());
         return result;

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -16,10 +16,16 @@
  * limitations under the License.
  */
 
+import java.util.Hashtable;
+
 import org.drools.WorkingMemory;
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
+import org.drools.spi.Constraint;
 import org.drools.spi.FactHandleFactory;
 import org.drools.util.PrimitiveLongStack;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 public abstract class AbstractFactHandleFactory
     implements
     FactHandleFactory {
@@ -75,6 +81,24 @@
                               workingMemory );
     }
 
+    
+    
+    public UncInternalFactHandle newUncFactHandle(Object object,
+			Hashtable<Constraint, IUncertainDegree> priors, boolean isEvent, 
+			WorkingMemory workingMemory) {
+    	long id = this.factHandlePool.isEmpty() ? this.id++ : this.factHandlePool.pop();
+		return newUncFactHandle( id, object, priors, isEvent, 0, workingMemory);
+	}
+    
+    public UncInternalFactHandle newUncFactHandle(Object object,
+			Hashtable<Constraint, IUncertainDegree> priors, boolean isEvent, long duration,
+			WorkingMemory workingMemory) {
+    	long id = this.factHandlePool.isEmpty() ? this.id++ : this.factHandlePool.pop();
+		return newUncFactHandle( id, object, priors, isEvent, duration, workingMemory);
+	}
+    
+    
+    
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#newFactHandle(long)
      */
@@ -106,7 +130,30 @@
                               workingMemory );
     }
 
-    /* (non-Javadoc)
+    
+    
+    protected final UncFactHandle newUncFactHandle(final long id,
+            final Object object,
+            Hashtable<Constraint, IUncertainDegree> priors,
+            final boolean isEvent,
+            final long duration,
+            final WorkingMemory workingMemory ) {
+    	
+    	return newUncFactHandle( id,
+    			object,
+    			priors,
+    			this.counter++,
+    			isEvent,
+    			duration,
+    			workingMemory );
+    }
+    
+    
+    protected abstract UncFactHandle newUncFactHandle(long id, Object object,
+			Hashtable<Constraint, IUncertainDegree> priors, long recency,
+			boolean isEvent, long duration, WorkingMemory workingMemory);
+
+	/* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#newFactHandle(long)
      */
     protected abstract InternalFactHandle newFactHandle(final long id,

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -25,6 +25,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -75,6 +76,7 @@
 import org.drools.spi.AgendaFilter;
 import org.drools.spi.AgendaGroup;
 import org.drools.spi.AsyncExceptionHandler;
+import org.drools.spi.Constraint;
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.GlobalResolver;
 import org.drools.spi.PropagationContext;
@@ -83,6 +85,8 @@
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
 
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
+
 /**
  * Implementation of <code>WorkingMemory</code>.
  * 
@@ -602,6 +606,35 @@
                        null,
                        null );
     }
+    
+    
+    
+    public FactHandle insert(final Object object, Hashtable<Constraint, IUncertainDegree> priors) throws FactException {
+        return insert( EntryPoint.DEFAULT,
+        			   object,
+                       0,
+                       false,
+                       false,
+                       null,
+                       null,
+                       priors);
+    }
+    
+    
+    public FactHandle insertLogical(final Object object, Hashtable<Constraint, IUncertainDegree> priors) throws FactException {
+        return insert( EntryPoint.DEFAULT,
+        			   object,
+                       0,
+                       false,
+                       true,
+                       null,
+                       null,
+                       priors);
+    }
+    
+    
+    
+    
 
     public FactHandle insert(final Object object,
                              final long duration) throws FactException {
@@ -725,6 +758,25 @@
                             rule,
                             activation );
     }
+    
+    
+    public FactHandle insertLogical(Object object,
+			long duration,
+			boolean dynamic, Rule rule, Activation activation,
+			Hashtable<Constraint, IUncertainDegree> logicalPremises)
+			throws FactException {
+    	
+    	return this.insert( EntryPoint.DEFAULT,
+                object,
+                0,
+                dynamic,
+                true,
+                rule,
+                activation,
+                logicalPremises);
+		
+	}
+    
 
     protected FactHandle insert(final EntryPoint entryPoint,
                                 final Object object,
@@ -732,10 +784,8 @@
                                 final boolean dynamic,
                                 boolean logical,
                                 final Rule rule,
-                                final Activation activation) throws FactException {
+                                final Activation activation) throws FactException {               
         
-        System.out.println("AbstractWorkingMemory :  State / Justify Ordeal");
-        
         if ( object == null ) {
             // you cannot assert a null object
             return null;
@@ -945,12 +995,9 @@
                                                                                   activation,
                                                                                   this.agenda.getActiveActivations(),
                                                                                   this.agenda.getDormantActivations(),
-                                                                                  entryPoint );
-            System.out.println("AbstractWorkingMemory : Wrapped a to-be-inserted obj with a handle");
-            System.out.println("AbstractWorkingMemory : Hijacked insert method to use uncValues");
+                                                                                  entryPoint );           
         doInsert( handle,
-                  object,
-                  new Degree(1),
+                  object,                  
                   propagationContext );
 
         if ( !this.actionQueue.isEmpty() ) {
@@ -963,6 +1010,9 @@
                                                            this );
     }
 
+    
+    
+    
     protected void addPropertyChangeListener(final Object object) {
         try {
             final Method method = object.getClass().getMethod( "addPropertyChangeListener",
@@ -992,8 +1042,9 @@
     
     public abstract void doInsert(InternalFactHandle factHandle,
             Object object, 
-            IUncertainDegree tDegree,
+            Hashtable<Constraint, IUncertainDegree> premises,
             PropagationContext propagationContext) throws FactException;
+    
 
     protected void removePropertyChangeListener(final FactHandle handle) {
         Object object = null;
@@ -1782,4 +1833,305 @@
 
     }
 
+    
+    
+
+
+    protected FactHandle insert(final EntryPoint entryPoint,
+    		final Object object,
+    		final long duration,
+    		final boolean dynamic,
+    		boolean logical,
+    		final Rule rule,
+    		final Activation activation,
+    		Hashtable<Constraint, IUncertainDegree> priors) throws FactException {
+
+    	System.out.println("AbstractWorkingMemory : Uncertain  State / Justify Ordeal");
+
+    	if ( object == null ) {
+//  		you cannot assert a null object
+    		return null;
+    	}
+
+    	ObjectTypeConf typeConf = getObjectTypeConf( entryPoint,
+    			object );
+
+    	InternalFactHandle handle = null;
+
+    	//TODO : Not really supported yet...
+    	if ( isSequential() ) {
+    		System.out.println("AWM :Sequential mode, buggy. TODO");
+    		handle = this.handleFactory.newUncFactHandle( object,
+    				priors,
+    				typeConf.isEvent(),
+    				duration,
+    				this );
+    		this.objectStore.addHandle( handle, object );
+    		insert( entryPoint,
+    				handle,
+    				object,
+    				rule,
+    				activation );
+    		return handle;
+    	}
+
+    	
+    	if ( dynamic ) {
+			addPropertyChangeListener( object );
+		}
+    	
+    	
+    	
+    	// The most sensible thing is to start from scratch again...    	   
+
+    	try {
+    		this.lock.lock();
+    			// check for IDENTITY
+    		handle = (InternalFactHandle) this.objectStore.getHandleForObject(object);
+    		
+    		
+    		if ( this.maintainTms ) {
+
+    			EqualityKey key; 
+
+    			if ( handle != null ) {
+    				// There is an ID object in memory
+    				key = handle.getEqualityKey();
+
+    				if ( !logical ) {
+    					// This is a STATE. Regardless of the prev state, priors are reset and object
+    					// is restated.
+    					if (key.getStatus() == EqualityKey.JUSTIFIED)
+    						this.tms.removeLogicalDependencies( handle );
+    					
+    					key.setStatus( EqualityKey.STATED );   
+    					//Restate with true overrides following evaluations.
+    					//Starting again from zero, evaluators must contribute 
+    					System.out.println("AWM : State existing-by-ID statement, which is overridden");
+    					return this.reAssert(entryPoint, handle, rule, activation, priors, false, false);    					
+    					
+    				} else {
+    					// This is a JUSTIFY.     					
+    					if  (key.getStatus() == EqualityKey.STATED) {
+    						//If the object is stated, the justification is ignored
+    						System.out.println("AWM : Justify existing-by-ID statement, ignored");
+    						return handle;
+    					} else {
+    						//TODO: Priors should enter the dependency, so to be undone
+    						if (activation != null) {
+    							this.tms.addLogicalDependency( handle,
+    									activation,
+    									activation.getPropagationContext(),
+    									rule );
+    						}
+    						//Restate with false merges info...
+    						// Evaluators contrib already in, so they must be inhibited
+    						System.out.println("AWM : Justify existing-by-ID justify, merge but not reeval");
+    						return this.reAssert(entryPoint, handle, rule, activation, priors, true, true);
+    					}
+    				}
+    				
+    			} else {
+    				// Ok, no ID object in memory.
+    				// Maybe there is an EQUAL object:
+    				key = this.tms.get(object);
+    				if (key != null) {
+    					//Yes, there is an EQ object
+    					
+    					if (logical) {
+    						
+    						// Justify an EQUAL obj    						
+    						if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
+        						//TODO : again, deps should include priors
+        						this.tms.addLogicalDependency( key.getFactHandle(),
+        								activation,
+        								activation.getPropagationContext(),
+        								rule );
+        						//Merge new info, but inhibit evaluators
+        						System.out.println("AWM : Justify existing-by-EQ justify, merge but not reeval");
+        						return reAssert(entryPoint, key.getFactHandle(), rule, activation, priors,true,true);
+        						//return key.getFactHandle();
+        					} else {
+        						// Can't justify a stated obj, do nothing
+        						System.out.println("AWM : Justify existing-by-EQ statement, do nothing");
+        						return key.getFactHandle();
+        					}
+    						
+    					} else {
+    						
+    						//STATE about an EQUAL obj
+    						
+    						if ( key.getStatus() == EqualityKey.STATED ) {
+    							// The obj was already stated, so reset that other object.
+    							// THIS IS A DIFFERENCE WITH THE USUAL SEMANTICS 
+    							System.out.println("AWM : State existing-by-EQ statement, override with values and new eval");
+    							return reAssert(entryPoint, key.getFactHandle(), rule, activation, priors,false,false);
+    						} else {
+    							// Stating an existing equal obj, which is only justified.
+    							// Update that object. 
+    							this.tms.removeLogicalDependencies( key.getFactHandle() );
+    	    					
+    	    					key.setStatus( EqualityKey.STATED );   
+    	    					//Restate with true overrides following evaluations.
+    	    					//Starting again from zero, evaluators must contribute 
+    	    					System.out.println("AWM : State existing-by-EQ justify, cleanup and override");
+    	    					return this.reAssert(entryPoint, key.getFactHandle(), rule, activation, priors, false, false);  
+    						}
+    					
+    						
+    					}
+    					
+    					    					
+    				} else {
+    					// Not even an EQ, this is the first time an object enters the mem
+    					//Alpha-evaluators must not be inhibited
+    					handle = this.handleFactory.newUncFactHandle( object,
+    							null,
+        						typeConf.isEvent(),
+        						duration,
+        						this );
+        				this.objectStore.addHandle( handle, object );
+
+        				key = new EqualityKey( handle );
+        				handle.setEqualityKey( key );
+        				this.tms.put( key );
+        				if ( !logical ) {
+        					key.setStatus( EqualityKey.STATED );
+        					System.out.println("AWM : Brand new statement, eval everything");
+        					return reAssert(entryPoint, handle, rule, activation, priors,false,false);
+        				} else {
+        					key.setStatus( EqualityKey.JUSTIFIED );
+        					if (activation != null && rule != null)
+        							this.tms.addLogicalDependency( handle,
+        							activation,
+        							activation.getPropagationContext(),
+        							rule );
+        					System.out.println("AWM : Brand new justification, eval everything");
+        					return reAssert(entryPoint, handle, rule, activation ,priors,false,false);
+        				}
+    					
+    				}
+    			}
+    			
+    			
+    			
+    		} else {
+    			
+    			// OK, here no TMS:
+    			// Logical insertions are ignored, statement exists already.
+    			if (logical) {
+    				System.out.println("AWM : No TMS, logical insertion ignored");
+    				return null;
+    			}
+    			
+    			if ( handle != null ) {
+    				// Object exists, priors are updated just later
+    				//TODO: Check: Obj should be retracted before being inserted again??
+    				System.out.println("AWM : No TMS, stated existing object, nothing done");
+    				return handle;
+    			} else {
+    			// No object exists, so we just create. Priors will be set just later
+    				handle = this.handleFactory.newUncFactHandle( object,
+    					null,		//priors
+    					typeConf.isEvent(),
+    					duration,
+    					this );
+    				this.objectStore.addHandle( handle, object );
+    				//Nothing to merge with, let the evaluators play
+    				System.out.println("AWM : No TMS, new insertion is evaluated");
+    				return reAssert(entryPoint, handle, rule, activation,priors,false,false);
+    			}
+
+    		}    		    		    		    	
+    	
+//    		
+//    		((UncInternalFactHandle) handle).addPriors(priors);
+//    		
+//		   		insert( entryPoint,
+//    				handle,
+//    				object,
+//    				rule,
+//    				activation,
+//    				priors);
+//    		
+
+    	} finally {
+    		this.lock.unlock();
+    	}
+    	
+    	
+    }  
+    
+    
+    
+    protected InternalFactHandle reAssert(
+    		EntryPoint entryPoint,
+    		InternalFactHandle handle, 
+    		Rule rule,
+    		Activation activation,
+    		Hashtable<Constraint, IUncertainDegree> priors, 
+    		boolean mergeWithExisting, boolean inhibitEvaluators) {
+    	
+    	    UncInternalFactHandle uHandle = (UncInternalFactHandle) handle;
+    	    if (mergeWithExisting) 
+    	    	uHandle.mergePriors(priors, this.getRuleBase().getTruthFactory());
+    	    else 
+    	    	uHandle.setPriors(priors);
+    	    
+    	    
+    	    uHandle.setOverruling(inhibitEvaluators);
+    	    
+	   		insertUnc( entryPoint,
+				handle,
+				handle.getObject(),
+				rule,
+				activation
+				);
+	   		
+    	return handle;
+    }
+    
+    
+
+    protected void insertUnc(final EntryPoint entryPoint,
+    		final InternalFactHandle handle,
+    		final Object object,
+    		final Rule rule,
+    		final Activation activation
+    		//final Hashtable<String, IUncertainDegree> priors
+    		) {
+    	this.ruleBase.executeQueuedActions();
+
+    	if ( activation != null ) {
+//  		release resources so that they can be GC'ed
+    		activation.getPropagationContext().releaseResources();
+    	}
+    	final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
+    			PropagationContext.ASSERTION,
+    			rule,
+    			activation,
+    			this.agenda.getActiveActivations(),
+    			this.agenda.getDormantActivations(),
+    			entryPoint );
+    	
+    	System.out.println("AbstractWorkingMemory : Wrapped a to-be-inserted obj with a handle");
+    	System.out.println("AbstractWorkingMemory : New insert method uses uncValues");
+    	doInsert( handle,
+    			object,           
+    			((UncInternalFactHandle) handle).getPriors(),
+    			propagationContext    			
+    			);
+
+    	if ( !this.actionQueue.isEmpty() ) {
+    		executeQueuedActions();
+    	}
+
+    	this.workingMemoryEventSupport.fireObjectInserted( propagationContext,
+    			handle,
+    			object,
+    			this );
+    }
+    
+    
+    
 }

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -16,8 +16,12 @@
  * limitations under the License.
  */
 
+import java.util.Hashtable;
+
 import org.drools.FactHandle;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 /**
  * Implementation of <code>FactHandle</code>.
  * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
@@ -41,6 +45,8 @@
     private EqualityKey       key;
     private int               objectHashCode;
     private boolean           shadowFact;
+    
+    
 
     // ----------------------------------------------------------------------
     // Constructors
@@ -170,4 +176,8 @@
     public boolean isEvent() {
         return false;
     }
+
+    
+
+	
 }

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/EqualityKey.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/EqualityKey.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/EqualityKey.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -53,7 +53,7 @@
         this.handle = handle;
         this.hashCode = handle.getObjectHashCode();
     }
-
+  
     public EqualityKey(final InternalFactHandle handle,
                        final int status) {
         this.handle = handle;

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/InternalFactHandle.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/InternalFactHandle.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -16,8 +16,12 @@
  * limitations under the License.
  */
 
+import java.util.Hashtable;
+
 import org.drools.FactHandle;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 public interface InternalFactHandle
     extends
     FactHandle {
@@ -43,6 +47,8 @@
 
     public void setShadowFact(boolean shadowFact);
     
+    
+    
     /**
      * Returns true if this FactHandle represents
      * and Event or false if this FactHandle represents

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -16,11 +16,17 @@
  * limitations under the License.
  */
 
+import java.util.Hashtable;
+
 import org.drools.FactException;
 import org.drools.FactHandle;
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
+import org.drools.spi.Constraint;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 public interface InternalWorkingMemoryActions
     extends
     InternalWorkingMemory {
@@ -47,6 +53,16 @@
             boolean logical,
             Rule rule,
             Activation activation) throws FactException;
+    
+    
+    FactHandle insertLogical(Object object,    		
+    		long duration,
+            boolean dynamic,            
+            Rule rule,
+            Activation activation,
+            Hashtable<Constraint, IUncertainDegree> logicalPremises) throws FactException;
+    
+    
 
     /*public FactHandle insertLogical(Object object,
                                     boolean dynamic) throws FactException;*/

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -66,7 +66,7 @@
 
     public ObjectHashMap getAssertMap() {
         return this.assertMap;
-    }
+    } 
 
     public Object put(final EqualityKey key) {
         return this.assertMap.put( key,

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/facttemplates/FactTemplateObjectType.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/facttemplates/FactTemplateObjectType.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/facttemplates/FactTemplateObjectType.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -19,6 +19,7 @@
 import org.drools.base.ValueType;
 import org.drools.spi.ObjectType;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
 
@@ -156,8 +157,8 @@
      * TODO: Compatibility between fact templates is to be considered...
      * @author Sotty
      */
-    public IUncertainDegree isCompatibleWith(Object object) {
-        boolean ans = this.isAssignableFrom(object);
-        return ans ? new Degree(1) : new Degree(0);
+    public IUncertainDegree isCompatibleWith(Object object, IDegreeFactory factory) {
+        
+        return factory.fromBoolean(isAssignableFrom(object));
     }
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -29,8 +29,10 @@
 import org.drools.util.FactHashTable;
 import org.drools.util.Iterator;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.IUncDegCombiner;
 
 /**
  * <code>AlphaNodes</code> are nodes in the <code>Rete</code> network used
@@ -142,7 +144,7 @@
         
         IUncertainDegree constrDeg = this.constraint.matches(handle, workingMemory);
         
-        IUncertainDegree ansDeg = AlphaNode.combineDegs(tDegree,constrDeg);  
+        IUncertainDegree ansDeg = AlphaNode.combineDegs(tDegree,constrDeg, workingMemory.getRuleBase().getTruthFactory());  
             
             System.out.println("UNCERTAIN AlphaNode : Passed object "+handle.getObject()+ " with degree "+ansDeg);
             if ( isObjectMemoryEnabled() ) {
@@ -169,8 +171,9 @@
      * @return              degree*constrDeg (product and over real valued degrees)  
      */
     public static IUncertainDegree combineDegs(final IUncertainDegree degree,
-            final IUncertainDegree constrDeg) {
-        return new Degree(constrDeg.getDegree().getValue()*degree.getDegree().getValue());
+            final IUncertainDegree constrDeg, IDegreeFactory factory) {
+    	IUncDegCombiner aggregator = factory.getAndOperator();
+    	return aggregator.eval(new IUncertainDegree[] {degree,constrDeg});        
     }
 
     public void assertObject(final InternalFactHandle handle,
@@ -384,7 +387,7 @@
             //TODO: pluggable evaluators here...
             constrDeg = this.constraint.matches(handle, workingMemory);
             
-            IUncertainDegree ansDeg = AlphaNode.combineDegs(tDegree,constrDeg);  
+            IUncertainDegree ansDeg = AlphaNode.combineDegs(tDegree,constrDeg,workingMemory.getRuleBase().getTruthFactory());  
                     this.sink.assertObject( handle,
                         ansDeg,
                         context,

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -24,7 +24,10 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.NodeMemory;
 import org.drools.common.PropagationContextImpl;
+import org.drools.common.UncFactHandle;
+import org.drools.common.UncInternalFactHandle;
 import org.drools.reteoo.builder.BuildContext;
+import org.drools.rule.ClassConstraint;
 import org.drools.rule.Declaration;
 import org.drools.rule.EntryPoint;
 import org.drools.spi.Constraint;
@@ -34,6 +37,7 @@
 import org.drools.util.FactHashTable;
 import org.drools.util.Iterator;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
 
@@ -132,8 +136,8 @@
      * @param object    The actual object whose class is to be evaluated
      * @return
      */
-    public IUncertainDegree isCompatibleWith(final Object object) {
-        return this.objectType.isCompatibleWith(object);
+    public IUncertainDegree isCompatibleWith(final Object object, IDegreeFactory factory) {
+        return this.objectType.isCompatibleWith(object, factory);
     }
     
     
@@ -178,10 +182,33 @@
                         false );
         }
         
-        IUncertainDegree tMatch = isCompatibleWith(handle.getObject());
-
+        UncInternalFactHandle uncHandle = (UncInternalFactHandle) handle;
+        	if (uncHandle == null) throw new RuntimeException("Uncertain Information expected here!!");
+        	
+        	Object object = uncHandle.getObject();
+        	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory(); 
+        	
+        	Constraint constr = new ClassConstraint(uncHandle.getObject().getClass());
+    
+    	IUncertainDegree prior = uncHandle.getPriors().get(constr);
+    	IUncertainDegree posterior = null;
+    	
+    	if (prior == null) {
+    		posterior = isCompatibleWith(handle.getObject(), factory);
+    	} else {
+    		if (! uncHandle.isOverruling()) {
+          		posterior = prior;
+          	} else {
+          		posterior = merge(prior, isCompatibleWith(handle.getObject(), factory), factory);
+          	}    		
+    	}
+    	
+    	uncHandle.setPrior(constr, posterior);
+    		    		    	    	    	    	    
+    	System.out.println("ReteOOWM: ClassMatch for "+object.getClass().getName() + " is "+posterior);
+      	      	      	      	
         this.sink.propagateAssertObject( handle,
-                                         ObjectTypeNode.combineDegrees(tDegree,tMatch),
+                                         this.combine(tDegree, posterior, factory),
                                          context,
                                          workingMemory );
     }
@@ -435,8 +462,11 @@
      * @param matchDeg     The degree up to which the object satisfies the node's constraint
      * @return              degree*constrDeg (product and over real valued degrees)  
      */
-    public static IUncertainDegree combineDegrees(final IUncertainDegree degree,
-            final IUncertainDegree matchDeg) {
-        return new Degree(matchDeg.getDegree().getValue()*degree.getDegree().getValue());
+    protected IUncertainDegree combine(final IUncertainDegree d1, final IUncertainDegree d2, IDegreeFactory factory) {
+    	return factory.getAndOperator().eval(new IUncertainDegree[] {d1,d2});
     }
-}
+    
+    protected IUncertainDegree merge(final IUncertainDegree d1, final IUncertainDegree d2, IDegreeFactory factory) {
+    	return factory.getAggregator().eval(new IUncertainDegree[] {d1,d2});
+    }
+    }

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -16,15 +16,23 @@
  * limitations under the License.
  */
 
+import java.util.Hashtable;
+
 import org.drools.TemporalSession;
 import org.drools.WorkingMemory;
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
 import org.drools.common.AbstractFactHandleFactory;
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.EventFactHandle;
 import org.drools.common.InternalFactHandle;
+import org.drools.common.UncFactHandle;
+import org.drools.common.UncInternalFactHandle;
+import org.drools.spi.Constraint;
 import org.drools.spi.FactHandleFactory;
 import org.drools.temporal.SessionClock;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 public class ReteooFactHandleFactory extends AbstractFactHandleFactory {
 
     private static final long serialVersionUID = 400L;
@@ -73,6 +81,20 @@
                                           recency );
         }
     }
+    
+    
+    
+    @Override
+    //TODO: No support for expiring UncFacts
+	protected UncFactHandle newUncFactHandle(long id, Object object,
+			Hashtable<Constraint, IUncertainDegree> priors, long recency,
+			boolean isEvent, long duration, WorkingMemory workingMemory) {
+    	
+    	return new UncFactHandle(id,object,recency,priors);
+    	
+	}
+    
+    
 
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#newInstance()
@@ -84,4 +106,8 @@
     public Class getFactHandleType() {
         return DefaultFactHandle.class;
     }
+
+	
+
+	
 }

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -22,6 +22,8 @@
 import java.io.Serializable;
 import java.util.Iterator;
 
+import javax.swing.text.SimpleAttributeSet;
+
 import org.drools.ClockType;
 import org.drools.FactException;
 import org.drools.FactHandle;
@@ -47,6 +49,8 @@
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.PropagationContext;
 
+import uncertainty.factory.IDegreeFactory;
+import uncertainty.factory.SimpleDegreeFactory;
 import uncertainty.truthvals.IUncertainDegree;
 
 /**
@@ -68,6 +72,31 @@
     private transient Rete    rete;
 
     private ReteooBuilder     reteooBuilder;
+    
+    
+    private static IDegreeFactory truthFactory = null;
+    
+    
+    public static IDegreeFactory truthFactory() {
+    	// TODO Dynamically decide which factory has to be instantiated
+		if (ReteooRuleBase.truthFactory == null)
+			ReteooRuleBase.truthFactory = new SimpleDegreeFactory();
+		return ReteooRuleBase.truthFactory;
+    }
+    
+    public IDegreeFactory getTruthFactory() {
+		return ReteooRuleBase.truthFactory();
+	}
+    
+    /**
+     * TODO : better not to mess like this...
+     * @deprecated
+     */   
+    public void setTruthFactory(IDegreeFactory factory) {
+    	ReteooRuleBase.truthFactory = factory;
+    }
+    
+    
 
     // ------------------------------------------------------------
     // Constructors
@@ -338,4 +367,11 @@
         private static final long serialVersionUID = 400L;
     }
 
+    
+    
+    
+    
+    
+	
+
 }

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -18,26 +18,32 @@
 
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.List;
 
 import org.drools.FactException;
 import org.drools.FactHandle;
 import org.drools.QueryResults;
 import org.drools.base.DroolsQuery;
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
 import org.drools.common.AbstractWorkingMemory;
 import org.drools.common.DefaultAgenda;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalRuleBase;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.PropagationContextImpl;
+import org.drools.common.UncInternalFactHandle;
 import org.drools.common.WorkingMemoryAction;
 import org.drools.event.RuleBaseEventListener;
+import org.drools.rule.ClassConstraint;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.Query;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
+import org.drools.spi.Constraint;
 import org.drools.spi.PropagationContext;
 
+import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
 
 /**
@@ -71,24 +77,46 @@
     public void doInsert(final InternalFactHandle handle,
                                final Object object,
                                final PropagationContext propagationContext) throws FactException {
-        
-        this.ruleBase.assertObject( handle,
-                                    object,
-                                    propagationContext,
-                                    this );
+            	    		   
+    		this.ruleBase.assertObject( handle,
+    				object,
+    				propagationContext,
+    				this );
+    	
     }
     
+    
+    
     public void doInsert(final InternalFactHandle handle,
             final Object object,
-            IUncertainDegree tDegree,
+            Hashtable<Constraint,IUncertainDegree> premises,
             final PropagationContext propagationContext) throws FactException {
 
+    	
+    	UncInternalFactHandle uncHandle = (UncInternalFactHandle) handle;
+    	
+    	    	    	    	    
+//    	// TODO : This seeds the uncertain path. maybe too early...
+//    	IUncertainDegree deg = uncHandle.getPriors().get(new ClassConstraint(object.getClass()));
+//    	if (deg == null)     	
+//    		deg = getRuleBase().getTruthFactory().True();
+//    	
+//    	    	    	
+//    	System.out.println("ReteOOWM: ClassMatch for "+object.getClass().getName() + " is "+deg);
+    		
         this.ruleBase.assertObject( handle,
                 object,
-                tDegree,
+                this.getRuleBase().getTruthFactory().True(),
                 propagationContext,
                 this );
     }
+    
+    
+    
+    
+    
+    
+    
 
     public void doRetract(final InternalFactHandle handle,
                           final PropagationContext propagationContext) {
@@ -203,4 +231,6 @@
         }
     }
 
+	
+
 }

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -17,6 +17,7 @@
  */
 
 import java.io.Serializable;
+import java.util.Vector;
 
 import org.drools.common.EventSupport;
 import org.drools.RuleBaseConfiguration;
@@ -45,8 +46,11 @@
 import org.drools.util.LinkedList;
 import org.drools.util.TupleHashTable;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.IUncDegCombiner;
+import uncertainty.truthvals.operators.ModusPonensOp;
 
 /**
  * Leaf Rete-OO node responsible for enacting <code>Action</code> s on a
@@ -84,6 +88,8 @@
     private TupleSinkNode      nextTupleSinkNode;
 
     protected boolean          tupleMemoryEnabled;
+    
+    private IUncertainDegree 	implication;
 
     // ------------------------------------------------------------
     // Constructors
@@ -107,6 +113,8 @@
         this.tupleSource = source;
         this.subrule = subrule;
         this.tupleMemoryEnabled = buildContext.isTerminalNodeMemoryEnabled();
+        	IDegreeFactory factory = buildContext.getRuleBase().getTruthFactory(); 
+        this.implication = factory.True();
     }
 
     // ------------------------------------------------------------
@@ -129,7 +137,15 @@
     public int getSequence() {
         return this.sequence;
     }
+    
+    
+    private IUncertainDegree getImplication() {		
+		return this.implication;
+	}
 
+    
+    
+
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     // org.drools.impl.TupleSink
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -164,10 +180,13 @@
             return;
         }
 
-        IUncertainDegree ansDeg = evaluateOperator(tuple);
+        IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
+        IUncertainDegree premiseDeg = evaluateOperator(tuple, factory);
         
-        System.out.println("RuleTerminalNode for " +this.rule + " : Received joined tuple "+tuple+ " with degree "+ansDeg);
+        IUncertainDegree conclDeg = applyInference(premiseDeg, getImplication() ,factory); 
         
+        System.out.println("RuleTerminalNode for " +this.rule + " : Received joined tuple "+tuple+ " with degree "+conclDeg);
+        
         // if the current Rule is no-loop and the origin rule is the same and its the same set of facts (tuple) then return
         if ( context.getType() == PropagationContext.MODIFICATION ) {
             if ( this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() ) && context.getActivationOrigin().getTuple().equals( tuple ) ) {
@@ -341,13 +360,20 @@
         }
 
         //TODO: Here the premise's truth value should have been calculated
-        System.out.println("RuleTerminalNode: A rule has been fired and added to the agenda\n\n");
+        System.out.println("RuleTerminalNode: A rule has been fired and added to the agenda");
+        System.out.println("Output degree is "+ conclDeg.toString()+ "\n\n\n");
         agenda.increaseActiveActivations();
     }
 
     
 
-    private void copyLogicalDependencies(final PropagationContext context,
+
+	
+
+	
+	
+	
+	private void copyLogicalDependencies(final PropagationContext context,
                                          final InternalWorkingMemory workingMemory,
                                          final AgendaItem item,
                                          Activation justifier) {
@@ -545,26 +571,43 @@
     
     
     
-    
-    private IUncertainDegree evaluateOperator(ReteTuple tuple) {
-        Degree ans = new Degree(1);
+    //TODO : Terminal Node should know its operator and act accordingly
+    private IUncertainDegree evaluateOperator(ReteTuple tuple, IDegreeFactory factory) {
+    	    	
+    	
         
+    	Vector<IUncertainDegree> degs = new Vector<IUncertainDegree>(5);
+    	IUncDegCombiner operator = factory.getAndOperator();    	    	    	
+        
+    	int arity = 0;
         ReteTuple tup = tuple;
         while (tup != null) {
             if (tup instanceof UncReteTuple) {
                 UncReteTuple ut = (UncReteTuple) tup;
-                Degree deg = (Degree) ut.getDegree();
-                ans.setValue(ans.getValue()*deg.getValue());
+                degs.add(ut.getDegree());
+                arity++;
             }
             tup = tup.getParent();
         }
         
-        return ans;
+        if (arity == 0) return factory.True();        
+        if (arity == 1) return degs.get(0);
+        
+        return operator.eval(degs.toArray(new IUncertainDegree[arity]));
+        
     }
     
     
+    //TODO : implic should be set in some way...
+    //TODO : and so the type of rule...
+    private IUncertainDegree applyInference(IUncertainDegree premiseDeg,
+			IUncertainDegree implic, IDegreeFactory factory) {
+		return factory.getModusPonensOp().eval(new IUncertainDegree[] {premiseDeg, implic});
+	}
     
     
+    
+    
 
     class TerminalNodeMemory
         implements

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/AndConstraint.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/AndConstraint.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/AndConstraint.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -26,8 +26,10 @@
 import org.drools.spi.BetaNodeFieldConstraint;
 import org.drools.util.ArrayUtils;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.IUncDegCombiner;
 
 /**
  * AND composite constraint, so the user can do things like:
@@ -135,13 +137,20 @@
 
     public IUncertainDegree matches(InternalFactHandle handle,
             InternalWorkingMemory workingMemory) {
-        double eps = 1;
-        if ( this.alphaConstraints.length > 0 ) {
-            for ( int i = 0; i < this.alphaConstraints.length; i++ ) {
-                eps *= ((Degree) this.alphaConstraints[i].matches(handle, workingMemory)).getValue();                
+    	
+    	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
+    	
+    	if (this.alphaConstraints.length > 0) {
+    		IUncertainDegree[] degs = new IUncertainDegree[this.alphaConstraints.length];
+    		for ( int i = 0; i < this.alphaConstraints.length; i++ ) {
+                degs[i] = this.alphaConstraints[i].matches(handle, workingMemory);                
             }
-        }
-        return new Degree(eps);
+    		
+    		IUncDegCombiner and = factory.getAndOperator();
+    		return and.eval(degs);
+    	} else return factory.True();
+    	
+    	
     }
     
 

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -16,13 +16,26 @@
  * limitations under the License.
  */
 
+import java.util.Hashtable;
+
+import org.drools.base.ClassFieldExtractor;
+import org.drools.base.ValueType;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
+import org.drools.base.evaluators.Operator;
+import org.drools.base.field.ObjectFieldImpl;
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.common.UncInternalFactHandle;
 import org.drools.spi.AlphaNodeFieldConstraint;
+import org.drools.spi.Constraint;
 import org.drools.spi.Evaluator;
 import org.drools.spi.FieldExtractor;
 import org.drools.spi.FieldValue;
 
+import uncertainty.factory.IDegreeFactory;
+import uncertainty.measures.IDegreeEvalFunction;
+import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
 
 public class LiteralConstraint
@@ -37,6 +50,25 @@
     private final FieldExtractor     extractor;
 
     private final LiteralRestriction restriction;
+    
+    
+    
+    /**
+     * Shortcut implementation to: 
+     * 	Type Obj.FieldName Op FieldValue
+     * 
+     * @param obj
+     * @param fieldName
+     * @param type
+     * @param op
+     * @param fieldValue
+     * @return
+     */
+    public static LiteralConstraint buildDefault(Object obj, String fieldName, ValueType type, Operator op, Object fieldValue) {
+    	return new LiteralConstraint(new ClassFieldExtractor(obj.getClass(),fieldName),
+				 new EqualityEvaluatorsDefinition().getEvaluator(type,op),
+				 new ObjectFieldImpl(fieldValue));  
+    }
 
     public LiteralConstraint(final FieldExtractor extractor,
                              final Evaluator evaluator,
@@ -53,6 +85,10 @@
         this.restriction = restriction;
     }
 
+    public LiteralConstraint getGeneralizedLiteralConstraint() {
+    	return new LiteralConstraint(this.extractor, this.restriction.getGeneralizedRestriction());
+    }
+    
     public Evaluator getEvaluator() {
         return this.restriction.getEvaluator();
     }
@@ -96,6 +132,8 @@
         int result = 1;
         result = PRIME * result + this.extractor.hashCode();
         result = PRIME * result + this.restriction.hashCode();
+//        	System.out.println("Ext hc : " + this.extractor.hashCode());
+//        	System.out.println("Rest hc : " + this.restriction.hashCode());
         return result;
     }
 
@@ -117,10 +155,88 @@
                                       this.getField() );
     }
 
+    
+    /**
+     * Method applies uncertain evaluation of the predicate Constr(Obj.Field)
+     * 
+     * An a priori value may be passed with the handle. In this case, this value is returned and the
+     * actual evaluator is ignored. If no prior is present, the evaluator is applied.
+     * 
+     * TODO: This behaviour should be overridden. The 
+     */
     public IUncertainDegree matches(InternalFactHandle handle,
             InternalWorkingMemory workingMemory) {
-        return this.restriction.matches( this.extractor,
-                handle,
-                workingMemory );
+    	
+    	
+    	System.out.println("LiteralConstraint :: Trying to evaluate an Alpha-Constraint over Object ..."+handle.getObject().toString());
+    	System.out.println("Using extractor of type "+this.extractor.getClass());
+    	ClassFieldExtractor fldEx = (ClassFieldExtractor) this.extractor;
+    	System.out.println("Going for "+fldEx.getFieldName());
+    	System.out.println("The value to be matched against is "+this.restriction.getField());    	
+    	
+    	
+    	
+    	Hashtable<Constraint, IUncertainDegree> priors = ((UncInternalFactHandle) handle).getPriors();
+    	UncInternalFactHandle uHandle = (UncInternalFactHandle) handle;
+    	
+    	LiteralConstraint key = null;    	
+    	if (priors != null && priors.containsKey(this)) { 
+    		key = this;
+    	} else {
+    		LiteralConstraint unbound = this.getGeneralizedLiteralConstraint(); 
+    		if (priors != null && priors.containsKey(unbound))
+    		key = unbound;
+    	}
+    		
+    	
+    	
+    	if (key != null) {
+    		// the field has already been evaluated
+    		IUncertainDegree prior = priors.get(key);
+    		if (uHandle.isOverruling()) {
+    			//the local evaluator is to be overruled. Maybe it has been applied earlier.
+    			return prior;
+    		} else {    			
+    			// Eval the operator, maybe merge with the available prior
+    			IUncertainDegree posterior = this.restriction.matches( this.extractor, handle, workingMemory );
+    			IUncertainDegree newPrior =  merge(prior, posterior, workingMemory.getRuleBase().getTruthFactory());
+    				uHandle.setPrior(this,newPrior);
+    			return newPrior;
+    		}
+    		
+    	} else {
+    		// no, the field has not
+    		// it now becomes the actual prior
+    		IUncertainDegree newPrior = this.restriction.matches( this.extractor, handle, workingMemory );
+    			uHandle.setPrior(this,newPrior);
+    		return newPrior;
+    	}
+    	    	     
+    	
+    	
+    	
+    	
     }
+    
+    
+    /**
+     * Merge function
+     * Provided priors, even when logical consequences, are merged with the evaluated ones.
+     * This method should wrap a sensible strategy (see DS combination...), for now it implements the max merge operator.
+     * TODO: Modify this method stub 
+     *  
+     * @param prior
+     * @param post
+     * @return
+     */
+    private IUncertainDegree merge(IUncertainDegree prior, IUncertainDegree post, IDegreeFactory factory) {
+    	if (prior == null) return post;
+    	if (post == null) return prior;
+    	IUncertainDegree ans = factory.getAggregator().eval(new IUncertainDegree[] {prior, post});
+    	return ans;
+    	    		    
+    }
+    
+    
+    
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import org.drools.base.field.ObjectFieldImpl;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.ReteTuple;
@@ -33,7 +34,7 @@
 
     private static final long          serialVersionUID     = 400L;
 
-    private final FieldValue           field;
+    private final FieldValue      	   field;
 
     private final Evaluator            evaluator;
 
@@ -48,6 +49,11 @@
         this.evaluator = evaluator;
         this.contextEntry = new LiteralContextEntry( fieldExtractor );
     }
+    
+    
+    public LiteralRestriction getGeneralizedRestriction() {
+    	return new LiteralRestriction(new ObjectFieldImpl(null),this.evaluator, this.contextEntry.extractor);
+    }
 
     public Evaluator getEvaluator() {
         return this.evaluator;
@@ -56,6 +62,8 @@
     public FieldValue getField() {
         return this.field;
     }
+    
+   
 
     public boolean isAllowed(final Extractor extractor,
                              final InternalFactHandle handle,
@@ -99,10 +107,16 @@
         return "[LiteralRestriction evaluator=" + this.evaluator + " value=" + this.field + "]";
     }
 
+    
+    /**
+     * TODO : REMOVE THIS MODIFICATION 
+     * Important computation modification
+     * Null fieldValues must match with any other
+     */
     public int hashCode() {
         final int PRIME = 31;
         int result = 1;
-        result = PRIME * result + this.evaluator.hashCode();
+        result = PRIME * result + this.evaluator.hashCode();                
         result = PRIME * result + ((this.field.getValue() != null) ? this.field.getValue().hashCode() : 0);
         return result;
     }
@@ -116,7 +130,12 @@
         }
         final LiteralRestriction other = (LiteralRestriction) object;
 
-        return this.field.equals( other.field ) && this.evaluator.equals( other.evaluator );
+        
+        //System.out.println("Testing equality between fieldvals : "+this.field.getValue()+ " and "+ other.field.getValue());
+        boolean eqField = this.field.getValue() == null || other.field.getValue() == null ||  this.field.equals( other.field ); 
+        boolean eqEval = this.evaluator.equals( other.evaluator );
+        
+        return eqField && eqEval;
     }
 
     public ContextEntry getContextEntry() {
@@ -124,7 +143,7 @@
     }
 
     public Object clone() {
-        return new LiteralRestriction( this.field,
+        return new LiteralRestriction( this.field,// nothing to do
                                        this.evaluator,
                                        this.contextEntry.extractor );
     }
@@ -179,7 +198,10 @@
 
     public IUncertainDegree matches(FieldExtractor extractor,
             InternalFactHandle handle, InternalWorkingMemory workingMemory) {
-        return this.evaluator.evaluateUnc( null,
+    	
+    	
+    	
+        return this.evaluator.evaluateUnc( workingMemory,
                 extractor,
                 handle.getObject(),
                 this.field );

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/OrConstraint.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/OrConstraint.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/rule/OrConstraint.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -25,8 +25,10 @@
 import org.drools.spi.BetaNodeFieldConstraint;
 import org.drools.util.ArrayUtils;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.Degree;
 import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.IUncDegCombiner;
 
 /**
  * A class to implement Multi-Field OR constraints, so user can do:
@@ -139,18 +141,21 @@
     }
 
     public IUncertainDegree matches(InternalFactHandle handle,
-            InternalWorkingMemory workingMemory) {        
-        if ( this.alphaConstraints.length > 0 ) {
-            double eps = 0;
-            for ( int i = 0; i < this.alphaConstraints.length; i++ ) {
-                double ei = ((Degree) this.alphaConstraints[i].matches( handle,
-                                                         workingMemory )).getValue(); 
-                eps = eps + ei - eps*ei;
-                }
-            return new Degree(eps);
-            }                    
-        return new Degree(1);
+            InternalWorkingMemory workingMemory) {
+    	
+    
+    	IDegreeFactory factory = workingMemory.getRuleBase().getTruthFactory();
+    	
+    	if (this.alphaConstraints.length > 0) {
+    		IUncertainDegree[] degs = new IUncertainDegree[this.alphaConstraints.length];
+    		for ( int i = 0; i < this.alphaConstraints.length; i++ ) {
+                degs[i] = this.alphaConstraints[i].matches(handle, workingMemory);                
+            }
+    		
+    		IUncDegCombiner or = factory.getOrOperator();
+    		return or.eval(degs);
+    	} else return factory.True();
+    	
     }
     
-    
 }

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/AlphaNodeFieldConstraint.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/AlphaNodeFieldConstraint.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/AlphaNodeFieldConstraint.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -30,4 +30,6 @@
     
     public IUncertainDegree matches(InternalFactHandle handle,
             InternalWorkingMemory workingMemory);
+           
+    
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -17,11 +17,16 @@
  */
 
 import java.io.Serializable;
+import java.util.Hashtable;
 
 import org.drools.FactHandle;
 import org.drools.WorkingMemory;
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
 import org.drools.common.InternalFactHandle;
+import org.drools.common.UncInternalFactHandle;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 /**
  * Factory Interface to return new <code>FactHandle</code>s
  * 
@@ -40,7 +45,17 @@
      */
     InternalFactHandle newFactHandle(Object object, boolean isEvent, WorkingMemory workingMemory );
     
+    
     /**
+     * Construct a uncertainty-based handle with a new id.
+     * 
+     * @return The handle.
+     */
+    UncInternalFactHandle newUncFactHandle(Object object, Hashtable<Constraint, IUncertainDegree> priors, boolean isEvent, WorkingMemory workingMemory );
+    
+    UncInternalFactHandle newUncFactHandle(Object object, Hashtable<Constraint, IUncertainDegree> priors, boolean isEvent, long duration, WorkingMemory workingMemory);
+    
+    /**
      * Construct a handle with a new id and a duration.
      * 
      * @return The handle.

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -17,13 +17,17 @@
  */
 
 import java.io.Serializable;
+import java.util.Hashtable;
 
 import org.drools.FactException;
 import org.drools.FactHandle;
 import org.drools.WorkingMemory;
+import org.drools.brms.client.modeldriven.brl.FieldConstraint;
 import org.drools.rule.Declaration;
 import org.drools.rule.Rule;
 
+import uncertainty.truthvals.IUncertainDegree;
+
 /**
  * KnowledgeHelper implementation types are injected into consequenses
  * instrumented at compile time and instances passed at runtime. It provides
@@ -109,6 +113,22 @@
     public void insertLogical(Object object,
     						  long duration,
     						  boolean dynamic) throws FactException;
+    
+    
+    /**
+     * When uncertainty is deduced about a fact, it has to be fed back into the
+     * system. The premises so obtained need not be evaluated, and so override the
+     * evaluators behaviour.
+     * 
+     * @param object	
+     * 		The (logically deduced) fact
+     * @param logicalPremises
+     * 		Map "field -> IUncDegree". For every field, the info is provided
+     * @throws FactException
+     */
+    public void insertLogical(Object object,
+			  Hashtable<Constraint, IUncertainDegree> logicalPremises) throws FactException;
+    
 
     void update(FactHandle handle,
                       Object newObject) throws FactException;

Modified: labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/ObjectType.java
===================================================================
--- labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/ObjectType.java	2008-03-14 01:05:56 UTC (rev 18951)
+++ labs/jbossrules/branches/uncertainDrools/drools-core/src/main/java/org/drools/spi/ObjectType.java	2008-03-14 01:07:10 UTC (rev 18952)
@@ -20,6 +20,7 @@
 
 import org.drools.base.ValueType;
 
+import uncertainty.factory.IDegreeFactory;
 import uncertainty.truthvals.IUncertainDegree;
 
 /**
@@ -56,7 +57,7 @@
      * 
      * 
      */
-    IUncertainDegree isCompatibleWith(Object object);
+    IUncertainDegree isCompatibleWith(Object object, IDegreeFactory factory);
     
     
     /**




More information about the jboss-svn-commits mailing list