[Spambayes-checkins] spambayes hammie.py,1.37,1.38

Skip Montanaro montanaro@users.sourceforge.net
Thu Nov 14 22:00:17 2002


Update of /cvsroot/spambayes/spambayes
In directory usw-pr-cvs1:/tmp/cvs-serv30618

Modified Files:
	hammie.py 
Log Message:
Only open the database in write mode if we're training.  This allows
multiple users to share the same database, though of course you're still
subject to training quality issues.


Index: hammie.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/hammie.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** hammie.py	7 Nov 2002 22:30:05 -0000	1.37
--- hammie.py	14 Nov 2002 22:00:15 -0000	1.38
***************
*** 105,110 ****
      """
  
!     def __init__(self, dbname, iterskip=()):
!         self.hash = anydbm.open(dbname, 'c')
          self.iterskip = iterskip
  
--- 105,110 ----
      """
  
!     def __init__(self, dbname, mode, iterskip=()):
!         self.hash = anydbm.open(dbname, mode)
          self.iterskip = iterskip
  
***************
*** 185,192 ****
      # should just use ZODB.
  
!     def __init__(self, dbname):
          classifier.Bayes.__init__(self)
          self.statekey = "saved state"
!         self.wordinfo = DBDict(dbname, (self.statekey,))
  
          self.restore_state()
--- 185,193 ----
      # should just use ZODB.
  
!     def __init__(self, dbname, mode):
          classifier.Bayes.__init__(self)
          self.statekey = "saved state"
!         self.wordinfo = DBDict(dbname, mode, (self.statekey,))
!         self.dbmode = mode
  
          self.restore_state()
***************
*** 197,201 ****
  
      def save_state(self):
!         self.wordinfo[self.statekey] = (self.nham, self.nspam)
  
      def restore_state(self):
--- 198,203 ----
  
      def save_state(self):
!         if self.dbmode != 'r':
!             self.wordinfo[self.statekey] = (self.nham, self.nspam)
  
      def restore_state(self):
***************
*** 383,392 ****
      return (spams, hams)
  
! def createbayes(pck=DEFAULTDB, usedb=False):
      """Create a Bayes instance for the given pickle (which
      doesn't have to exist).  Create a PersistentBayes if
      usedb is True."""
      if usedb:
!         bayes = PersistentBayes(pck)
      else:
          bayes = None
--- 385,394 ----
      return (spams, hams)
  
! def createbayes(pck=DEFAULTDB, usedb=False, mode='r'):
      """Create a Bayes instance for the given pickle (which
      doesn't have to exist).  Create a PersistentBayes if
      usedb is True."""
      if usedb:
!         bayes = PersistentBayes(pck, mode)
      else:
          bayes = None
***************
*** 427,430 ****
--- 429,433 ----
      do_filter = False
      usedb = USEDB
+     mode = 'r'
      for opt, arg in opts:
          if opt == '-h':
***************
*** 432,437 ****
--- 435,442 ----
          elif opt == '-g':
              good.append(arg)
+             mode = 'c'
          elif opt == '-s':
              spam.append(arg)
+             mode = 'c'
          elif opt == '-p':
              pck = arg
***************
*** 451,455 ****
      save = False
  
!     bayes = createbayes(pck, usedb)
      h = Hammie(bayes)
  
--- 456,460 ----
      save = False
  
!     bayes = createbayes(pck, usedb, mode)
      h = Hammie(bayes)
  





More information about the Spambayes-checkins mailing list