From 3d876a3599362abcada6790386ca8caa2c843589 Mon Sep 17 00:00:00 2001 From: Paul Asmuth Date: Sun, 29 Jan 2012 21:11:41 +0100 Subject: [PATCH] scaffold --- Gemfile | 7 +++++++ Gemfile.lock | 22 ++++++++++++++++++++++ Rakefile | 12 ++++++++++++ lib/recommendify.rb | 4 ++++ lib/recommendify/jaccard_processor.rb | 7 +++++++ lib/recommendify/similarity_matrix.rb | 7 +++++++ spec/similarity_matrix_spec.rb | 6 ++++++ spec/spec_helper.rb | 2 ++ test.rb | 17 ++++++++++++----- 9 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile create mode 100644 lib/recommendify.rb create mode 100644 lib/recommendify/jaccard_processor.rb create mode 100644 lib/recommendify/similarity_matrix.rb create mode 100644 spec/similarity_matrix_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d21bea7 --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +source :rubygems + +group :development do + gem "rake" + gem "rspec" + gem "yard" +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..08cfb06 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,22 @@ +GEM + remote: http://rubygems.org/ + specs: + diff-lcs (1.1.3) + rake (0.9.2.2) + rspec (2.8.0) + rspec-core (~> 2.8.0) + rspec-expectations (~> 2.8.0) + rspec-mocks (~> 2.8.0) + rspec-core (2.8.0) + rspec-expectations (2.8.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.8.0) + yard (0.7.4) + +PLATFORMS + ruby + +DEPENDENCIES + rake + rspec + yard diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..9988620 --- /dev/null +++ b/Rakefile @@ -0,0 +1,12 @@ +require "rubygems" +require "rspec" +require 'rspec/core/rake_task' +require "yard" + +desc "Run all examples" +task RSpec::Core::RakeTask.new('spec') + +task :default => "spec" + +desc "Generate documentation" +task YARD::Rake::YardocTask.new diff --git a/lib/recommendify.rb b/lib/recommendify.rb new file mode 100644 index 0000000..88ab3ab --- /dev/null +++ b/lib/recommendify.rb @@ -0,0 +1,4 @@ +module Recommendify; end + +require "recommendify/similarity_matrix" +require "recommendify/jaccard_processor" \ No newline at end of file diff --git a/lib/recommendify/jaccard_processor.rb b/lib/recommendify/jaccard_processor.rb new file mode 100644 index 0000000..ad63cbd --- /dev/null +++ b/lib/recommendify/jaccard_processor.rb @@ -0,0 +1,7 @@ +class Recommendify::JaccardProcessor + + def initialize(opts={}) + + end + +end \ No newline at end of file diff --git a/lib/recommendify/similarity_matrix.rb b/lib/recommendify/similarity_matrix.rb new file mode 100644 index 0000000..07e6604 --- /dev/null +++ b/lib/recommendify/similarity_matrix.rb @@ -0,0 +1,7 @@ +class Recommendify::SimilarityMatrix + + def self.method_missing(method, *args) + puts method + end + +end \ No newline at end of file diff --git a/spec/similarity_matrix_spec.rb b/spec/similarity_matrix_spec.rb new file mode 100644 index 0000000..804b790 --- /dev/null +++ b/spec/similarity_matrix_spec.rb @@ -0,0 +1,6 @@ +require ::File.expand_path('../spec_helper', __FILE__) + +describe Recommendify::SimilarityMatrix do + + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..8d3083a --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require "rspec" +require ::File.expand_path('../../lib/recommendify', __FILE__) \ No newline at end of file diff --git a/test.rb b/test.rb index be713d5..0819fc0 100644 --- a/test.rb +++ b/test.rb @@ -1,8 +1,14 @@ +$: << ::File.expand_path("../lib", __FILE__) +require "recommendify" -class RecommendedProfiles < Recommendify::Base +class UserRecommender < Recommendify::SimilarityMatrix + + max_neighbors 50 + + processor :visits, + :similarity_func => :jaccard end -RecommendedProfiles.reset_matrix! buckets = Hash.new{ |h,k| h[k]=[] } @@ -12,8 +18,9 @@ class RecommendedProfiles < Recommendify::Base end buckets.each do |user_id, items| - puts "#{user_id} -> #{items.join(",")}" - RecommendedProfiles.add_interactions(items) + next if user_id.length == 0 + puts "#{user_id} -> #{items.join(",")}" + UserRecommender.visits.add_set(user_id, items) end -RecommededProfiles.process! +UserRecommender.process!