class Recommendify::InputMatrix

Public Class Methods

create(opts) click to toggle source
# File lib/recommendify/input_matrix.rb, line 3
def self.create(opts)
  klass = "#{Recommendify.capitalize(opts[:similarity_func])}InputMatrix"
  Recommendify.constantize(klass.intern).new(opts)
end
new(opts) click to toggle source
# File lib/recommendify/input_matrix.rb, line 8
def initialize(opts)
  @opts = opts
end

Public Instance Methods

add_set(set_id, item_ids) click to toggle source

add a set of item_ids to the matrix

# File lib/recommendify/input_matrix.rb, line 21
def add_set(set_id, item_ids)
  raise "implemented in subclass"
end
add_single(set_id, item_id, other_item_ids) click to toggle source

add a single item to a set of item_ids to the matrix

# File lib/recommendify/input_matrix.rb, line 26
def add_single(set_id, item_id, other_item_ids)
  raise "implemented in subclass"
end
all_items() click to toggle source

retrieve all item_ids in the matrix

# File lib/recommendify/input_matrix.rb, line 42
def all_items
  # retzrb => [ "item23", "item42", "item17", (...) ]
  raise "implemented in subclass"
end
delete_item(item_id) click to toggle source

delete item_id from the matrix

# File lib/recommendify/input_matrix.rb, line 48
def delete_item(item_id)
  raise "implemented in subclass"
end
redis_key(append=nil) click to toggle source
# File lib/recommendify/input_matrix.rb, line 12
def redis_key(append=nil)
  [@opts.fetch(:redis_prefix), @opts.fetch(:key), append].flatten.compact.join(":")
end
similarities_for(item1) click to toggle source

calculate all similarities to other items in the matrix for item1

# File lib/recommendify/input_matrix.rb, line 36
def similarities_for(item1)
  # return => [ ["item23", 0.6], ["item42", 0.23], (...) ]
  raise "implemented in subclass"
end
similarity(item1, item2) click to toggle source

calculate the similarity between item1 and item1 (0.0-1.0)

# File lib/recommendify/input_matrix.rb, line 31
def similarity(item1, item2)
  raise "implemented in subclass"
end
weight() click to toggle source
# File lib/recommendify/input_matrix.rb, line 16
def weight
  (@opts[:weight] || 1).to_f
end