diff options
author | Mike Pirnat <mpirnat@gmail.com> | 2012-08-08 23:10:18 -0400 |
---|---|---|
committer | Mike Pirnat <mpirnat@gmail.com> | 2012-08-08 23:15:40 -0400 |
commit | 82bdf837d993fdf8db5f6e8fa6169be964adb687 (patch) | |
tree | 3df08f0dcabcbc570c7e404272b34fdab0f174d3 | |
parent | 775be2a87ad8a744548d1a1d0ae87a7e665ca10e (diff) | |
download | tiny-webapps-82bdf837d993fdf8db5f6e8fa6169be964adb687.tar.bz2 tiny-webapps-82bdf837d993fdf8db5f6e8fa6169be964adb687.tar.xz tiny-webapps-82bdf837d993fdf8db5f6e8fa6169be964adb687.zip |
Rudimentary scripts for training spam and ham from stdin
-rw-r--r-- | train_ham.py | 29 | ||||
-rw-r--r-- | train_spam.py | 29 |
2 files changed, 58 insertions, 0 deletions
diff --git a/train_ham.py b/train_ham.py new file mode 100644 index 0000000..4989c7c --- /dev/null +++ b/train_ham.py | |||
@@ -0,0 +1,29 @@ | |||
1 | """ | ||
2 | A rudimentary way to train additional ham into our pickle file. | ||
3 | |||
4 | Example usage: | ||
5 | |||
6 | $ python train_spam.py /path/to/spam.pkl | ||
7 | blah blah blah^D | ||
8 | """ | ||
9 | import sys | ||
10 | from ConfigParser import SafeConfigParser as ConfigParser, \ | ||
11 | NoSectionError, NoOptionError | ||
12 | from spambayes.storage import PickledClassifier | ||
13 | |||
14 | |||
15 | config = ConfigParser() | ||
16 | with open("/etc/email_gateway.cfg") as fp: | ||
17 | config.readfp(fp) | ||
18 | |||
19 | |||
20 | def main(): | ||
21 | pickle_filename = sys.argv[-1] | ||
22 | bayes = PickledClassifier(pickle_filename) | ||
23 | message = sys.stdin.readlines() | ||
24 | bayes.learn(message, False) | ||
25 | bayes.store() | ||
26 | |||
27 | |||
28 | if __name__ == '__main__': | ||
29 | main() | ||
diff --git a/train_spam.py b/train_spam.py new file mode 100644 index 0000000..c1f2065 --- /dev/null +++ b/train_spam.py | |||
@@ -0,0 +1,29 @@ | |||
1 | """ | ||
2 | A rudimentary way to train additional spam into our pickle file. | ||
3 | |||
4 | Example usage: | ||
5 | |||
6 | $ python train_spam.py /path/to/spam.pkl | ||
7 | blah blah blah^D | ||
8 | """ | ||
9 | import sys | ||
10 | from ConfigParser import SafeConfigParser as ConfigParser, \ | ||
11 | NoSectionError, NoOptionError | ||
12 | from spambayes.storage import PickledClassifier | ||
13 | |||
14 | |||
15 | config = ConfigParser() | ||
16 | with open("/etc/email_gateway.cfg") as fp: | ||
17 | config.readfp(fp) | ||
18 | |||
19 | |||
20 | def main(): | ||
21 | pickle_filename = sys.argv[-1] | ||
22 | bayes = PickledClassifier(pickle_filename) | ||
23 | message = sys.stdin.readlines() | ||
24 | bayes.learn(message, True) | ||
25 | bayes.store() | ||
26 | |||
27 | |||
28 | if __name__ == '__main__': | ||
29 | main() | ||