[Spambayes-checkins] spambayes Corpus.py,1.3,1.4 FileCorpus.py,1.5,1.6 Options.py,1.77,1.78 storage.py,1.1,1.2

Tim Stone timstone4@users.sourceforge.net
Tue Nov 26 00:43:53 2002


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

Modified Files:
	Corpus.py FileCorpus.py Options.py storage.py 
Log Message:
Added [globals] section to Options, with a verbose boolean

Changed FileCorpus, Corpus, storage to use the verbose global

Changed the test harness in FileCorpus to account for the wanton
destruction of my favorite method: classifier.classify()  <wink>

Index: Corpus.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Corpus.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Corpus.py	25 Nov 2002 02:29:44 -0000	1.3
--- Corpus.py	26 Nov 2002 00:43:51 -0000	1.4
***************
*** 87,94 ****
  import tokenizer
  import re
  
  SPAM = True
  HAM = False
- Verbose = False
  
  class Corpus:
--- 87,94 ----
  import tokenizer
  import re
+ from Options import options
  
  SPAM = True
  HAM = False
  
  class Corpus:
***************
*** 115,119 ****
          '''Add a Message to this corpus'''
  
!         if Verbose:
              print 'adding message %s to corpus' % (message.key())
  
--- 115,119 ----
          '''Add a Message to this corpus'''
  
!         if options.verbose:
              print 'adding message %s to corpus' % (message.key())
  
***************
*** 134,138 ****
  
          key = message.key()
!         if Verbose:
              print 'removing message %s from corpus' % (key)
          self.unCacheMessage(key)
--- 134,138 ----
  
          key = message.key()
!         if options.verbose:
              print 'removing message %s from corpus' % (key)
          self.unCacheMessage(key)
***************
*** 152,156 ****
          key = message.key()
  
!         if Verbose:
              print 'placing %s in corpus cache' % (key)
  
--- 152,156 ----
          key = message.key()
  
!         if options.verbose:
              print 'placing %s in corpus cache' % (key)
  
***************
*** 169,173 ****
          # This method should probably not be overridden
  
!         if Verbose:
              print 'Flushing %s from corpus cache' % (key)
  
--- 169,173 ----
          # This method should probably not be overridden
  
!         if options.verbose:
              print 'Flushing %s from corpus cache' % (key)
  
***************
*** 249,253 ****
              Corpus.cacheMessage(self, msg)
          else:
!             if Verbose:
                  print 'Not caching %s because it has expired' % (msg.key())
              raise KeyError, msg
--- 249,253 ----
              Corpus.cacheMessage(self, msg)
          else:
!             if options.verbose:
                  print 'Not caching %s because it has expired' % (msg.key())
              raise KeyError, msg
***************
*** 262,266 ****
                  msg = self[key]
              except KeyError, e:
!                 if Verbose:
                      print 'message %s has expired' % (key)
                  self.removeMessage(e[0])
--- 262,266 ----
                  msg = self[key]
              except KeyError, e:
!                 if options.verbose:
                      print 'message %s has expired' % (key)
                  self.removeMessage(e[0])

Index: FileCorpus.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/FileCorpus.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** FileCorpus.py	25 Nov 2002 20:49:12 -0000	1.5
--- FileCorpus.py	26 Nov 2002 00:43:51 -0000	1.6
***************
*** 88,91 ****
--- 88,92 ----
  import storage
  import sys, os, gzip, fnmatch, getopt, errno, time, stat
+ from Options import options
  
  class FileCorpus(Corpus.Corpus):
***************
*** 133,137 ****
              raise ValueError
  
!         if Corpus.Verbose:
              print 'adding',message.key(),'to corpus'
  
--- 134,138 ----
              raise ValueError
  
!         if options.verbose:
              print 'adding',message.key(),'to corpus'
  
***************
*** 145,149 ****
          '''Remove a Message from this corpus'''
  
!         if Corpus.Verbose:
              print 'removing',message.key(),'from corpus'
  
--- 146,150 ----
          '''Remove a Message from this corpus'''
  
!         if options.verbose:
              print 'removing',message.key(),'from corpus'
  
***************
*** 163,167 ****
              s = ''
  
!         if Corpus.Verbose and nummsgs > 0:
              lst = ', ' + '%s' % (self.keys())
          else:
