@@ -54,18 +54,12 @@ def initialize(*args)
5454 @backend = options [ :backend ]
5555 @tokenizer = options [ :tokenizer ] || Tokenizer ::Whitespace
5656 @token_filters = options [ :token_filters ] || [ TokenFilter ::Stopword ]
57- if @enable_stemmer && !@token_filters . include? ( TokenFilter ::Stemmer )
58- @token_filters << TokenFilter ::Stemmer
59- end
60- if @token_filters . include? ( TokenFilter ::Stopword )
61- TokenFilter ::Stopword . language = @language
62- end
57+ @token_filters << TokenFilter ::Stemmer if @enable_stemmer && !@token_filters . include? ( TokenFilter ::Stemmer )
58+ TokenFilter ::Stopword . language = @language if @token_filters . include? ( TokenFilter ::Stopword )
6359
6460 populate_initial_categories
6561
66- if options . key? ( :stopwords )
67- custom_stopwords options [ :stopwords ]
68- end
62+ custom_stopwords options [ :stopwords ] if options . key? ( :stopwords )
6963 end
7064
7165 # Provides a general training method for all categories specified in Bayes#new
@@ -168,7 +162,7 @@ def classify_with_score(text)
168162 # Return the classification without the score
169163 def classify ( text )
170164 result , score = classify_with_score ( text )
171- result = nil if score < @threshold || score == Float ::INFINITY if threshold_enabled?
165+ result = nil if threshold_enabled? && ( score < @threshold || score == Float ::INFINITY )
172166 result
173167 end
174168
@@ -256,7 +250,7 @@ def add_category(category)
256250 @backend . add_category ( category )
257251 end
258252
259- alias_method : append_category, : add_category
253+ alias append_category add_category
260254
261255 def reset
262256 @backend . reset
@@ -277,7 +271,7 @@ def custom_stopwords(stopwords)
277271 if stopwords . strip . empty?
278272 stopwords = [ ]
279273 elsif File . exist? ( stopwords )
280- stopwords = File . read ( stopwords ) . force_encoding ( " utf-8" ) . split
274+ stopwords = File . read ( stopwords ) . force_encoding ( ' utf-8' ) . split
281275 else
282276 return # Do not overwrite the default
283277 end
0 commit comments