Module: Suggestor::Algorithms::RecommendationAlgorithm
- Included in:
- EuclideanDistance, PearsonCorrelation
- Defined in:
- lib/suggestor/algorithms/recommendation_algorithm.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
Instance Method Summary collapse
- #initialize(collection) ⇒ Object
- #no_shared_items_between?(first, second) ⇒ Boolean
-
#recommented_related_items_for(main) ⇒ Object
returns recommended related items for the main user The most important feature.
- #shared_items_between(first, second) ⇒ Object
-
#similar_items_to(main) ⇒ Object
returns similar items based on their similary score for example, similar users based on their movies reviews.
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
5 6 7 |
# File 'lib/suggestor/algorithms/recommendation_algorithm.rb', line 5 def collection @collection end |
Instance Method Details
#initialize(collection) ⇒ Object
7 8 9 |
# File 'lib/suggestor/algorithms/recommendation_algorithm.rb', line 7 def initialize(collection) @collection = collection end |
#no_shared_items_between?(first, second) ⇒ Boolean
40 41 42 |
# File 'lib/suggestor/algorithms/recommendation_algorithm.rb', line 40 def no_shared_items_between?(first,second) shared_items_between(first,second).empty? end |
#recommented_related_items_for(main) ⇒ Object
returns recommended related items for the main user The most important feature. For example, a user will get movie recommendations based on his past movie reviews and how it compares with others
30 31 32 33 34 35 36 37 38 |
# File 'lib/suggestor/algorithms/recommendation_algorithm.rb', line 30 def (main) @similarities = @totals = Hash.new(0) @main = main create_similarities_totals generate_rankings end |
#shared_items_between(first, second) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/suggestor/algorithms/recommendation_algorithm.rb', line 44 def shared_items_between(first,second) return [] unless values_for(first) && values_for(second) (first).select do |item| (second).include? item end end |
#similar_items_to(main) ⇒ Object
returns similar items based on their similary score for example, similar users based on their movies reviews
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/suggestor/algorithms/recommendation_algorithm.rb', line 13 def similar_items_to(main) #just compare those whore aren't the main item compare_to = collection.dup compare_to.delete(main) # return results based on their score compare_to.keys.inject({}) do |result, other| result.merge!({other => similarity_score_between(main,other)}) end end |