My favorites
|
Sign in
django-spambayes
A collection of utility apps for using SpamBayes filtering within Django projects.
Project Home
Downloads
Issues
Source
Checkout
|
Browse
|
Changes
|
r11
Source path:
svn
/
trunk
/
docs
/
djangobayes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
DjangoBayes
===========
The DjangoBayes app is the workhorse that gets Django and SpamBayes to talk
to each other. It contains a Django model for SpamBayes to store its 'learned'
data in and a SpamBayes ``Classifier`` subclass that wraps the Django model.
This is all wrapped up in a SpamBayes ``Hammie`` instance
(``djangobayes.filter.filter``) which contains the public API accessed by
other apps.
Setup:
------
First follow the instructions in ``INSTALL.txt`` and make sure
``djangobayes.py`` is on your ``PYHTONPATH``.
Add ``djangobayes`` to ``INSTALLED_APPS`` in your ``settings.py`` file. Then,
from the command line run:
python manage.py syncdb
Basic Usage:
------------
>>> from djangobayes.filter import filter
>>> score = filter.score('some text')
>>> if score < 0.3:
... # do something with spam
... elif score > 0.8:
... # do something with ham
... else:
... # unsure - do something else
Of course, this will only work if SpamBayes has been trained. To train do:
>>> filter.train('some spam', True)
>>> filter.store()
>>> filter.train('some ham', False)
>>> filter.store()
In some situations you may want to filter based on more than a single body
of text. For example, an author's name, e-mail address, IP address, etc. As
SpamBayes is intended for filtering e-mail, you can pass in a message object
rather than a plain string. DjangoBayes provides a handy shortcut,
``build_msg`` which excepts a ``body`` and any keywords you provide to build
a message. For example:
>>> from djangobayes.filter import build_msg
>>> msg = build_msg('some text', author='Bob', email='bob@example.com')
>>> score = filter.score(msg)
>>> # or ...
>>> msg = build_msg('body text', **{'name' : 'Sue', 'ip' : '127.0.0.1'})
>>> filter.train(msg)
>>> filter.store()
As far as I can tell, SpamBayes doesn't really care what the names of the
keywords are as long as they are consistent throughout your app. It simply
sees them as e-mail headers and doesn't give any particular headers more
weight than others. That's why the primary text _must_ be passed in
separately.
As this is a SpamBayes API, see the SpamBayes documentation (and read the
code) for more information.
Show details
Hide details
Change log
r10
by waylan on Sep 29, 2008
Diff
Added docs and setup.py
Go to:
/trunk/INSTALL.txt
/trunk/LICENSE.txt
/trunk/MANIFEST.in
/trunk/README.txt
/trunk/docs
/trunk/docs/commentbayes.txt
/trunk/docs/djangobayes.txt
/trunk/settings.py
/trunk/setup.py
/trunk/urls.py
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 2282 bytes, 63 lines
View raw file
Hosted by