nbayes 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ NBayes is a full-featured, Ruby implementation of Naive Bayes. Some of the feat
12
12
  * optional binarized mode
13
13
  * uses log probabilities to avoid underflow
14
14
 
15
- For more information, view this blog post (coming soon)
15
+ For more information, view this blog post: http://blog.oasic.net/2012/06/naive-bayes-for-ruby.html
16
16
 
17
17
  == Contributing to nbayes
18
18
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -159,7 +159,6 @@ module NBayes
159
159
  final_probs
160
160
  end
161
161
 
162
-
163
162
  # Loads class instance from a data file (e.g., yaml)
164
163
  def self.from(yml_file)
165
164
  nbayes = YAML.load_file(yml_file)
@@ -167,9 +166,26 @@ module NBayes
167
166
  nbayes
168
167
  end
169
168
 
170
- # Dumps class instance to a file
171
- def dump(yml_file)
172
- File.open(yml_file, "w") {|f| YAML.dump(self, f) }
169
+ # Load class instance
170
+ def load(yml)
171
+ if yml.nil?
172
+ return NBayes::Base.new
173
+ elsif yml[0..2] == "---"
174
+ nbayes = YAML.load(yml)
175
+ else
176
+ nbayes = YAML.load_file(yml_file)
177
+ end
178
+ nbayes.reset_after_import() # yaml does not properly set the defaults on the Hashes
179
+ nbayes
180
+ end
181
+
182
+ # Dumps class instance to a data file (e.g., yaml) or a string
183
+ def dump(arg)
184
+ if arg.instance_of? String
185
+ File.open(arg, "w") {|f| YAML.dump(self, f) }
186
+ else
187
+ YAML.dump(arg)
188
+ end
173
189
  end
174
190
 
175
191
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "nbayes"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["oasic"]
12
- s.date = "2012-06-27"
12
+ s.date = "2012-07-13"
13
13
  s.description = "Ruby implementation of Naive Bayes that generates true probabilities per class, works with many token types, and provides lots of bells and whistles while being optimized for performance."
14
14
  s.email = "j@oasic.net"
15
15
  s.extra_rdoc_files = [
@@ -148,4 +148,14 @@ describe "NBayes" do
148
148
  end
149
149
  end
150
150
 
151
+ it "should dump to yaml string and load from yaml string" do
152
+ @nbayes.train( %w[a a a a], 'classA' )
153
+ @nbayes.train( %w[b b b b], 'classB' )
154
+ results = @nbayes.classify( ['b'] )
155
+ results['classB'].should >= 0.5
156
+ yml = @nbayes.dump(@nbayes)
157
+ @nbayes2 = NBayes::Base.new.load(yml)
158
+ results = @nbayes.classify( ['b'] )
159
+ results['classB'].should >= 0.5
160
+ end
151
161
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: nbayes
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - oasic
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-06-27 00:00:00 Z
13
+ date: 2012-07-13 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -91,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
- hash: -4266862066196834109
94
+ hash: 1596303061917544948
95
95
  segments:
96
96
  - 0
97
97
  version: "0"