1
2
3
4 """The Stoplist class holds a list of (undesired) words."""
5
6
8 """Stoplist classes holding every words of the stoplist(s).
9
10 The program's predictors test every suggested words against the stoplist. If
11 a suggested word is a stoplist word then the suggested word is not added to
12 the suggested words list.
13
14 G{classtree StopList}
15 """
16
18 """Extract every words of the file and store them in a list.
19
20 The file must contains one word per line. The method dosen't lower any
21 word.
22
23 @param stopListFile:
24 Path to the stoplist file.
25 @type stopListFile: str
26 """
27 self.stopListFile = stopListFile
28 self.words = []
29 if self.stopListFile:
30 try:
31 with open(self.stopListFile) as f:
32 self.words = [x.strip('\n') for x in f.readlines()]
33 except IOError:
34 lg.error('Cannot open file "%s". Stop list won\'t be used'
35 % (self.stopListFile))
36 self.size = len(self.words)
37
39 """Add words to the stoplist.
40
41 @param wordList:
42 The words to add.
43 @type wordList: list
44 """
45 for word in wordList:
46 self.add_word(word)
47
49 """Add a word to the stoplist.
50
51 @param word:
52 The word to add.
53 @type word: str
54 """
55 self.words.append(word)
56 self.size += 1
57
59 """Remove words from the stoplist.
60
61 @param wordList:
62 The words to remove.
63 @type wordList: list
64 """
65 for word in wordList:
66 self.remove_word(word)
67
69 """Remove a word from the stoplist.
70
71 @param word:
72 The word to remove.
73 @type word: str
74 """
75 try:
76 self.words.remove(word)
77 self.size -= 1
78 except ValueError:
79 print('WARNING: "' + word + '" is not in stop list')
80