recommender-core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af526dd7ce5518845a6ddb738193919ccebe7879
4
+ data.tar.gz: 96686cf178180de62daca570e3b767a6f003a686
5
+ SHA512:
6
+ metadata.gz: 8c63fe907f43f18c3d70beab4cbfa63bec7eaf336fb5872434e87867dcfb0b5d08fb92b0b3cd4ee1b47e985a95654c99c424de1ce494339fa7377cb2dc1d2e9a
7
+ data.tar.gz: 11c3fa7c623aaeac45dcfcb99c1426a619db40014eb0f160ee0de0aaeea3925d118889ae31f1a35ef82de342c58b3887c0a54cc7b65071bc07bac80416d06b5d
data/.autotest ADDED
@@ -0,0 +1,9 @@
1
+ require 'autotest/fsevent'
2
+
3
+ class Autotest::Rspec2 < Autotest
4
+ def make_test_cmd(files_to_test)
5
+ files_to_test.empty? ? '' :
6
+ "#{prefix}#{ruby}#{suffix} --ng -S '#{RSPEC_EXECUTABLE}' --tty \
7
+ #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
8
+ end
9
+ end
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '1.9.3', :engine => 'jruby', :engine_version => '1.7.12'
4
+ gem 'autotest'
5
+ gem 'autotest-fsevent'
6
+ gem 'ZenTest'
7
+ gem 'autotest-spec'
8
+
9
+ platform :jruby do
10
+ gem 'jruby_mahout'
11
+ end
12
+ # Specify your gem's dependencies in recommender_core.gemspec
13
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # RecommenderCore
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'recommender_core'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install recommender_core
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/recommender_core/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,64 @@
1
+ require 'jruby_mahout'
2
+
3
+ class RecommenderCore::Handler
4
+
5
+ def self.similar_users(params)
6
+ recommender = init_recommender(params[:hash])
7
+ recommender.similar_users(params[:id], params[:nb_wanted], params[:rescorer])
8
+ end
9
+
10
+ def self.similar_items(params)
11
+ recommender = init_recommender(params[:hash])
12
+ recommender.similar_items(params[:id], params[:nb_wanted], params[:rescorer])
13
+ end
14
+
15
+ def self.recommend_items(params)
16
+ recommender = init_recommender(params[:hash])
17
+ recommender.recommend(params[:id], params[:nb_wanted], params[:rescorer])
18
+ end
19
+
20
+ def self.evaluate(params)
21
+ recommender = init_recommender(params[:hash])
22
+ recommender.evaluate(params[:training_prcentage], params[:eval_prcentage])
23
+ end
24
+
25
+
26
+ def self.estimate_preference(params)
27
+ recommender = init_recommender(params[:hash])
28
+ recommender.estimate_preference(params[:user_id], params[:item_id])
29
+ end
30
+
31
+ private #################################
32
+
33
+ def self.tell_to_do()
34
+ end
35
+
36
+ def self.respond_to()
37
+ end
38
+
39
+ def self.init_recommender(params)
40
+ recommender = JrubyMahout::Recommender.new(params[:similarity_metric], params[:neighborhood], params[:recommender_algo], true)
41
+ file = data_to_csv(params[:engine_data])
42
+ recommender.data_model = JrubyMahout::DataModel.new('file', {file_path: file.path}).data_model
43
+ free_file(file.path)
44
+ recommender
45
+ end
46
+
47
+ def self.data_to_csv(engine_data)
48
+ file = File.new(return_tmp_path, "w+")
49
+ return nil unless file
50
+ engine_data.each do |row|
51
+ file.puts "#{row[:customer_id]},#{row[:item_id]},#{row[:preference]}"
52
+ end
53
+ file.rewind
54
+ file
55
+ end
56
+
57
+ def self.free_file(file)
58
+ File.delete(file)
59
+ end
60
+
61
+ def self.return_tmp_path
62
+ 'tmp/' + Time.now.to_s + ".csv"
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module RecommenderCore
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "recommender_core/version"
2
+ require 'recommender_core/handler'
3
+
4
+ module RecommenderCore
5
+ # Your code goes here...
6
+ class Handler
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'recommender_core/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "recommender-core"
8
+ spec.version = RecommenderCore::VERSION
9
+ spec.authors = ["atacraft & fabira"]
10
+ spec.email = ["atacraft@gmail.com"]
11
+ spec.summary = %q{The core module of the recommender}
12
+ spec.description = %q{This one is responsible of interactions with mahout}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,41 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe RecommenderCore::Handler do
4
+ let(:engine_data) { engine_data_sample }
5
+ let(:hash_user_based) { { similarity_metric: 'PearsonCorrelationSimilarity', neighborhood: 5, recommender_algo: 'GenericUserBasedRecommender', engine_data: engine_data } }
6
+ let(:hash_item_based) { { similarity_metric: 'PearsonCorrelationSimilarity', neighborhood: 5, recommender_algo: 'GenericItemBasedRecommender', engine_data: engine_data } }
7
+ let(:params_user_based) { {hash: hash_user_based, id: 1, nb_wanted: 2, rescorer: nil} }
8
+ let(:params_item_based) { {hash: hash_item_based, id: 1, nb_wanted: 2, rescorer: nil} }
9
+ let(:evaluation) { {hash: hash_item_based, training_prcentage: 0.7, eval_prcentage: 0.3} }
10
+ let(:estimation) { {hash: hash_user_based, user_id: 1, item_id: 3} }
11
+
12
+ describe ".init_recommender" do
13
+ it { expect(RecommenderCore::Handler.init_recommender(hash_user_based)).to_not be_nil }
14
+ it { expect(RecommenderCore::Handler.init_recommender(hash_item_based).class).to eq(JrubyMahout::Recommender) }
15
+ it { expect(RecommenderCore::Handler.init_recommender(hash_user_based).data_model).to_not be_nil }
16
+ end
17
+
18
+ describe ".data_to_csv" do
19
+ it { expect(RecommenderCore::Handler.data_to_csv(engine_data).class).to eq(File) }
20
+ end
21
+
22
+ describe '.similar_users' do
23
+ it { expect(RecommenderCore::Handler.similar_users(params_user_based)).to_not be_nil }
24
+ end
25
+
26
+ describe '.similar_items' do
27
+ it { expect(RecommenderCore::Handler.similar_items(params_item_based)).to_not be_nil }
28
+ end
29
+
30
+ describe '.recommend_items' do
31
+ it { expect(RecommenderCore::Handler.recommend_items(params_item_based)).to_not be_nil }
32
+ end
33
+
34
+ describe '.evaluate' do
35
+ it { expect(RecommenderCore::Handler.evaluate(evaluation)).to_not be_nil }
36
+ end
37
+
38
+ describe '.estimate_preference' do
39
+ it { expect(RecommenderCore::Handler.estimate_preference(estimation)).to_not be_nil }
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ require 'recommender_core'
2
+
3
+ def engine_data_sample
4
+ engine_data = []
5
+ engine_data << {customer_id: 1, item_id: 1, preference: 1}
6
+
7
+ 10000.times do
8
+ engine_data << { customer_id: rand(1..5), item_id: rand(1..10), preference: rand(1..5) }
9
+ end
10
+ engine_data
11
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: recommender-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - atacraft & fabira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :development
55
+ description: This one is responsible of interactions with mahout
56
+ email:
57
+ - atacraft@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .autotest
63
+ - .gitignore
64
+ - .rspec
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/recommender_core.rb
70
+ - lib/recommender_core/handler.rb
71
+ - lib/recommender_core/version.rb
72
+ - recommender_core.gemspec
73
+ - spec/handler_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: The core module of the recommender
99
+ test_files:
100
+ - spec/handler_spec.rb
101
+ - spec/spec_helper.rb