[Python-checkins] r56564 - tracker/instances/python-dev-spambayes-integration/extensions/spambayes.py

erik.forsberg python-checkins at python.org
Fri Jul 27 12:04:11 CEST 2007


Author: erik.forsberg
Date: Fri Jul 27 12:04:11 2007
New Revision: 56564

Modified:
   tracker/instances/python-dev-spambayes-integration/extensions/spambayes.py
Log:

Compensate for different classes having different property names for
the author.

Added utility function for finding out if an instance is classified as
spam.


Modified: tracker/instances/python-dev-spambayes-integration/extensions/spambayes.py
==============================================================================
--- tracker/instances/python-dev-spambayes-integration/extensions/spambayes.py	(original)
+++ tracker/instances/python-dev-spambayes-integration/extensions/spambayes.py	Fri Jul 27 12:04:11 2007
@@ -7,10 +7,10 @@
     node = db.getnode(classname, nodeid)
 
     authorage = node['creation'].timestamp() - \
-                db.getnode('user', node['author'])['creation'].timestamp()
+                db.getnode('user', node.get('author', node.get('creator')))['creation'].timestamp()
 
     tokens = ["klass:%s" % classname,
-              "author:%s" % node['author'],
+              "author:%s" % node.get('author', node.get('creator')),
               "authorage:%d" % int(authorage)]
 
     klass = db.getclass(classname)
@@ -18,7 +18,6 @@
 
 def train_spambayes(db, content, tokens, is_spam):
     spambayes_uri = db.config.detectors['SPAMBAYES_URI']
-    spam_cutoff = float(db.config.detectors['SPAMBAYES_SPAM_CUTOFF'])
 
     server = xmlrpclib.ServerProxy(spambayes_uri, verbose=False)
     try:
@@ -63,6 +62,16 @@
         self.db.commit()
             
 
+def is_spam(obj):
+    cutoff_score = float(obj._db.config.detectors['SPAMBAYES_SPAM_CUTOFF'])
+    try:
+        score = obj['spambayes_score']
+    except KeyError:
+        return False
+    return score >= cutoff_score
+
+
 def init(instance):
     instance.registerAction("spambayes_classify", SpambayesClassify)
+    instance.registerUtil('is_spam', is_spam)
     


More information about the Python-checkins mailing list