Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
I would start by running the test stuff.
test = euclidean(@people, 'Lisa Rose', 'Gene Seymour')
puts "#{test} should equal 0.148148148148"
Also note that the version in the book is wrong,
which is why i have the #errata comment there, since my version is the correct one, afaik.
so, both euclidean and pearson are meant to be interchangeable.
So, all that both of them do is take a hash in the following form:
:owner_object => {:owned_object => score, :owned_object => score,
:another_owner_object => {:owned_object => score}
Where score is an int. To try this for yourself, just construct some hash and
pass in two of the keys.
So, euclidean will just take a hash like that, plus two of the keys
for the owner objects and tell you how similar they are.
Does that make sense?
I wrote the method to be very clear for people / movies,
but it's unfortunaly kind of unclear if you want to abstract it.
However, it is abstract.
You can see all this at work in the delicious_recommendations.rb file.
So, when it calls super, in top matches in the class in that file, it's calling
the top_matches defined in recommendations.rb, (since it's defined on object it gets called
by super -- i was lazy).
So, looking here, we can see that peearson is getting called.
I think that you could just change this to euclidean and it would still work. So that's another example.
def top_matches(people, person, n=5)
scores = do |critic, items|
unless person == critic
[(block_given? ? yield(people, person, critic) : pearson(people, person, critic)), critic]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment