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
|
--- reverend/guessers/email.py 2006-04-25 00:15:27.000000000 +0200
+++ reverend/guessers/email.py 2006-04-25 01:12:16.000000000 +0200
@@ -9,7 +9,6 @@
import email
from reverend.thomas import Bayes
-from reverend.splitter import Splitter
class EmailClassifier(Bayes):
@@ -19,19 +18,22 @@
# This should return a list of strings
# which will be used as the key into
# the table of token counts
- tokens = self.getHeaderTokens(msg)
- tokens += self.getBodyTokens(msg)
-
+ for tok in self.getHeaderTokens(msg):
+ yield tok
+
+ for tok in self.getBodyTokens(msg):
+ yield tok
+
# Get some tokens that are generated from the
# header and the structure
- tokens += self.getMetaTokens(msg)
- return tokens
+ for tok in self.getMetaTokens(msg):
+ yield tok
def getBodyTokens(self, msg):
text = self.getTextPlain(msg)
if text is None:
text = ''
- tl = self.splitter.split(text)
+ tl = self._tokenizer.tokenize(text)
return tl
def getHeaderTokens(self, msg):
@@ -40,12 +42,12 @@
text += msg.get('from','fromnoone') + ' '
text += msg.get('to','tonoone') + ' '
text += msg.get('cc','ccnoone') + ' '
- tl = self.splitter.split(text)
+ tl = self._tokenizer.tokenize(text)
return tl
def getTextPlain(self, msg):
for part in msg.walk():
- typ = part.get_type()
+ typ = part.get_content_type()
if typ and typ.lower() == "text/plain":
text = part.get_payload(decode=True)
return text
@@ -53,7 +55,7 @@
def getTextHtml(self, msg):
for part in msg.walk():
- typ = part.get_type()
+ typ = part.get_content_type()
if typ and typ.lower() == "text/html":
text = part.get_payload(decode=False)
return text
|