simple_recommender 0.0.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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +34 -0
- data/lib/simple_recommender.rb +5 -0
- data/lib/simple_recommender/recommendable.rb +91 -0
- data/lib/simple_recommender/version.rb +3 -0
- data/lib/tasks/simple_recommender_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/book.rb +10 -0
- data/test/dummy/app/models/like.rb +4 -0
- data/test/dummy/app/models/tag.rb +2 -0
- data/test/dummy/app/models/user.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +13 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +32 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +85 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/migrate/20170123001813_create_books.rb +9 -0
- data/test/dummy/db/migrate/20170123001819_create_users.rb +9 -0
- data/test/dummy/db/migrate/20170123001909_create_books_users.rb +11 -0
- data/test/dummy/db/migrate/20170123010745_enable_int_array_extension.rb +5 -0
- data/test/dummy/db/migrate/20170125030342_create_tags.rb +9 -0
- data/test/dummy/db/migrate/20170125030446_create_likes.rb +10 -0
- data/test/dummy/db/migrate/20170125032813_add_author_to_books.rb +5 -0
- data/test/dummy/db/migrate/20170125034331_create_books_tags.rb +8 -0
- data/test/dummy/db/migrate/20170125034341_remove_books_users.rb +5 -0
- data/test/dummy/db/schema.rb +63 -0
- data/test/dummy/log/development.log +511 -0
- data/test/dummy/log/test.log +5624 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/models/book_test.rb +77 -0
- data/test/dummy/test/models/like_test.rb +7 -0
- data/test/dummy/test/models/tag_test.rb +7 -0
- data/test/dummy/test/models/user_test.rb +7 -0
- data/test/fixtures/books.yml +29 -0
- data/test/fixtures/likes.yml +57 -0
- data/test/fixtures/tags.yml +19 -0
- data/test/fixtures/users.yml +19 -0
- data/test/simple_recommender_test.rb +7 -0
- data/test/test_helper.rb +20 -0
- metadata +199 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BookTest < ActiveSupport::TestCase
|
4
|
+
describe BookTest do
|
5
|
+
|
6
|
+
describe "#similar_by" do
|
7
|
+
let(:book) { Book.first }
|
8
|
+
|
9
|
+
it "returns a result for a has_many through association" do
|
10
|
+
assert book.similar_by(:users)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns a result for a has_and_belongs_to_many association" do
|
14
|
+
assert book.similar_by(:tags)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "raises an ArgumentError for an invalid association type" do
|
18
|
+
assert_raises ArgumentError do
|
19
|
+
book.similar_by(:author)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "convenience methods" do
|
25
|
+
it "defines a convenience method for a has_and_belongs_to_many association" do
|
26
|
+
assert_equal true, Book.first.respond_to?(:similar_by_tags)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "defines a convenience method for a has_many through association" do
|
30
|
+
assert_equal true, Book.first.respond_to?(:similar_by_users)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not define a convenience method for an invalid association type" do
|
34
|
+
assert_equal false, Book.first.respond_to?(:similar_by_authors)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:python_book) { Book.find_by(name: "Learning Python") }
|
39
|
+
let(:ruby_book) { Book.find_by(name: "Learning Ruby") }
|
40
|
+
let(:cpp_book) { Book.find_by(name: "Learning C++") }
|
41
|
+
let(:violin_book) { Book.find_by(name: "Playing Violin") }
|
42
|
+
|
43
|
+
describe "#similar_by_tags" do
|
44
|
+
let(:n_results) { 3 }
|
45
|
+
subject { python_book.similar_by_tags(n_results: n_results) }
|
46
|
+
|
47
|
+
it "returns similar books" do
|
48
|
+
assert_equal [ruby_book, cpp_book, violin_book], subject
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns similarity scores" do
|
52
|
+
expected_similarities = [1.0, (2.0/3), (1.0/4)]
|
53
|
+
|
54
|
+
expected_similarities.zip(subject.map(&:similarity)).each do |expected, actual|
|
55
|
+
assert_in_delta expected, actual, 0.01
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#similar_by_users" do
|
61
|
+
let(:n_results) { 3 }
|
62
|
+
subject { python_book.similar_by_users(n_results: n_results) }
|
63
|
+
|
64
|
+
it "returns similar books" do
|
65
|
+
assert_equal [ruby_book, cpp_book, violin_book], subject
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns similarity scores" do
|
69
|
+
expected_similarities = [1.0, (1.0/3), (1.0/3)]
|
70
|
+
|
71
|
+
expected_similarities.zip(subject.map(&:similarity)).each do |expected, actual|
|
72
|
+
assert_in_delta expected, actual, 0.01
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
2
|
+
|
3
|
+
harry_potter:
|
4
|
+
name: Harry Potter
|
5
|
+
tags: fiction, fantasy
|
6
|
+
|
7
|
+
lotr:
|
8
|
+
name: Lord of the Rings
|
9
|
+
tags: fiction, fantasy
|
10
|
+
|
11
|
+
great_expectations:
|
12
|
+
name: Great Expectations
|
13
|
+
tags: fiction
|
14
|
+
|
15
|
+
learning_ruby:
|
16
|
+
name: Learning Ruby
|
17
|
+
tags: nonfiction, programming, scripting
|
18
|
+
|
19
|
+
learning_python:
|
20
|
+
name: Learning Python
|
21
|
+
tags: nonfiction, programming, scripting
|
22
|
+
|
23
|
+
learning_cpp:
|
24
|
+
name: Learning C++
|
25
|
+
tags: nonfiction, programming
|
26
|
+
|
27
|
+
playing_violin:
|
28
|
+
name: Playing Violin
|
29
|
+
tags: nonfiction, music
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
2
|
+
|
3
|
+
a:
|
4
|
+
user: fiction_fred
|
5
|
+
book: harry_potter
|
6
|
+
|
7
|
+
b:
|
8
|
+
user: fiction_fred
|
9
|
+
book: lotr
|
10
|
+
|
11
|
+
c:
|
12
|
+
user: fiction_fanny
|
13
|
+
book: harry_potter
|
14
|
+
|
15
|
+
d:
|
16
|
+
user: fiction_fanny
|
17
|
+
book: great_expectations
|
18
|
+
|
19
|
+
e:
|
20
|
+
user: fiction_fil
|
21
|
+
book: lotr
|
22
|
+
|
23
|
+
f:
|
24
|
+
user: fiction_fil
|
25
|
+
book: great_expectations
|
26
|
+
|
27
|
+
g:
|
28
|
+
user: programmer_paulina
|
29
|
+
book: learning_ruby
|
30
|
+
|
31
|
+
h:
|
32
|
+
user: programmer_paulina
|
33
|
+
book: learning_python
|
34
|
+
|
35
|
+
i:
|
36
|
+
user: programmer_paul
|
37
|
+
book: learning_ruby
|
38
|
+
|
39
|
+
j:
|
40
|
+
user: programmer_paul
|
41
|
+
book: learning_python
|
42
|
+
|
43
|
+
k:
|
44
|
+
user: programmer_paul
|
45
|
+
book: learning_cpp
|
46
|
+
|
47
|
+
l:
|
48
|
+
user: programmer_paige
|
49
|
+
book: learning_ruby
|
50
|
+
|
51
|
+
m:
|
52
|
+
user: programmer_paige
|
53
|
+
book: learning_python
|
54
|
+
|
55
|
+
n:
|
56
|
+
user: programmer_paige
|
57
|
+
book: playing_violin
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
2
|
+
|
3
|
+
fiction:
|
4
|
+
name: Fiction
|
5
|
+
|
6
|
+
nonfiction:
|
7
|
+
name: Nonfiction
|
8
|
+
|
9
|
+
fantasy:
|
10
|
+
name: Fantasy
|
11
|
+
|
12
|
+
programming:
|
13
|
+
name: programming
|
14
|
+
|
15
|
+
scripting:
|
16
|
+
name: scripting
|
17
|
+
|
18
|
+
music:
|
19
|
+
name: music
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
2
|
+
|
3
|
+
fiction_fred:
|
4
|
+
name: Fiction Fred
|
5
|
+
|
6
|
+
fiction_fanny:
|
7
|
+
name: Fiction Fanny
|
8
|
+
|
9
|
+
fiction_fil:
|
10
|
+
name: Fiction Fil
|
11
|
+
|
12
|
+
programmer_paulina:
|
13
|
+
name: Programmer Paulina
|
14
|
+
|
15
|
+
programmer_paul:
|
16
|
+
name: Programmer Paul
|
17
|
+
|
18
|
+
programmer_paige:
|
19
|
+
name: Programmer Paige
|