[jboss-svn-commits] JBL Code SVN: r14616 - labs/jbossrules/trunk/drools-decisiontables/src/main/resources.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Aug 26 20:39:50 EDT 2007


Author: michael.neale at jboss.com
Date: 2007-08-26 20:39:50 -0400 (Sun, 26 Aug 2007)
New Revision: 14616

Modified:
   labs/jbossrules/trunk/drools-decisiontables/src/main/resources/PyDT.py
Log:
moved to a more functional approach

Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/resources/PyDT.py
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/resources/PyDT.py	2007-08-26 22:25:50 UTC (rev 14615)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/resources/PyDT.py	2007-08-27 00:39:50 UTC (rev 14616)
@@ -33,7 +33,7 @@
 
     
 
-
+"""
 for row in table['data'] :
     #go through all the conditions, evaluating
     row_pass = True
@@ -61,31 +61,32 @@
 
 
 print str(fact)
+"""
 
+
 #lets try a map based approach
 def eval_table(row) :
     #go through all the conditions, evaluating
-    row_pass = True
-    for condition in headers :
+
+    def check_condition(condition) :    
+    #for condition in headers :
         col_index = condition[0]
+        if not row.has_key(col_index) :
+            return True
         cell_value = row[col_index]
-         
         predicate = str(condition[1]) + str(cell_value)
-        
-        if not eval(predicate) :
-            #then failure due to negation
-            row_pass = False
-            break
-        #if they all pass
-        #then iterate through and apply the action (unless we finish on first match)
-        #thats it !
-    if row_pass :
-        for action in table['action_headers'] :
-            
+        return eval(predicate)
+
+    size = len(filter(check_condition,headers))       
+
+    if size == len(headers) :
+        #for action in table['action_headers'] :
+        def apply_actions(action) :    
             col_label = action[0]
             if (row.has_key(col_label)) :
                 fact[action[1]] = row[col_label]
-
+        map(apply_actions, table['action_headers'])
+        
 map(eval_table, table['data'])
 
-
+print "And the result is: " + str(fact)




More information about the jboss-svn-commits mailing list