inferx 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/inferx/category.rb +22 -0
- data/lib/inferx/version.rb +1 -1
- data/spec/inferx/category_spec.rb +26 -0
- metadata +3 -3
data/lib/inferx/category.rb
CHANGED
@@ -71,6 +71,14 @@ class Inferx
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
# Prepare to enhance the training data. Use for high performance.
|
75
|
+
#
|
76
|
+
# @yield [train] process something
|
77
|
+
# @yieldparam [Proc] train enhance the training data giving words
|
78
|
+
def ready_to_train(&process)
|
79
|
+
train(aggregate(&process))
|
80
|
+
end
|
81
|
+
|
74
82
|
# Attenuate the training data giving words.
|
75
83
|
#
|
76
84
|
# @param [Array<String>] words an array of words
|
@@ -98,6 +106,14 @@ class Inferx
|
|
98
106
|
end
|
99
107
|
end
|
100
108
|
|
109
|
+
# Prepare to attenuate the training data giving words.
|
110
|
+
#
|
111
|
+
# @yield [untrain] process something
|
112
|
+
# @yieldparam [Proc] untrain attenuate the training data giving words
|
113
|
+
def ready_to_untrain(&process)
|
114
|
+
untrain(aggregate(&process))
|
115
|
+
end
|
116
|
+
|
101
117
|
# Get effectively scores for each word.
|
102
118
|
#
|
103
119
|
# @param [Array<String>] words an array of words
|
@@ -123,5 +139,11 @@ class Inferx
|
|
123
139
|
hash
|
124
140
|
end
|
125
141
|
end
|
142
|
+
|
143
|
+
def aggregate
|
144
|
+
all = []
|
145
|
+
yield lambda { |items| all += items }
|
146
|
+
all
|
147
|
+
end
|
126
148
|
end
|
127
149
|
end
|
data/lib/inferx/version.rb
CHANGED
@@ -122,6 +122,19 @@ describe Inferx::Category, '#train' do
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
+
describe Inferx::Category, '#ready_to_train' do
|
126
|
+
it 'calls #train with the words to train block' do
|
127
|
+
category = described_class.new(redis_stub, :red, 2)
|
128
|
+
category.should_receive(:train).with(%w(word1 word2 word3))
|
129
|
+
|
130
|
+
category.ready_to_train do |train|
|
131
|
+
train[%w(word1)]
|
132
|
+
train[%w(word2)]
|
133
|
+
train[%w(word3)]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
125
138
|
describe Inferx::Category, '#untrain' do
|
126
139
|
it 'calls Redis#zincrby, Redis#zremrangebyscore and Redis#hincrby' do
|
127
140
|
redis = redis_stub do |s|
|
@@ -177,6 +190,19 @@ describe Inferx::Category, '#untrain' do
|
|
177
190
|
end
|
178
191
|
end
|
179
192
|
|
193
|
+
describe Inferx::Category, '#ready_to_untrain' do
|
194
|
+
it 'calls #untrain with the words to untrain block' do
|
195
|
+
category = described_class.new(redis_stub, :red, 2)
|
196
|
+
category.should_receive(:untrain).with(%w(word1 word2 word3))
|
197
|
+
|
198
|
+
category.ready_to_untrain do |untrain|
|
199
|
+
untrain[%w(word1)]
|
200
|
+
untrain[%w(word2)]
|
201
|
+
untrain[%w(word3)]
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
180
206
|
describe Inferx::Category, '#scores' do
|
181
207
|
it 'calls Redis#zscore' do
|
182
208
|
redis = redis_stub do |s|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inferx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.8.
|
90
|
+
rubygems_version: 1.8.24
|
91
91
|
signing_key:
|
92
92
|
specification_version: 3
|
93
93
|
summary: Naive Bayes classifier, the training data on Redis
|