similus 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ $: << File.join(File.dirname(__FILE__), "/../lib")
2
+ require 'similus'
3
+
4
+ describe "Similus" do
5
+ before(:all) do
6
+ # Clear redis
7
+ Similus.clear_database!
8
+
9
+ Similus.add_activity(["User", 1], :view, ["Movie", "Star Wars 1"])
10
+ Similus.add_activity(["User", 1], :view, ["Movie", "Star Wars 2"])
11
+ Similus.add_activity(["User", 1], :view, ["Movie", "Star Wars 3"])
12
+ Similus.add_activity(["User", 1], :view, ["Movie", "Star Wars 4"])
13
+
14
+ Similus.add_activity(["User", 2], :view, ["Movie", "Star Wars 3"])
15
+ Similus.add_activity(["User", 2], :view, ["Movie", "Star Wars 4"])
16
+ Similus.add_activity(["User", 2], :view, ["Movie", "Star Wars 5"])
17
+
18
+ Similus.add_activity(["User", 3], :view, ["Movie", "Star Wars 1"])
19
+ Similus.add_activity(["User", 3], :view, ["Movie", "Star Wars 3"])
20
+ Similus.add_activity(["User", 3], :view, ["Movie", "Star Wars 5"])
21
+
22
+ Similus.add_activity(["User", 4], :view, ["Movie", "Star Wars 2"])
23
+ Similus.add_activity(["User", 4], :view, ["Movie", "Star Wars 3"])
24
+
25
+ Similus.add_activity(["User", 5], :view, ["Movie", "Star Wars 1"])
26
+ Similus.add_activity(["User", 5], :view, ["Movie", "Star Wars 2"])
27
+ Similus.add_activity(["User", 5], :view, ["Movie", "Star Wars 3"])
28
+ Similus.add_activity(["User", 5], :view, ["Movie", "Blade Runner"])
29
+
30
+ Similus.add_activity(["User", 6], :view, ["Movie", "Star Wars 1"])
31
+ Similus.add_activity(["User", 6], :view, ["Movie", "Star Wars 5"])
32
+ Similus.add_activity(["User", 6], :view, ["Movie", "Blade Runner"])
33
+
34
+ Similus.add_activity(["User", 7], :view, ["Movie", "Casablanca"])
35
+ end
36
+
37
+ describe "#similar_to" do
38
+ describe "User 1" do
39
+ before(:all) do
40
+ @similar_to_user_1 = Similus.similar_to(["User", 1])
41
+ end
42
+
43
+ it "should be most similar to user 5 with score of 3.0" do
44
+ @similar_to_user_1.first[:id].should == "5"
45
+ @similar_to_user_1.first[:score].should == 3.0
46
+ end
47
+
48
+ it "should not include itself" do
49
+ @similar_to_user_1.detect { |x| x[:id] == "1" }.should be_nil
50
+ end
51
+
52
+ it "should not be similar to users with just 1 similarity" do
53
+ @similar_to_user_1.detect { |x| x[:id] == "6" }.should be_nil
54
+ end
55
+
56
+ it "should be similar to users even if they will not have new recommendations" do
57
+ @similar_to_user_1.detect { |x| x[:id] == "4" }.should_not be_nil
58
+ end
59
+
60
+ it "should be similar to users 2, 3 and 4 with 2 similarities " do
61
+ @similar_to_user_1.select { |x| x[:score] == 2.0 }.size.should == 3
62
+ end
63
+ end
64
+
65
+ describe "the other users" do
66
+ before(:all) do
67
+ @similar_to_user_2 = Similus.similar_to(["User", 2])
68
+ @similar_to_user_3 = Similus.similar_to(["User", 3])
69
+ @similar_to_user_4 = Similus.similar_to(["User", 4])
70
+ @similar_to_user_5 = Similus.similar_to(["User", 5])
71
+ @similar_to_user_6 = Similus.similar_to(["User", 6])
72
+ @similar_to_user_7 = Similus.similar_to(["User", 7])
73
+ end
74
+
75
+ it "shall have the expected similarities and scores for the rest of users" do
76
+ @similar_to_user_2.size.should == 2
77
+ @similar_to_user_2.select { |x| x[:score] == 2.0 }.size.should == 2
78
+ @similar_to_user_2.select { |x| %w(1 3).include? x[:id]}.size.should == 2
79
+
80
+ @similar_to_user_3.size.should == 4
81
+ @similar_to_user_3.select { |x| %w(1 2 5 6).include? x[:id]}.size.should == 4
82
+ @similar_to_user_3.select { |x| x[:score] == 2.0}.size.should == 4
83
+
84
+ @similar_to_user_4.size.should == 2
85
+ @similar_to_user_4.select { |x| %w(1 5).include? x[:id]}.size.should == 2
86
+ @similar_to_user_4.select { |x| x[:score] == 2.0}.size.should == 2
87
+
88
+ @similar_to_user_5.first[:score].should == 3.0
89
+ @similar_to_user_5.size.should == 4
90
+ @similar_to_user_5.select { |x| %w(1 3 4 6).include? x[:id]}.size.should == 4
91
+ @similar_to_user_5.select { |x| x[:score] == 2.0}.size.should == 3
92
+
93
+ @similar_to_user_6.size.should == 2
94
+ @similar_to_user_6.select { |x| %w(3 5).include? x[:id]}.size.should == 2
95
+ @similar_to_user_6.select { |x| x[:score] == 2.0}.size.should == 2
96
+ end
97
+
98
+ it "shall have no similarities for user 7" do
99
+ @similar_to_user_7.size.should == 0
100
+ end
101
+ end
102
+ end
103
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: similus
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Horaci Cuevas
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDLjCCAhagAwIBAgIBADANBgkqhkiG9w0BAQUFADA9MQ8wDQYDVQQDDAZob3Jh
19
+ Y2kxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2NvbTAe
20
+ Fw0xMDEwMDcxMzEwMDlaFw0xMTEwMDcxMzEwMDlaMD0xDzANBgNVBAMMBmhvcmFj
21
+ aTEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29tMIIB
22
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApLeu332eDpZ0g8mxNx9UPkr8
23
+ qG/bywvNXYjMpuHaSRgDDKP4fUGmGXy9A+y4CSYD6u2+zRCY/KdS9b+d077aGy3F
24
+ KDhSUx7mXYRO5dWvGWcj/nTTANLxQsDzS/JVL2LcWQDym0m24XquFmbiLRCikhmM
25
+ X7Kcmgo6cB2D0iUW5MTqFaSCkKkl0/KR3BUJ9bbRPQhDKke2Nyg4xz6Hmg1Ju69F
26
+ mJqGseYLRC2VxRhdJwl/ZwWvSA5C3ulrTozgTHkhhjmX20XWxpv6uTdSPk4MLYqv
27
+ dVjswl7X7Rm5XiJm9bVJnAoU4/k/X39mEIKIKcqe18oqwB0+O5USrt4W4Pc7DwID
28
+ AQABozkwNzAJBgNVHRMEAjAAMB0GA1UdDgQWBBSivbT4vUH86eE+g8HjLB9fb5pa
29
+ yjALBgNVHQ8EBAMCBLAwDQYJKoZIhvcNAQEFBQADggEBAFHTHc8/ntUrSGG6O6fZ
30
+ PPhPIzCDEp2qhpENsnJPBy4XYrHFGK8PDo1Qoi07SbqeQ+hgMVm9nQ3vZtOjQvx/
31
+ Qcm4q2DRKBNhAPYlEjyAvymzmbXNJb8QOA+5Jzs5Xa0knokGjYO0w6sw6pDZPOQg
32
+ YzWSRpnQxTgFbYZ4InqRfv1KU5urF3itsSSoChpVarloBW0M0ppcbnOip1Qj3IfU
33
+ Yn8bclUd5GoR/ZaSO9iXG7GkkczwwUI6d8esL6BXvZEUSiDC//xgYZUEb8lEDAJB
34
+ hv4MxrZjuDQ4zRtLTMV1+7761io+Ikp8UWLybRkOkq/t8oFMHsRvBkOAK7nFXdrD
35
+ BJ0=
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2010-10-07 00:00:00 +02:00
39
+ default_executable:
40
+ dependencies: []
41
+
42
+ description: A ruby library to find similar objects and make recommendations based on activity of objects
43
+ email: horaci @@ gmail.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - LICENSES
50
+ - README.rdoc
51
+ - lib/similus.rb
52
+ - lib/similus/config.rb
53
+ - lib/similus/core.rb
54
+ - lib/similus/redis.rb
55
+ files:
56
+ - LICENSES
57
+ - README.rdoc
58
+ - Rakefile
59
+ - benchmarks/benchmark1.rb
60
+ - benchmarks/benchmark2.rb
61
+ - benchmarks/custom_benchmark.rb
62
+ - benchmarks/redis.conf
63
+ - init.rb
64
+ - lib/similus.rb
65
+ - lib/similus/config.rb
66
+ - lib/similus/core.rb
67
+ - lib/similus/redis.rb
68
+ - test/add_activity_spec.rb
69
+ - test/recommended_spec.rb
70
+ - test/similar_spec.rb
71
+ - Manifest
72
+ - similus.gemspec
73
+ has_rdoc: true
74
+ homepage: http://github.com/horaci/similus
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --line-numbers
80
+ - --inline-source
81
+ - --title
82
+ - Similus
83
+ - --main
84
+ - README.rdoc
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 1
102
+ - 2
103
+ version: "1.2"
104
+ requirements: []
105
+
106
+ rubyforge_project: similus
107
+ rubygems_version: 1.3.7
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A ruby library to find similar objects and make recommendations based on activity of objects
111
+ test_files: []
112
+
Binary file