predictor 1.0.0 → 2.0.0.rc1
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.
- checksums.yaml +4 -4
- data/Changelog.md +13 -0
- data/Gemfile +1 -1
- data/README.md +75 -32
- data/docs/READMEv1.md +206 -0
- data/lib/predictor/base.rb +128 -60
- data/lib/predictor/input_matrix.rb +29 -82
- data/lib/predictor/version.rb +1 -1
- data/spec/base_spec.rb +160 -94
- data/spec/input_matrix_spec.rb +30 -160
- data/spec/predictor_spec.rb +1 -1
- metadata +6 -4
data/spec/input_matrix_spec.rb
CHANGED
@@ -14,22 +14,6 @@ describe Predictor::InputMatrix do
|
|
14
14
|
@matrix.redis_key.should == "predictor-test:mymatrix"
|
15
15
|
end
|
16
16
|
|
17
|
-
it "should respond to add_set" do
|
18
|
-
@matrix.respond_to?(:add_set).should == true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should respond to add_single" do
|
22
|
-
@matrix.respond_to?(:add_single).should == true
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should respond to similarities_for" do
|
26
|
-
@matrix.respond_to?(:similarities_for).should == true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should respond to all_items" do
|
30
|
-
@matrix.respond_to?(:all_items).should == true
|
31
|
-
end
|
32
|
-
|
33
17
|
describe "weight" do
|
34
18
|
it "returns the weight configured or a default of 1" do
|
35
19
|
@matrix.weight.should == 1.0 # default weight
|
@@ -38,16 +22,10 @@ describe Predictor::InputMatrix do
|
|
38
22
|
end
|
39
23
|
end
|
40
24
|
|
41
|
-
describe "
|
42
|
-
it "adds each member of the set to the 'all_items' set" do
|
43
|
-
@matrix.all_items.should_not include("foo", "bar", "fnord", "blubb")
|
44
|
-
@matrix.add_set "item1", ["foo", "bar", "fnord", "blubb"]
|
45
|
-
@matrix.all_items.should include("foo", "bar", "fnord", "blubb")
|
46
|
-
end
|
47
|
-
|
25
|
+
describe "add_to_set" do
|
48
26
|
it "adds each member of the set to the key's 'sets' set" do
|
49
27
|
@matrix.items_for("item1").should_not include("foo", "bar", "fnord", "blubb")
|
50
|
-
@matrix.
|
28
|
+
@matrix.add_to_set "item1", "foo", "bar", "fnord", "blubb"
|
51
29
|
@matrix.items_for("item1").should include("foo", "bar", "fnord", "blubb")
|
52
30
|
end
|
53
31
|
|
@@ -56,7 +34,7 @@ describe Predictor::InputMatrix do
|
|
56
34
|
@matrix.sets_for("bar").should_not include("item1")
|
57
35
|
@matrix.sets_for("fnord").should_not include("item1")
|
58
36
|
@matrix.sets_for("blubb").should_not include("item1")
|
59
|
-
@matrix.
|
37
|
+
@matrix.add_to_set "item1", "foo", "bar", "fnord", "blubb"
|
60
38
|
@matrix.sets_for("foo").should include("item1")
|
61
39
|
@matrix.sets_for("bar").should include("item1")
|
62
40
|
@matrix.sets_for("fnord").should include("item1")
|
@@ -64,58 +42,11 @@ describe Predictor::InputMatrix do
|
|
64
42
|
end
|
65
43
|
end
|
66
44
|
|
67
|
-
describe "add_set!" do
|
68
|
-
it "calls add_set and process_item! for each item" do
|
69
|
-
@matrix.should_receive(:add_set).with("item1", ["foo", "bar"])
|
70
|
-
@matrix.should_receive(:process_item!).with("foo")
|
71
|
-
@matrix.should_receive(:process_item!).with("bar")
|
72
|
-
@matrix.add_set! "item1", ["foo", "bar"]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "add_single" do
|
77
|
-
it "adds the item to the 'all_items' set" do
|
78
|
-
@matrix.all_items.should_not include("foo")
|
79
|
-
@matrix.add_single "item1", "foo"
|
80
|
-
@matrix.all_items.should include("foo")
|
81
|
-
end
|
82
|
-
|
83
|
-
it "adds the item to the key's 'sets' set" do
|
84
|
-
@matrix.items_for("item1").should_not include("foo")
|
85
|
-
@matrix.add_single "item1", "foo"
|
86
|
-
@matrix.items_for("item1").should include("foo")
|
87
|
-
end
|
88
|
-
|
89
|
-
it "adds the key to the item's 'items' set" do
|
90
|
-
@matrix.sets_for("foo").should_not include("item1")
|
91
|
-
@matrix.add_single "item1", "foo"
|
92
|
-
@matrix.sets_for("foo").should include("item1")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "add_single!" do
|
97
|
-
it "calls add_single and process_item! for the item" do
|
98
|
-
@matrix.should_receive(:add_single).with("item1", "foo")
|
99
|
-
@matrix.should_receive(:process_item!).with("foo")
|
100
|
-
@matrix.add_single! "item1", "foo"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "all_items" do
|
105
|
-
it "returns all items across all sets in the input matrix" do
|
106
|
-
@matrix.add_set "item1", ["foo", "bar", "fnord", "blubb"]
|
107
|
-
@matrix.add_set "item2", ["foo", "bar", "snafu", "nada"]
|
108
|
-
@matrix.add_set "item3", ["nada"]
|
109
|
-
@matrix.all_items.should include("foo", "bar", "fnord", "blubb", "snafu", "nada")
|
110
|
-
@matrix.all_items.length.should == 6
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
45
|
describe "items_for" do
|
115
46
|
it "returns the items in the given set ID" do
|
116
|
-
@matrix.
|
47
|
+
@matrix.add_to_set "item1", ["foo", "bar", "fnord", "blubb"]
|
117
48
|
@matrix.items_for("item1").should include("foo", "bar", "fnord", "blubb")
|
118
|
-
@matrix.
|
49
|
+
@matrix.add_to_set "item2", ["foo", "bar", "snafu", "nada"]
|
119
50
|
@matrix.items_for("item2").should include("foo", "bar", "snafu", "nada")
|
120
51
|
@matrix.items_for("item1").should_not include("snafu", "nada")
|
121
52
|
end
|
@@ -123,8 +54,8 @@ describe Predictor::InputMatrix do
|
|
123
54
|
|
124
55
|
describe "sets_for" do
|
125
56
|
it "returns the set IDs the given item is in" do
|
126
|
-
@matrix.
|
127
|
-
@matrix.
|
57
|
+
@matrix.add_to_set "item1", ["foo", "bar", "fnord", "blubb"]
|
58
|
+
@matrix.add_to_set "item2", ["foo", "bar", "snafu", "nada"]
|
128
59
|
@matrix.sets_for("foo").should include("item1", "item2")
|
129
60
|
@matrix.sets_for("snafu").should == ["item2"]
|
130
61
|
end
|
@@ -132,9 +63,9 @@ describe Predictor::InputMatrix do
|
|
132
63
|
|
133
64
|
describe "related_items" do
|
134
65
|
it "returns the items in sets the given item is also in" do
|
135
|
-
@matrix.
|
136
|
-
@matrix.
|
137
|
-
@matrix.
|
66
|
+
@matrix.add_to_set "item1", ["foo", "bar", "fnord", "blubb"]
|
67
|
+
@matrix.add_to_set "item2", ["foo", "bar", "snafu", "nada"]
|
68
|
+
@matrix.add_to_set "item3", ["nada", "other"]
|
138
69
|
@matrix.related_items("bar").should include("foo", "fnord", "blubb", "snafu", "nada")
|
139
70
|
@matrix.related_items("bar").length.should == 5
|
140
71
|
@matrix.related_items("other").should == ["nada"]
|
@@ -143,109 +74,48 @@ describe Predictor::InputMatrix do
|
|
143
74
|
end
|
144
75
|
end
|
145
76
|
|
146
|
-
describe "
|
147
|
-
it "should calculate the correct similarity between two items" do
|
148
|
-
add_two_item_test_data!(@matrix)
|
149
|
-
@matrix.process!
|
150
|
-
@matrix.similarity("fnord", "blubb").should == 0.4
|
151
|
-
@matrix.similarity("blubb", "fnord").should == 0.4
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "similarities_for" do
|
156
|
-
it "should calculate all similarities for an item (1/3)" do
|
157
|
-
add_three_item_test_data!(@matrix)
|
158
|
-
@matrix.process!
|
159
|
-
res = @matrix.similarities_for("fnord", with_scores: true)
|
160
|
-
res.length.should == 2
|
161
|
-
res[0].should == ["shmoo", 0.75]
|
162
|
-
res[1].should == ["blubb", 0.4]
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should calculate all similarities for an item (2/3)" do
|
166
|
-
add_three_item_test_data!(@matrix)
|
167
|
-
@matrix.process!
|
168
|
-
res = @matrix.similarities_for("shmoo", with_scores: true)
|
169
|
-
res.length.should == 2
|
170
|
-
res[0].should == ["fnord", 0.75]
|
171
|
-
res[1].should == ["blubb", 0.2]
|
172
|
-
end
|
173
|
-
|
174
|
-
|
175
|
-
it "should calculate all similarities for an item (3/3)" do
|
176
|
-
add_three_item_test_data!(@matrix)
|
177
|
-
@matrix.process!
|
178
|
-
res = @matrix.similarities_for("blubb", with_scores: true)
|
179
|
-
res.length.should == 2
|
180
|
-
res[0].should == ["fnord", 0.4]
|
181
|
-
res[1].should == ["shmoo", 0.2]
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe "delete_item!" do
|
77
|
+
describe "delete_item" do
|
186
78
|
before do
|
187
|
-
@matrix.
|
188
|
-
@matrix.
|
189
|
-
@matrix.
|
190
|
-
@matrix.process!
|
79
|
+
@matrix.add_to_set "item1", "foo", "bar", "fnord", "blubb"
|
80
|
+
@matrix.add_to_set "item2", "foo", "bar", "snafu", "nada"
|
81
|
+
@matrix.add_to_set "item3", "nada", "other"
|
191
82
|
end
|
192
83
|
|
193
84
|
it "should delete the item from sets it is in" do
|
194
85
|
@matrix.items_for("item1").should include("bar")
|
195
86
|
@matrix.items_for("item2").should include("bar")
|
196
87
|
@matrix.sets_for("bar").should include("item1", "item2")
|
197
|
-
@matrix.delete_item
|
88
|
+
@matrix.delete_item("bar")
|
198
89
|
@matrix.items_for("item1").should_not include("bar")
|
199
90
|
@matrix.items_for("item2").should_not include("bar")
|
200
91
|
@matrix.sets_for("bar").should be_empty
|
201
92
|
end
|
202
|
-
|
203
|
-
it "should delete the cached similarities for the item" do
|
204
|
-
@matrix.similarities_for("bar").should_not be_empty
|
205
|
-
@matrix.delete_item!("bar")
|
206
|
-
@matrix.similarities_for("bar").should be_empty
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should delete the item from other cached similarities" do
|
210
|
-
@matrix.similarities_for("foo").should include("bar")
|
211
|
-
@matrix.delete_item!("bar")
|
212
|
-
@matrix.similarities_for("foo").should_not include("bar")
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should delete the item from the all_items set" do
|
216
|
-
@matrix.all_items.should include("bar")
|
217
|
-
@matrix.delete_item!("bar")
|
218
|
-
@matrix.all_items.should_not include("bar")
|
219
|
-
end
|
220
93
|
end
|
221
94
|
|
222
95
|
it "should calculate the correct jaccard index" do
|
223
|
-
@matrix.
|
224
|
-
@matrix.
|
225
|
-
@matrix.
|
226
|
-
|
227
|
-
@matrix.
|
228
|
-
"bar",
|
229
|
-
"snafu"
|
230
|
-
).should == 2.0/3.0
|
96
|
+
@matrix.add_to_set "item1", "foo", "bar", "fnord", "blubb"
|
97
|
+
@matrix.add_to_set "item2", "bar", "fnord", "shmoo", "snafu"
|
98
|
+
@matrix.add_to_set "item3", "bar", "nada", "snafu"
|
99
|
+
|
100
|
+
@matrix.calculate_jaccard("bar", "snafu").should == 2.0/3.0
|
231
101
|
end
|
232
102
|
|
233
103
|
private
|
234
104
|
|
235
105
|
def add_two_item_test_data!(matrix)
|
236
|
-
matrix.
|
237
|
-
matrix.
|
238
|
-
matrix.
|
239
|
-
matrix.
|
240
|
-
matrix.
|
106
|
+
matrix.add_to_set("user42", "fnord", "blubb")
|
107
|
+
matrix.add_to_set("user44", "blubb")
|
108
|
+
matrix.add_to_set("user46", "fnord")
|
109
|
+
matrix.add_to_set("user48", "fnord", "blubb")
|
110
|
+
matrix.add_to_set("user50", "fnord")
|
241
111
|
end
|
242
112
|
|
243
113
|
def add_three_item_test_data!(matrix)
|
244
|
-
matrix.
|
245
|
-
matrix.
|
246
|
-
matrix.
|
247
|
-
matrix.
|
248
|
-
matrix.
|
114
|
+
matrix.add_to_set("user42", "fnord", "blubb", "shmoo")
|
115
|
+
matrix.add_to_set("user44", "blubb")
|
116
|
+
matrix.add_to_set("user46", "fnord", "shmoo")
|
117
|
+
matrix.add_to_set("user48", "fnord", "blubb")
|
118
|
+
matrix.add_to_set("user50", "fnord", "shmoo")
|
249
119
|
end
|
250
120
|
|
251
121
|
end
|
data/spec/predictor_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe Predictor do
|
|
9
9
|
|
10
10
|
it "should raise an exception if unconfigured redis connection is accessed" do
|
11
11
|
Predictor.redis = nil
|
12
|
-
lambda{
|
12
|
+
lambda{ Predictor.redis }.should raise_error(/not configured/i)
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: predictor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pathgather
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -45,10 +45,12 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- Changelog.md
|
48
49
|
- Gemfile
|
49
50
|
- LICENSE
|
50
51
|
- README.md
|
51
52
|
- Rakefile
|
53
|
+
- docs/READMEv1.md
|
52
54
|
- lib/predictor.rb
|
53
55
|
- lib/predictor/base.rb
|
54
56
|
- lib/predictor/input_matrix.rb
|
@@ -74,9 +76,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
76
|
version: '0'
|
75
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
78
|
requirements:
|
77
|
-
- - '
|
79
|
+
- - '>'
|
78
80
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
81
|
+
version: 1.3.1
|
80
82
|
requirements: []
|
81
83
|
rubyforge_project:
|
82
84
|
rubygems_version: 2.1.11
|