--- 164,168 ----
              s = ''
  
!         if options.verbose and nummsgs > 0:
              lst = ', ' + '%s' % (self.keys())
          else:
***************
*** 205,209 ****
          '''Read the Message substance from the file'''
  
!         if Corpus.Verbose:
              print 'loading', self.file_name
  
--- 206,210 ----
          '''Read the Message substance from the file'''
  
!         if options.verbose:
              print 'loading', self.file_name
  
***************
*** 221,225 ****
          '''Write the Message substance to the file'''
  
!         if Corpus.Verbose:
              print 'storing', self.file_name
  
--- 222,226 ----
          '''Write the Message substance to the file'''
  
!         if options.verbose:
              print 'storing', self.file_name
  
***************
*** 232,236 ****
          '''Message hara-kiri'''
  
!         if Corpus.Verbose:
              print 'physically deleting file',self.pathname()
  
--- 233,237 ----
          '''Message hara-kiri'''
  
!         if options.verbose:
              print 'physically deleting file',self.pathname()
  
***************
*** 251,255 ****
          sub = self.getSubstance()
          
!         if Corpus.Verbose:
              sub = self.getSubstance()
          else:
--- 252,256 ----
          sub = self.getSubstance()
          
!         if options.verbose:
              sub = self.getSubstance()
          else:
***************
*** 294,298 ****
          '''Read the Message substance from the file'''
  
!         if Corpus.Verbose:
              print 'loading', self.file_name
  
--- 295,299 ----
          '''Read the Message substance from the file'''
  
!         if options.verbose:
              print 'loading', self.file_name
  
***************
*** 312,316 ****
          '''Write the Message substance to the file'''
  
!         if Corpus.Verbose:
              print 'storing', self.file_name
  
--- 313,317 ----
          '''Write the Message substance to the file'''
  
!         if options.verbose:
              print 'storing', self.file_name
  
***************
*** 445,459 ****
  
      for msg in unsurecorpus:
!         type = classbayes.classify(msg)
  
!         print 'Message %s spam probability is %f' % (msg.key(), msg.spamprob)
  
!         if type == 'ham':
              print 'Moving %s from unsurecorpus to hamcorpus, \
! based on prob of %f' % (msg.key(), msg.spamprob)
              hamcorpus.takeMessage(msg.key(), unsurecorpus)
!         elif type == 'spam':
              print 'Moving %s from unsurecorpus to spamcorpus, \
! based on prob of %f' % (msg.key(), msg.spamprob)
              spamcorpus.takeMessage(msg.key(), unsurecorpus)
  
--- 446,460 ----
  
      for msg in unsurecorpus:
!         prob = classbayes.spamprob(msg.tokenize())
  
!         print 'Message %s spam probability is %f' % (msg.key(), prob)
  
!         if prob < options.ham_cutoff:
              print 'Moving %s from unsurecorpus to hamcorpus, \
! based on prob of %f' % (msg.key(), prob)
              hamcorpus.takeMessage(msg.key(), unsurecorpus)
!         elif prob > options.spam_cutoff:
              print 'Moving %s from unsurecorpus to spamcorpus, \
! based on prob of %f' % (msg.key(), prob)
              spamcorpus.takeMessage(msg.key(), unsurecorpus)
  
***************
*** 686,690 ****
          sys.exit()
  
!     Corpus.Verbose = False
      runTestServer = False
      setupTestServer = False
--- 687,691 ----
          sys.exit()
  
!     options.verbose = False
      runTestServer = False
      setupTestServer = False
***************
*** 707,715 ****
              cleanupTestServer = True
          elif opt == '-v':
!             Corpus.Verbose = True
          elif opt == '-g':
              useGzip = True
          elif opt == '-u':
              useExistingDB = True
  
      if setupTestServer:
--- 708,718 ----
              cleanupTestServer = True
          elif opt == '-v':
!             options.verbose = True
          elif opt == '-g':
              useGzip = True
          elif opt == '-u':
              useExistingDB = True
+         elif opt == '-v':
+             options.verbose = True
  
      if setupTestServer:

