"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "spambayes-1.0.4/spambayes/cdb_classifier.py" of archive spambayes-1.0.4.zip:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 """A classifier that uses a CDB database.
2
3 A CDB wordinfo database is quite small and fast but is slow to update.
4 It is appropriate if training is done rarely (e.g. monthly or weekly using
5 archived ham and spam). See mailsort.py for an example application that
6 uses this classifier.
7 """
8
9 from spambayes import cdb
10 from spambayes.tokenizer import tokenize
11 from spambayes.classifier import Classifier
12
13 class CdbClassifier(Classifier):
14 def __init__(self, cdbfile=None):
15 Classifier.__init__(self)
16 if cdbfile is not None:
17 self.wordinfo = cdb.Cdb(cdbfile)
18
19 def probability(self, record):
20 return float(record)
21
22 def save_wordinfo(self, db_file):
23 items = []
24 for word, record in self.wordinfo.iteritems():
25 prob = Classifier.probability(self, record)
26 items.append((word, str(prob)))
27 cdb.cdb_make(db_file, items)