@@ -29,12 +29,11 @@ class Bayes
2929 # backend: BayesMemoryBackend.new Alternatively, BayesRedisBackend.new for persistent storage
3030 def initialize ( *args )
3131 @initial_categories = [ ]
32- options = { language : 'en' ,
32+ options = { language : 'en' ,
3333 enable_threshold : false ,
34- threshold : 0.0 ,
35- enable_stemmer : true ,
36- backend : BayesMemoryBackend . new
37- }
34+ threshold : 0.0 ,
35+ enable_stemmer : true ,
36+ backend : BayesMemoryBackend . new }
3837 args . flatten . each do |arg |
3938 if arg . is_a? ( Hash )
4039 options . merge! ( arg )
@@ -79,6 +78,7 @@ def train(category, text)
7978 word_hash = Hasher . word_hash ( text , @enable_stemmer ,
8079 tokenizer : @tokenizer , token_filters : @token_filters )
8180 return if word_hash . empty?
81+
8282 category = CategoryNamer . prepare_name ( category )
8383
8484 # Add the category dynamically or raise an error
@@ -110,9 +110,11 @@ def untrain(category, text)
110110 word_hash = Hasher . word_hash ( text , @enable_stemmer ,
111111 tokenizer : @tokenizer , token_filters : @token_filters )
112112 return if word_hash . empty?
113+
113114 category = CategoryNamer . prepare_name ( category )
114115 word_hash . each do |word , count |
115116 next if @backend . total_words < 0
117+
116118 orig = @backend . category_word_frequency ( category , word ) || 0
117119 @backend . update_category_word_frequency ( category , word , -count )
118120 if @backend . category_word_frequency ( category , word ) <= 0
0 commit comments