Module: Recommendify::CCMatrix

Included in:
CosineInputMatrix, JaccardInputMatrix
Defined in:
lib/recommendify/cc_matrix.rb

Instance Method Summary collapse

Instance Method Details

#add_set(set_id, item_ids) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/recommendify/cc_matrix.rb', line 10

def add_set(set_id, item_ids)
  # FIXPAUL: forbid | and : in item_ids
  item_ids.each do |item_id|
    item_count_incr(item_id)
  end
  all_pairs(item_ids).map do |pair| 
    i1, i2 = pair.split(":") 
    ccmatrix.incr(i1, i2)
  end
end

#add_single(set_id, item_id, other_item_ids) ⇒ Object



21
22
23
24
25
26
# File 'lib/recommendify/cc_matrix.rb', line 21

def add_single(set_id, item_id, other_item_ids)
  item_count_incr(item_id)
  other_item_ids.each do |other_item|
    ccmatrix.incr(item_id, other_item)
  end
end

#all_itemsObject



28
29
30
# File 'lib/recommendify/cc_matrix.rb', line 28

def all_items
  Recommendify.redis.hkeys(redis_key(:items))
end

#ccmatrixObject



3
4
5
6
7
8
# File 'lib/recommendify/cc_matrix.rb', line 3

def ccmatrix
  @ccmatrix ||= Recommendify::SparseMatrix.new(
    :redis_prefix => @opts.fetch(:redis_prefix),
    :key => [@opts.fetch(:key), :ccmatrix].join(":")
  )
end

#delete_item(item_id) ⇒ Object



32
33
34
35
# File 'lib/recommendify/cc_matrix.rb', line 32

def delete_item(item_id)    
  Recommendify.redis.hdel(redis_key(:items), item_id)
  ccmatrix.send(:k_delall, item_id)
end