-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplefilters.py
42 lines (30 loc) · 1.63 KB
/
simplefilters.py
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
from basefilter import BaseFilter
from utils import read_classification_from_file, write_classification_to_file
from random import choice
class NaiveFilter(BaseFilter):
"""This filter classifies all the emails as OK"""
def __init__(self):
super(NaiveFilter, self).__init__()
def train(self, training_corpus_path):
self.dictionary = read_classification_from_file(training_corpus_path + '/!truth.txt')
self.dictionary.fromkeys(self.dictionary, self.table[0])
def test(self, prediction_corpus_path):
write_classification_to_file(self.dictionary, prediction_corpus_path + '/!prediction.txt')
class ParanoidFilter(BaseFilter):
"""This filter classifies all the emails as SPAM"""
def __init__(self):
super(ParanoidFilter, self).__init__()
def train(self, training_corpus_path):
self.dictionary = read_classification_from_file(training_corpus_path + '/!truth.txt')
self.dictionary.fromkeys(self.dictionary, self.table[1])
def test(self, prediction_corpus_path):
write_classification_to_file(self.dictionary, prediction_corpus_path + '/!prediction.txt')
class RandomFilter(BaseFilter):
"""This filter classifies all the emails by random"""
def __init__(self):
super(RandomFilter, self).__init__()
def train(self, training_corpus_path):
self.dictionary = read_classification_from_file(training_corpus_path + '/!truth.txt')
self.dictionary = {x: choice(self.table) for x in self.dictionary}
def test(self, prediction_corpus_path):
write_classification_to_file(self.dictionary, prediction_corpus_path + '/!prediction.txt')