omnicat-bayes 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Omnicat
2
2
  module Bayes
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
@@ -96,8 +96,9 @@ module OmniCat
96
96
  "Document is not found in #{category_name} documents!"
97
97
  end
98
98
  doc.tokens.each do |token, count|
99
- decrement_token_counts(category_name, token, count)
100
99
  @categories[category_name].tokens[token] = @categories[category_name].tokens[token].to_i - count
100
+ @categories[category_name].tokens.delete(token) if @categories[category_name].tokens[token] == 0
101
+ decrement_token_counts(category_name, token, count)
101
102
  end
102
103
  @categories[category_name].docs.delete(doc_key) if @categories[category_name].docs[doc_key].count == 0
103
104
  decrement_doc_counts(category_name)
@@ -180,7 +181,7 @@ module OmniCat
180
181
 
181
182
  # nodoc
182
183
  def modify_uniq_token_count(token, uniq_token_addition)
183
- categories.each do |_, category|
184
+ @categories.each do |_, category|
184
185
  if category.tokens.has_key?(token)
185
186
  uniq_token_addition = 0
186
187
  break
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'omnicat', '~> 0.2.1'
21
+ spec.add_dependency 'hashable', '~> 0.1.1'
22
+ spec.add_dependency 'omnicat', '~> 0.2.2'
22
23
  spec.add_development_dependency 'bundler', '~> 1.3'
23
24
  spec.add_development_dependency 'rake'
24
25
  end
@@ -128,6 +128,16 @@ class TestBayes < Test::Unit::TestCase
128
128
  def test_train_missing_category
129
129
  assert_raise(StandardError) { @bayes.train 'neutral', 'how are you?' }
130
130
  end
131
+
132
+ def test_unique_token_count
133
+ @bayes.add_category 'positive'
134
+ @bayes.train_batch 'positive', ['good job ever', 'valid syntax',
135
+ 'best moments of my good life']
136
+ assert_equal(10,@bayes.uniq_token_count)
137
+ @bayes.untrain_batch 'positive', ['good job ever', 'valid syntax',
138
+ 'best moments of my good life']
139
+ assert_equal(0,@bayes.uniq_token_count)
140
+ end
131
141
 
132
142
  def test_classifiability_error
133
143
  @bayes.add_category 'positive'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omnicat-bayes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,6 +11,22 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.1
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: omnicat
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -18,7 +34,7 @@ dependencies:
18
34
  requirements:
19
35
  - - ~>
20
36
  - !ruby/object:Gem::Version
21
- version: 0.2.1
37
+ version: 0.2.2
22
38
  type: :runtime
23
39
  prerelease: false
24
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +42,7 @@ dependencies:
26
42
  requirements:
27
43
  - - ~>
28
44
  - !ruby/object:Gem::Version
29
- version: 0.2.1
45
+ version: 0.2.2
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: bundler
32
48
  requirement: !ruby/object:Gem::Requirement