Index: Options.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Options.py,v
retrieving revision 1.77
retrieving revision 1.78
diff -C2 -d -r1.77 -r1.78
*** Options.py	25 Nov 2002 04:23:31 -0000	1.77
--- Options.py	26 Nov 2002 00:43:51 -0000	1.78
***************
*** 370,373 ****
--- 370,376 ----
  html_ui_port: 8880
  html_ui_launch_browser: False
+ 
+ [globals]
+ verbose: False
  """
  
***************
*** 456,459 ****
--- 459,464 ----
      'html_ui': {'html_ui_port': int_cracker,
                  'html_ui_launch_browser': boolean_cracker,
+                 },
+     'globals': {'verbose': boolean_cracker,
                  },
  }

Index: storage.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/storage.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** storage.py	25 Nov 2002 06:22:26 -0000	1.1
--- storage.py	26 Nov 2002 00:43:51 -0000	1.2
***************
*** 56,60 ****
  NO_UPDATEPROBS = False   # Probabilities will not be autoupdated with training
  UPDATEPROBS = True       # Probabilities will be autoupdated with training
- DEBUG = False
  
  class PickledClassifier(classifier.Classifier):
--- 56,59 ----
***************
*** 73,77 ****
          # that pickle does its job
  
!         if DEBUG:
              print 'Loading state from',self.db_name,'pickle'
  
--- 72,76 ----
          # that pickle does its job
  
!         if options.verbose:
              print 'Loading state from',self.db_name,'pickle'
  
***************
*** 90,99 ****
              self.meta.nspam = tempbayes.get_nspam()
  
!             if DEBUG:
                  print '%s is an existing pickle, with %d ham and %d spam' \
                        % (self.db_name, self.nham, self.nspam)
          else:
              # new pickle
!             if DEBUG:
                  print self.db_name,'is a new pickle'
              self.wordinfo = {}
--- 89,98 ----
              self.meta.nspam = tempbayes.get_nspam()
  
!             if options.verbose:
                  print '%s is an existing pickle, with %d ham and %d spam' \
                        % (self.db_name, self.nham, self.nspam)
          else:
              # new pickle
!             if options.verbose:
                  print self.db_name,'is a new pickle'
              self.wordinfo = {}
***************
*** 104,108 ****
          '''Store self as a pickle'''
  
!         if DEBUG:
              print 'Persisting',self.db_name,'as a pickle'
  
--- 103,107 ----
          '''Store self as a pickle'''
  
!         if options.verbose:
              print 'Persisting',self.db_name,'as a pickle'
  
***************
*** 135,139 ****
          '''Load state from WIDict'''
  
!         if DEBUG:
              print 'Loading state from',self.db_name,'WIDict'
  
--- 134,138 ----
          '''Load state from WIDict'''
  
!         if options.verbose:
              print 'Loading state from',self.db_name,'WIDict'
  
***************
*** 146,155 ****
              self.set_nspam(nspam)
  
!             if DEBUG:
                  print '%s is an existing DBDict, with %d ham and %d spam' \
                        % (self.db_name, self.nham, self.nspam)
          else:
              # new dbdict
!             if DEBUG:
                  print self.db_name,'is a new DBDict'
              self.set_nham(0)
--- 145,154 ----
              self.set_nspam(nspam)
  
!             if options.verbose:
                  print '%s is an existing DBDict, with %d ham and %d spam' \
                        % (self.db_name, self.nham, self.nspam)
          else:
              # new dbdict
!             if options.verbose:
                  print self.db_name,'is a new DBDict'
              self.set_nham(0)
***************
*** 159,163 ****
          '''Place state into persistent store'''
  
!         if DEBUG:
              print 'Persisting',self.db_name,'state in WIDict'
  
--- 158,162 ----
          '''Place state into persistent store'''
  
!         if options.verbose:
              print 'Persisting',self.db_name,'state in WIDict'
  
***************
*** 185,189 ****
          '''Train the database with the message'''
  
!         if DEBUG:
              print 'training with',message.key()
  
--- 184,188 ----
          '''Train the database with the message'''
  
!         if options.verbose:
              print 'training with',message.key()
  
***************
*** 199,203 ****
          '''Untrain the database with the message'''
  
!         if DEBUG:
              print 'untraining with',message.key()
  
--- 198,202 ----
          '''Untrain the database with the message'''
  
!         if options.verbose:
              print 'untraining with',message.key()
  





More information about the Spambayes-checkins mailing list