WWW::AfinimaKi - AfinimaKi Recommendation Engine Client
use WWW::AfinimaKi; # Notice the uppercase "K"! my $api = WWW::AfinimaKi->new( $your_api_key, $your_api_secret); ... $api->set_rate($email_sha256, $user_id, $rates); ... my $estimated_rate = $api->estimate_rate($email_sha256, $rate); ... my $recommendations = $api->get_recommendations($email_sha256); foreach (@$recommendations) { print "item_id: $_->{item_id} estimated_rate: $_->{estimated_rate}\n"; } ... my $recommendations = $api->get_recommendations($email_sha256); foreach (@$recommendations) { print "item_id: $_->{item_id} estimated_rate: $_->{estimated_rate}\n"; } ... my $soul_mates = $api->get_soul_mates($email_sha256); foreach (@$soul_mates) { print "user_id: $_->{user_id} afinimaki: $_->{afinamki} email_sha256: $_->{email_sha256}\n"; }
WWW::AfinimaKi is a simple client for the AfinimaKi Recommendation API. Check http://www.afinimaki.com for more details.
All functions use an email digest of your users, in orden to maintain their privacy. The digest function is SHA256. You can generate the digest with the function sha256_hex from the module Digest::SHA.
my $api = WWW::AfinimaKi->new( api_key => $your_api_key, api_secret => $your_api_secret, debug => $debug_level, memcached => $memcached_server ); if (!$api) { die "Error construction afinimaki, wrong keys length?"; } new Construct the AfinimaKi object. No network traffic is generated (the account credentialas are not checked at this point). The given keys must be 32 character long. You can get them at www.afinimaki.com Debug level can be 0 or 1.
$api->set_rate( $email_sha256, $user_id, $item_id, $rate, $ts, ); $api->add_to_wishlist( $email_sha256, $user_id, $item_id, $ts, ); $api->add_to_blacklist( ... same as add_to_wishlist ...); $api->remove_from_lists( ... same as add_to_wishlist ...); $ts is the unix timestamp when the action was done (if $ts is not given, the action was performed now). user_id indicate the API to store your user_id in the DB, besides the email_sha256. Then, functions like get_soul_mates can return you back your user's ID for your conveniente. All calls wait until the RPC call has ended. On error, return is undef, and the RPC::XML error will be carp'ed. On success, the returned values are: 1: The rate was inserted 2: The rate existed previous, and it was NOT modified 3: The rate existed previous, and it was updated by this call -1: Error in parameters
Stores rates in the server
Adds the given $item_ids to user's wishlist. This means that id will not be in the user's recommentation list, and the action will be use to tune users's recommendations (The user seems to like this item).
Adds the given $item_ids to user's blacklist. This means that id will not be in the user's recommentation list, and the action will be use to tune users's recommendations (The user seems to dislike this item).
Removes the given items from user's wish and black lists, and also removes user item's rating (if any).
Set rate rate as NULL. This is useful when the user has already experienced the item (watched a movie, bought the product) but did set a rate. Therefore the item shouldn't be recommended again to the user.
my $estimated_rate = $api->estimate_rate($email_sha256, $item_id); Estimate a rate. Undef is returned if the rate could not be estimated (usually because the given user or the given item does not have many rates). On error, returns undef, and carp the RPC::XML error.
my $rates_hashref = $api->estimate_rate($email_sha256, @item_ids); foreach my $item_id (keys %$rates_hashref) { print "Estimated rate for $item_id is $rates_hashref->{$item_id}\n"; } Estimate multimple rates. The returned hash has the structure: item_id => estimated_rate On error, returns undef, and carp the RPC::XML error.
my $recommendations = $api->get_recommendations($email_sha256); foreach (@$recommendations) { print "item_id: $_->{item_id} estimated_rate: $_->{estimated_rate}\n"; } Get a list of user's recommentations, based on users' and community previous rates. Recommendations does not include rated or marked items (in the whish or black list).
my $afinimaki = $api->get_user_user_afinimaki($email_sha256_user_1, $email_sha256_user_2); Gets user vs user afinimaki. AfinimaKi range is [0.0-1.0].
my $soul_mates = $api->get_soul_mates($email_sha256); foreach (@$soul_mates) { print "user_id: $_->{user_id} afinimaki: $_->{afinimaki} email_sha: $_->{email_sha256} \n"; } Get a list of user's soul mates (users with similar tastes). AfinimaKi range is [0.0-1.0]. Note that user_id in the results will ONLY be filled if you have upload you user_id's using set_rate or a similar function.
WWW::AfinimaKi by Matias Alejo Garcia (matiu at cpan.org)
Copyright (c) 2010 Matias Alejo Garcia. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The WWW::AfinimaKi is free Open Source software. IT COMES WITHOUT WARRANTY OF ANY KIND.
Github repository is at http://github.com/matiu/WWW--AfinimaKi
None discovered yet... please let me know if you run into one.
To install WWW::AfinimaKi, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::AfinimaKi
CPAN shell
perl -MCPAN -e shell install WWW::AfinimaKi
For more information on module installation, please visit the detailed CPAN module installation guide.