[Spambayes-checkins] spambayes Bayes.py,1.3,1.4
Tim Stone
timstone4@projects.sourceforge.net
Mon Nov 18 04:48:12 2002
Update of /cvsroot/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv32640
Modified Files:
Bayes.py
Log Message:
Corrected the load/store semantic to DBDictBayes, which had been using a
straight DBDict instance - with continual persistence. This was
inconsistent with the PersistentBayes design point, and did not meet
the requirements of pop3proxy, which will have 'quit' and 'save and quit'
options.
Index: Bayes.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Bayes.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Bayes.py 16 Nov 2002 16:47:39 -0000 1.3
--- Bayes.py 18 Nov 2002 04:48:10 -0000 1.4
***************
*** 63,66 ****
--- 63,68 ----
import cPickle as pickle
import errno
+ import copy
+ import anydbm
PICKLE_TYPE = 1
***************
*** 176,180 ****
self.db_name = db_name
self.statekey = "saved state"
- self.wordinfo = DBDict(db_name, 'c', (self.statekey,)) # r/rw?
self.load()
--- 178,181 ----
***************
*** 186,199 ****
print 'Loading state from',self.db_name,'DB_Dict'
! if self.wordinfo.has_key(self.statekey):
! self.nham, self.nspam = self.wordinfo[self.statekey]
!
if Corpus.Verbose:
print '%s is an existing DBDict, with %d ham and %d spam' \
% (self.db_name, self.nham, self.nspam)
else:
# new dbdict
if Corpus.Verbose:
print self.db_name,'is a new DBDict'
self.nham = 0
self.nspam = 0
--- 187,209 ----
print 'Loading state from',self.db_name,'DB_Dict'
! try:
! wi = DBDict(self.db_name, 'r')
! except anydbm.error:
! wi = {}
!
! if wi.has_key(self.statekey):
if Corpus.Verbose:
print '%s is an existing DBDict, with %d ham and %d spam' \
% (self.db_name, self.nham, self.nspam)
+
+ self.nham, self.nspam = wi[self.statekey]
+
+ for word,info in wi:
+ self.wordinfo[word] = info
else:
# new dbdict
if Corpus.Verbose:
print self.db_name,'is a new DBDict'
+ self.wordinfo = {}
self.nham = 0
self.nspam = 0
***************
*** 202,209 ****
'''Place state into persistent store'''
if Corpus.Verbose:
print 'Persisting',self.db_name,'state in DBDict'
! self.wordinfo[self.statekey] = (self.nham, self.nspam)
--- 212,223 ----
'''Place state into persistent store'''
+ wi = DBDict(self.db_name, 'c')
+
if Corpus.Verbose:
print 'Persisting',self.db_name,'state in DBDict'
! wi[self.statekey] = (self.nham, self.nspam)
! for word in self.wordinfo:
! wi[word] = self.wordinfo[word]
More information about the Spambayes-checkins
mailing list