[Spambayes-checkins] spambayes/spambayes classifier.py,1.5,1.6

Tim Peters tim_one at users.sourceforge.net
Sun May 25 22:55:43 EDT 2003


Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv13387/spambayes

Modified Files:
	classifier.py 
Log Message:
Somewhere along the way, WordInfo lost its __slots__ decoration.
Restoring it cuts the memory burden of my dict-based classifier by more
than a factor of 2.  It should also speed it a bit.  Also added/restored
comments about the purpose of this class, and removed extraneous
punctuation from the method implementations.


Index: classifier.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/classifier.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** classifier.py	22 May 2003 05:21:16 -0000	1.5
--- classifier.py	26 May 2003 04:55:40 -0000	1.6
***************
*** 53,58 ****
--- 53,66 ----
  
  class WordInfo(object):
+     # A WordInfo is created for each distinct word.  spamcount is the
+     # number of trained spam msgs in which the word appears, and hamcount
+     # the number of trained ham msgs.
+     #
      # Invariant:  For use in a classifier database, at least one of
      # spamcount and hamcount must be non-zero.
+     #
+     # Important:  This is a tiny object.  Use of __slots__ is essential
+     # to conserve memory.
+     __slots__ = 'spamcount', 'hamcount'
  
      def __init__(self):
***************
*** 60,72 ****
  
      def __repr__(self):
!         return "WordInfo%r" % repr((self.spamcount,
!                                     self.hamcount))
  
      def __getstate__(self):
!         return (self.spamcount,
!                 self.hamcount)
  
      def __setstate__(self, t):
!         (self.spamcount, self.hamcount) = t
  
  
--- 68,78 ----
  
      def __repr__(self):
!         return "WordInfo" + repr((self.spamcount, self.hamcount))
  
      def __getstate__(self):
!         return self.spamcount, self.hamcount
  
      def __setstate__(self, t):
!         self.spamcount, self.hamcount = t
  
  





More information about the Spambayes-checkins mailing list