@@ -86,26 +86,26 @@ def score(self, word, previous=None):
86
86
# Probability of the given word.
87
87
88
88
return unigrams [word ] / total
89
- else :
90
- # Penalize words not found in the unigrams according
91
- # to their length, a crucial heuristic.
92
89
93
- return 10.0 / (total * 10 ** len (word ))
94
- else :
95
- bigram = '{0} {1}' .format (previous , word )
90
+ # Penalize words not found in the unigrams according
91
+ # to their length, a crucial heuristic.
96
92
97
- if bigram in bigrams and previous in unigrams :
93
+ return 10.0 / ( total * 10 ** len ( word ))
98
94
99
- # Conditional probability of the word given the previous
100
- # word. The technical name is *stupid backoff* and it's
101
- # not a probability distribution but it works well in
102
- # practice.
95
+ bigram = '{0} {1}' .format (previous , word )
103
96
104
- return bigrams [bigram ] / total / self .score (previous )
105
- else :
106
- # Fall back to using the unigram probability.
97
+ if bigram in bigrams and previous in unigrams :
107
98
108
- return self .score (word )
99
+ # Conditional probability of the word given the previous
100
+ # word. The technical name is *stupid backoff* and it's
101
+ # not a probability distribution but it works well in
102
+ # practice.
103
+
104
+ return bigrams [bigram ] / total / self .score (previous )
105
+
106
+ # Fall back to using the unigram probability.
107
+
108
+ return self .score (word )
109
109
110
110
111
111
def isegment (self , text ):
@@ -174,10 +174,10 @@ def clean(cls, text):
174
174
return '' .join (letters )
175
175
176
176
177
- _segmenter = Segmenter ()
178
- load = _segmenter .load
179
- isegment = _segmenter .isegment
180
- segment = _segmenter .segment
177
+ _segmenter = Segmenter () # pylint: disable=invalid-name
178
+ load = _segmenter .load # pylint: disable=invalid-name
179
+ isegment = _segmenter .isegment # pylint: disable=invalid-name
180
+ segment = _segmenter .segment # pylint: disable=invalid-name
181
181
UNIGRAMS = _segmenter .unigrams
182
182
BIGRAMS = _segmenter .bigrams
183
183
0 commit comments