[Spambayes-checkins] spambayes hammie.py,1.21,1.22

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 27 Sep 2002 11:48:07 -0700


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

Modified Files:
	hammie.py 
Log Message:
Patch inspired by Alexander Leiding to support multiple -g, -s, -u
arguments.


Index: hammie.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/hammie.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** hammie.py	24 Sep 2002 00:38:37 -0000	1.21
--- hammie.py	27 Sep 2002 18:48:05 -0000	1.22
***************
*** 11,18 ****
--- 11,21 ----
      -g PATH
          mbox or directory of known good messages (non-spam) to train on.
+         Can be specified more than once.
      -s PATH
          mbox or directory of known spam messages to train on.
+         Can be specified more than once.
      -u PATH
          mbox of unknown messages.  A ham/spam decision is reported for each.
+         Can be specified more than once.
      -p FILE
          use file as the persistent store.  loads data from this file if it
***************
*** 264,268 ****
  
      pck = DEFAULTDB
!     good = spam = unknown = None
      do_filter = usedb = False
      for opt, arg in opts:
--- 267,273 ----
  
      pck = DEFAULTDB
!     good = []
!     spam = []
!     unknown = []
      do_filter = usedb = False
      for opt, arg in opts:
***************
*** 270,276 ****
              usage(0)
          elif opt == '-g':
!             good = arg
          elif opt == '-s':
!             spam = arg
          elif opt == '-p':
              pck = arg
--- 275,281 ----
              usage(0)
          elif opt == '-g':
!             good.append(arg)
          elif opt == '-s':
!             spam.append(arg)
          elif opt == '-p':
              pck = arg
***************
*** 280,284 ****
              do_filter = True
          elif opt == '-u':
!             unknown = arg
      if args:
          usage(2, "Positional arguments not allowed")
--- 285,289 ----
              do_filter = True
          elif opt == '-u':
!             unknown.append(arg)
      if args:
          usage(2, "Positional arguments not allowed")
***************
*** 289,298 ****
  
      if good:
!         print "Training ham:"
!         train(bayes, good, False)
          save = True
      if spam:
!         print "Training spam:"
!         train(bayes, spam, True)
          save = True
  
--- 294,305 ----
  
      if good:
!         for g in good:
!             print "Training ham (%s):" % g
!             train(bayes, g, False)
          save = True
      if spam:
!         for s in spam:
!             print "Training spam (%s):" % s
!             train(bayes, s, True)
          save = True
  
***************
*** 308,312 ****
  
      if unknown:
!         score(bayes, unknown)
  
  if __name__ == "__main__":
--- 315,322 ----
  
      if unknown:
!         for u in unknown:
!             if len(unknown) > 1:
!                 print "Scoring", u
!             score(bayes, u)
  
  if __name__ == "__main__":