NAME
Jubatus::Recommender::Client - Perl extension for interfacing with recommendation server 'jubarecommender'
SYNOPSIS
use Jubatus;
my $juba_client_type = "recommender";
my $host_name_or_ip_address = "localhost"; # master node's
my $port_number_of_juba_process = 13714; # meanless
my $cluster_name = "jubatus_perl_doc";
# even if it isn't in a distributed environment using ZooKeeper and Jubatus keepers.
# you can select from (recommender | regression | classifier | stat | graph | anomaly | nearestneighbor | clustering)
my $reco_client = Jubatus->get_client($juba_client_type, $host_name_or_ip_address, $port_number_of_juba_process, $cluster_name);
# got Jubatus::Recommender::Client object
# In the following example, get maximum value from sample array using Jubatus::Recommender::Client object
my $is_clear = $reco_client->clear();
{ # You can use an array reference of array references to initialize the Jubatus::Common::Datum object
my $row_id = "red";
my $values = [["name", "red"], ["image", "warm"], ["R", 255.0], ["G", 0.0], ["B", 0.0]];
my $datum = Jubatus::Common::Datum->new($string_values, $num_values);
my $is_update = $reco_client->update_row($row_id, $datum);
}
{ # And also you can use an hash to initialize the Jubatus::Common::Datum object
my $row_id = "blue";
my $hash = {
"name" => "blue",
"image" => "cold",
"R" => 0.0,
"G" => 0.0,
"B" => 255.0
};
my $datum = Jubatus::Common::Datum->new($hash);
my $is_update = $reco_client->update_row($row_id, $datum);
}
{
my $row_id = "cyan";
my $values = [["name", "cyan"], ["image", "cold"], ["R", 0.0], ["G", 255.0], ["B", 255.0]];
my $datum = Jubatus::Common::Datum->new($values);
my $is_update = $reco_client->update_row($row_id, $datum);
}
{
my $row_id = "magenta";
my $values = [["name", "magenta"], ["image", "warm"], ["R", 255.0], ["G", 0.0], ["B", 255.0]];
my $datum = Jubatus::Common::Datum->new($values);
my $is_update = $reco_client->update_row($row_id, $datum);
}
{
my $row_id = "yellow";
my $values = [["name", "yellow"], ["image", "warm"], ["R", 255.0], ["G", 255.0], ["B", 0.0]];
my $datum = Jubatus::Common::Datum->new($values);
my $is_update = $reco_client->update_row($row_id, $datum);
}
{
my $row_id = "green";
my $values = [["name", "green"], ["image", "cold"], ["R", 0.0], ["G", 255.0], ["B", 0.0]];
my $datum = Jubatus::Common::Datum->new($values);
my $max_result_num = 10;
my $similar_row = $reco_client->similar_row_from_datum($datum, $max_result_num);
# return cyan, yellow, blue
my $is_update = $reco_client->update_row($row_id, $datum);
}
{
my $similar_row = $reco_client->similar_row_from_id("green", $max_result_num);
# return green, cyan, yellow, blue
}
DESCRIPTION
This module provide a interface of recommendation server 'jubarecommender' by TCP-based MessagePack RPC protocol using AnyEvent::MPRPC::Client
METHODS
Jubatus::Recommender::Client provide many methods.
Constructors
This constructors can die when invalid parameters are given.
Jubatus::Recommender::Client->new($host, $port);
This code will create Jubatus::Recommender::Client object and return it. You should set $host and $port in agreement to running jubastat server application.
use Jubatus::Recommender::Client;
my $host = 'localhost';
my $port = '13714';
my $obj = Jubatus::Recommender::Client->new($host, $port);
The above code is equivalent to:
use Jubatus;
my $host = 'localhost';
my $port = '13714';
my $juba_client_type = 'recommender';
my $reco_client = Jubatus->get_client($host, $port, $juba_client_type);
See Jubatus for more detail.
Jubatus::Recommender::Client->new($host, $port, $cluster_name);
You must set $cluster_name if you are distributed environment user.
use Jubatus::Recommender::Client;
my $host = 'localhost';
my $port = '13714';
my $cluster_name = "perl doc";
my $obj = Jubatus::Recommender::Client->new($host, $port, $cluster_name);
The above code is equivalent to:
use Jubatus;
my $juba_client_type = 'recommender';
my $host = 'localhost';
my $port = '13714';
my $cluster_name = "perl doc";
my $reco_client = Jubatus->get_client($juba_client_type, $host, $port, $cluster_name);
See Jubatus for more detail.
Jubatus::Recommender::Client->new($host, $port, $cluster_name, $timeout_seconds);
Default value of timeout parameter of server process is 10 seconds. If you want to set timeout parameter, you should set 4th argument.
use Jubatus::Recommender::Client;
my $host = 'localhost';
my $port = '13714';
my $cluster_name = "perl doc";
my $timeout_secondes = 10;
my $obj = Jubatus::Recommender::Client->new($host, $port, $cluster_name, $timeout_secondes);
The above code is equivalent to:
use Jubatus;
my $juba_client_type = 'recommender';
my $host = 'localhost';
my $port = '13714';
my $cluster_name = "perl doc";
my $timeout_secondes = 10;
my $reco_client = Jubatus->get_client($juba_client_type, $host, $port, $cluster_name, $timeout_secondes);
See Jubatus for more detail.
FUNCTIONS
get_client()
Returns the reference to the Jubatus::Recommender::Client object which has a "client" field. This field is a reference of AnyEvent::MPRPC::Client object to call a raw MessagePack-RPC client instance which is used by Jubatus client libraries. The functions of Jubatus::Recommender::Client are wrapper of AnyEvent::MPRPC::Client.
Input:
- None
Output:
- Jubatus::Recommender::Client object - Return a Jubatus::Recommender::Client object
Which is used ad MessagePack-RPC client instance of jubarecommender server.
get_config()
Returns a server configuration from a server which is belonging to the cluster which execute the $cluster_name tasks.
Input:
- none
Output:
- JSON file formated string - Returns a server configuration from a server.
This configuration is same as the configuration file which was assigned
when you start the jubarecommender server.
get_status()
Returns server status from all servers which are belonging to the cluster which execute the $cluster_name tasks. Each server is represented by a pair of a host name and a port number.
Input:
- none
save($save_file_name)
Stores the learning model as $save_file_name to the local disk of all servers which are belonging to the cluster which execute the $cluster_name tasks.
Input:
- $save_file_name - File name to save
Output:
- binary(1 or 0) - Return integer value 1 if this function saves files
successfully at all servers
load($load_file_name)
Restores the saved model using $load_file_name at the local disk of all servers which are belonging to the cluster which execute the $cluster_name tasks.
Input:
- $load_file_name - File name to restore
Output:
- binary(1 or 0) - Return integer value 1 if this function restore saved
model successfully at all servers
clear()
Completely clears the learning model on the memory of all servers which are belonging to the cluster which execute the $cluster_name tasks.
Input:
- none
Output:
- binary(1 or 0) - Return integer value 1 if this function clears the
saved model successfully at all servers
Output:
- Hash reference which have a hash reference value - Returns a server
status from all servers which are belonging to the cluster which execute
the $cluster_name tasks. Each server is represented by a pair of host name
and a port number. This pair is used for a key of the return hash
reference. The value of the return hash reference is hash reference. The
keys of this hash reference are the server status name and each values are
the server status informations.
SEE ALSO
http://jubat.us/ https://github.com/jubatus
AnyEvent::MPRPC AnyEvent::MPRPC::Client http://msgpack.org/ http://wiki.msgpack.org/display/MSGPACK/RPC+specification
https://github.com/overlast/p5-Jubatus
LICENSE
Copyright (C) 2013 by Toshinori Sato (@overlast).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Toshinori Sato (@overlast) <overlasting@gmail.com>