[Spambayes-checkins] spambayes hammiefilter.py,1.10,1.11
Neale Pickett
npickett at users.sourceforge.net
Tue Jan 21 21:23:19 EST 2003
Update of /cvsroot/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv13378
Modified Files:
hammiefilter.py
Log Message:
* Fix function name in hammie.py
* Expound upon docstrings in hammie.py
* Options.py will now look for bayescustomize.ini and ~/.spambayesrc.
Hopefully some non-Unix folks will update this with sensible defaults
for their platforms.
* hammiefilter has a ton of new options -- check the docstring
Index: hammiefilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/hammiefilter.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** hammiefilter.py 21 Jan 2003 14:50:25 -0000 1.10
--- hammiefilter.py 22 Jan 2003 05:23:17 -0000 1.11
***************
*** 17,32 ****
"""Usage: %(program)s [OPTION]...
- A hammie front-end to make the simple stuff simple. The intent is to call
- this from procmail and its ilk like so:
-
- :0 fw
- | hammiefilter.py
-
- Then, you can set up your MUA to pipe ham and spam to it, one at a time, by
- calling it with either the -g or -s options, respectively.
-
[OPTION] is one of:
-h
show usage and exit
-d DBFILE
use database in DBFILE
--- 17,25 ----
"""Usage: %(program)s [OPTION]...
[OPTION] is one of:
-h
show usage and exit
+ -x
+ show some usage examples and exit
-d DBFILE
use database in DBFILE
***************
*** 35,53 ****
-n
create a new database
! -g
! train as a good (ham) message
! -s
! train as a bad (spam) message
! -t
! filter and train based on the result (you must make sure to
! untrain all mistakes later)
! -G
! untrain ham (only use if you've already trained this message)
! -S
! untrain spam (only use if you've already trained this message)
! All processing options operate on stdin. If no processing options are
! given, stdin will be scored: the same message, with a new header
! containing the score, will be send to stdout.
"""
--- 28,50 ----
-n
create a new database
! * -f
! filter (default if no processing options are given)
! * -t
! [EXPERIMENTAL] filter and train based on the result (you must
! make sure to untrain all mistakes later)
! * -g
! [EXPERIMENTAL] (re)train as a good (ham) message
! * -s
! [EXPERIMENTAL] (re)train as a bad (spam) message
! * -G
! [EXPERIMENTAL] untrain ham (only use if you've already trained
! this message)
! * -S
! [EXPERIMENTAL] untrain spam (only use if you've already trained
! this message)
! All processing options (marked with *) operate on stdin. If no
! processing options are given, stdin will be scored: the same message,
! with a new header containing the score, will be send to stdout.
"""
***************
*** 61,64 ****
--- 58,89 ----
program = sys.argv[0]
+ example_doc = """_Examples_
+
+ filter a message on disk:
+ %(program)s < message
+
+ (re)train a message as ham:
+ %(program)s -g < message
+
+ (re)train a message as spam:
+ %(program)s -s < message
+
+
+ procmail recipie to filter and train in one step:
+ :0 fw
+ | %(program)s -t
+
+
+ mutt configuration. This binds the 'H' key to retrain the message as
+ ham, and prompt for a folder to move it to. The 'S' key retrains as
+ spam, and moves to a 'spam' folder.
+ XXX: add this
+
+ """
+
+ def examples():
+ print example_doc % globals()
+ sys.exit(0)
+
def usage(code, msg=''):
"""Print usage message and sys.exit(code)."""
***************
*** 81,102 ****
h = hammie.open(self.dbname, self.usedb, 'n')
h.store()
! print "Created new database in", self.dbname
def filter(self, msg):
h = hammie.open(self.dbname, self.usedb, 'r')
! print h.filter(msg)
def filter_train(self, msg):
h = hammie.open(self.dbname, self.usedb, 'c')
! print h.filter(msg, train=True)
def train_ham(self, msg):
h = hammie.open(self.dbname, self.usedb, 'c')
! h.train_ham(msg)
h.store()
def train_spam(self, msg):
h = hammie.open(self.dbname, self.usedb, 'c')
! h.train_spam(msg)
h.store()
--- 106,127 ----
h = hammie.open(self.dbname, self.usedb, 'n')
h.store()
! print >> sys.stderr, "Created new database in", self.dbname
def filter(self, msg):
h = hammie.open(self.dbname, self.usedb, 'r')
! return h.filter(msg)
def filter_train(self, msg):
h = hammie.open(self.dbname, self.usedb, 'c')
! return h.filter(msg, train=True)
def train_ham(self, msg):
h = hammie.open(self.dbname, self.usedb, 'c')
! h.train_ham(msg, True)
h.store()
def train_spam(self, msg):
h = hammie.open(self.dbname, self.usedb, 'c')
! h.train_spam(msg, True)
h.store()
***************
*** 114,121 ****
h = HammieFilter()
actions = []
! opts, args = getopt.getopt(sys.argv[1:], 'hd:D:ngstGS', ['help'])
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt == '-d':
h.usedb = True
--- 139,148 ----
h = HammieFilter()
actions = []
! opts, args = getopt.getopt(sys.argv[1:], 'hxd:D:nfgstGS', ['help', 'examples'])
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
+ elif opt in ('-x', '--examples'):
+ examples()
elif opt == '-d':
h.usedb = True
***************
*** 124,127 ****
--- 151,156 ----
h.usedb = False
h.dbname = arg
+ elif opt == '-f':
+ actions.append(h.filter)
elif opt == '-g':
actions.append(h.train_ham)
***************
*** 144,148 ****
for action in actions:
action(msg)
!
if __name__ == "__main__":
--- 173,177 ----
for action in actions:
action(msg)
! sys.stdout.write(msg.as_string(unixfrom=(msg.get_unixfrom() is not None)))
if __name__ == "__main__":
More information about the Spambayes-checkins
mailing list