bayesball 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -1
- data/lib/bayesball/persistence.rb +1 -0
- data/lib/bayesball/persistence/sequel.rb +38 -0
- data/lib/bayesball/version.rb +1 -1
- data/spec/bayesball/persistence/sequel_spec.rb +38 -0
- data/spec/spec_helper.rb +11 -0
- metadata +10 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 478528e5894a3dedc57435782136dae425e36c49
|
4
|
+
data.tar.gz: 2c6b799680658bb607031eee0b4ca985eff6f14a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f28d402de88b753a1fe012e5e7e3cabdf59a8c001d6154fcd02d237fe1d66462922e50dffd9f18cb6900d92d0be4d6dd5a98c148d5c0686a4e6d11651fc7c2cb
|
7
|
+
data.tar.gz: 804e9ebdc8a73a5fe741482ffa2282624227530b136fac9a1faf52bee0b0f0e4dde152e163a104b9d47f267a44171d97d4d25a63200606aea1d31899cd519bf7
|
data/Gemfile
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Bayesball
|
2
|
+
module Persistence
|
3
|
+
class Sequel
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
attr_reader :dataset
|
7
|
+
def initialize(dataset)
|
8
|
+
@dataset = dataset
|
9
|
+
end
|
10
|
+
|
11
|
+
def empty?
|
12
|
+
@collection.count == 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](key)
|
16
|
+
dataset.where(bucket: key).to_hash(:word, :count)
|
17
|
+
end
|
18
|
+
|
19
|
+
def []=(key, value)
|
20
|
+
dataset.where(bucket: key).delete
|
21
|
+
value.each do |word, count|
|
22
|
+
dataset.insert word: word, count: count, bucket: key
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def each
|
27
|
+
if block_given?
|
28
|
+
dataset.to_a.group_by{|i| i[:bucket] }.each do |bucket, group|
|
29
|
+
counts = Hash[group.map{|g| [g[:word], g[:count]]}]
|
30
|
+
yield [bucket, counts]
|
31
|
+
end
|
32
|
+
else
|
33
|
+
self.to_enum
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/bayesball/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Bayesball
|
4
|
+
module Persistence
|
5
|
+
describe Sequel do
|
6
|
+
let(:dataset) { SEQUEL_DB[:bayesball_buckets] }
|
7
|
+
let(:persistence) { Sequel.new(dataset) }
|
8
|
+
|
9
|
+
it 'should return counts' do
|
10
|
+
persistence['truck'].wont_be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should set counts' do
|
14
|
+
persistence['car'] = {'x' => 3, 'y' => 2}
|
15
|
+
persistence['car'].must_equal 'x' => 3, 'y' => 2
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should reduce' do
|
19
|
+
persistence['duck'] = {'x' => 8, 'y' => 5}
|
20
|
+
persistence['cat'] = {'x' => 7, 'y' => 1}
|
21
|
+
persistence['dog'] = {'x' => 2, 'y' => 2}
|
22
|
+
|
23
|
+
result = persistence.reduce({}) do |memo, (category, counts)|
|
24
|
+
total = counts.values.reduce(:+).to_f
|
25
|
+
memo[category] = total
|
26
|
+
memo
|
27
|
+
end
|
28
|
+
result['duck'].must_equal 13
|
29
|
+
result['cat'].must_equal 8
|
30
|
+
result['dog'].must_equal 4
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return enumerator from each' do
|
34
|
+
persistence.each.class.must_equal Enumerator
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,3 +7,14 @@ require 'minitest/pride'
|
|
7
7
|
require 'minitest/autorun'
|
8
8
|
|
9
9
|
Bundler.require :development
|
10
|
+
|
11
|
+
SEQUEL_DB = Sequel.connect 'sqlite:///'
|
12
|
+
|
13
|
+
SEQUEL_DB.create_table :bayesball_buckets do
|
14
|
+
column :bucket, String, null: false
|
15
|
+
column :word, String, null: false
|
16
|
+
column :count, Integer, null: false
|
17
|
+
|
18
|
+
index :bucket
|
19
|
+
index [:bucket, :word], unique: true
|
20
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bayesball
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jason Staten
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-08-13 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: A bayes classifier
|
15
14
|
email:
|
@@ -29,42 +28,38 @@ files:
|
|
29
28
|
- lib/bayesball/classifier.rb
|
30
29
|
- lib/bayesball/persistence.rb
|
31
30
|
- lib/bayesball/persistence/mongo.rb
|
31
|
+
- lib/bayesball/persistence/sequel.rb
|
32
32
|
- lib/bayesball/stopwords.txt
|
33
33
|
- lib/bayesball/version.rb
|
34
34
|
- spec/bayesball/classifier_spec.rb
|
35
35
|
- spec/bayesball/persistence/mongo_spec.rb
|
36
|
+
- spec/bayesball/persistence/sequel_spec.rb
|
36
37
|
- spec/spec_helper.rb
|
37
38
|
homepage: ''
|
38
39
|
licenses: []
|
40
|
+
metadata: {}
|
39
41
|
post_install_message:
|
40
42
|
rdoc_options: []
|
41
43
|
require_paths:
|
42
44
|
- lib
|
43
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
46
|
requirements:
|
46
|
-
- -
|
47
|
+
- - '>='
|
47
48
|
- !ruby/object:Gem::Version
|
48
49
|
version: '0'
|
49
|
-
segments:
|
50
|
-
- 0
|
51
|
-
hash: -4130593485830818059
|
52
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
51
|
requirements:
|
55
|
-
- -
|
52
|
+
- - '>='
|
56
53
|
- !ruby/object:Gem::Version
|
57
54
|
version: '0'
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
hash: -4130593485830818059
|
61
55
|
requirements: []
|
62
56
|
rubyforge_project:
|
63
|
-
rubygems_version:
|
57
|
+
rubygems_version: 2.0.3
|
64
58
|
signing_key:
|
65
|
-
specification_version:
|
59
|
+
specification_version: 4
|
66
60
|
summary: A bayes classifier
|
67
61
|
test_files:
|
68
62
|
- spec/bayesball/classifier_spec.rb
|
69
63
|
- spec/bayesball/persistence/mongo_spec.rb
|
64
|
+
- spec/bayesball/persistence/sequel_spec.rb
|
70
65
|
- spec/spec_helper.rb
|