Class: Recommendify::InputMatrix
- Inherits:
-
Object
- Object
- Recommendify::InputMatrix
- Defined in:
- lib/recommendify/input_matrix.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#add_set(set_id, item_ids) ⇒ Object
add a set of item_ids to the matrix.
-
#add_single(set_id, item_id, other_item_ids) ⇒ Object
add a single item to a set of item_ids to the matrix.
-
#all_items ⇒ Object
retrieve all item_ids in the matrix.
-
#delete_item(item_id) ⇒ Object
delete item_id from the matrix.
-
#initialize(opts) ⇒ InputMatrix
constructor
A new instance of InputMatrix.
- #redis_key(append = nil) ⇒ Object
-
#similarities_for(item1) ⇒ Object
calculate all similarities to other items in the matrix for item1.
-
#similarity(item1, item2) ⇒ Object
calculate the similarity between item1 and item1 (0.0-1.0).
- #weight ⇒ Object
Constructor Details
#initialize(opts) ⇒ InputMatrix
Returns a new instance of InputMatrix.
8 9 10 |
# File 'lib/recommendify/input_matrix.rb', line 8 def initialize(opts) @opts = opts end |
Class Method Details
.create(opts) ⇒ Object
3 4 5 6 |
# 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 |
Instance Method Details
#add_set(set_id, item_ids) ⇒ Object
add a set of item_ids to the matrix
21 22 23 |
# 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) ⇒ Object
add a single item to a set of item_ids to the matrix
26 27 28 |
# 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 ⇒ Object
retrieve all item_ids in the matrix
42 43 44 45 |
# File 'lib/recommendify/input_matrix.rb', line 42 def all_items # retzrb => [ "item23", "item42", "item17", (...) ] raise "implemented in subclass" end |
#delete_item(item_id) ⇒ Object
delete item_id from the matrix
48 49 50 |
# File 'lib/recommendify/input_matrix.rb', line 48 def delete_item(item_id) raise "implemented in subclass" end |
#redis_key(append = nil) ⇒ Object
12 13 14 |
# 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) ⇒ Object
calculate all similarities to other items in the matrix for item1
36 37 38 39 |
# 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) ⇒ Object
calculate the similarity between item1 and item1 (0.0-1.0)
31 32 33 |
# File 'lib/recommendify/input_matrix.rb', line 31 def similarity(item1, item2) raise "implemented in subclass" end |
#weight ⇒ Object
16 17 18 |
# File 'lib/recommendify/input_matrix.rb', line 16 def weight (@opts[:weight] || 1).to_f end |