[spambayes-dev] [Spambayes] ZeroDivisionError with hammie.score()

Tony Meyer tameyer at ihug.co.nz
Sun Jul 16 06:39:08 CEST 2006


> I've included the full traceback that you get when you run the script
> I provided.  Hopefully this will provide some information.  Any ideas
> on how to resolve this would be great -- I'm moderately new to Python.
>  Also, I upgraded to 1.1a2 and it's still occuring...
[...]

I believe the problem is in _wordinfoget, which should return None if  
the word is not in the database (and this is how _worddistanceget  
decides whether to use the 'unknown token' probability).

PGClassifier's _wordinfoget method (actually the base  
SQLClassifier's), which, as Kenny said, isn't widely used, is:

     def _wordinfoget(self, word):
         if isinstance(word, unicode):
             word = word.encode("utf-8")

         row = self._get_row(word)
         if row:
             item = self.WordInfoClass()
             item.__setstate__((row["nspam"], row["nham"]))
             return item
         else:
             return self.WordInfoClass()

I believe this should be:

     def _wordinfoget(self, word):
         if isinstance(word, unicode):
             word = word.encode("utf-8")

         row = self._get_row(word)
         if row:
             item = self.WordInfoClass()
             item.__setstate__((row["nspam"], row["nham"]))
             return item
         else:
             return None

(This is more-or-less what the mySQL storage option does).

Try that change (just changing the final return from  
"self.WordInfoClass()" to "None"), and see if it fixes the problem.   
If it does, please let us know so that we can make the change in the  
repository as well.

=Tony.Meyer




More information about the spambayes-dev mailing list