App42 Cloud API

Ruby Cloud SDK

Recommendation

Recommendation engine which provides recommendation based on customer id, item id and the preference of the customer for a particular Item. Recommendations can be fetched based on User Similarity i.e. It finds similarity based on on Users and Item Similarity which finds similarity based on Items. The Recommendation Engine currently supports two types of Similarity Algorithms i.e. EuclideanDistanceSimilarity and PearsonCorrelationSimilarity. By default when similarity is not specified PearsonCorrelationSimilarity is used e.g. in the method itemBased(userId,howMany) it uses PearsonCorrelationSimilarity. In the method itemBasedBySimilarity(similarity,userId,howMany) one can specify which similarity algorithm has to be used e.g. Recommender.EUCLIDEAN_DISTANCE or Recommender.PEARSON_CORRELATION. Preference file can be loaded using the method loadPreferenceFile(preferenceFilePath) in csv format. This preferencefile has to be uploaded once which can be a batch process

The csv format for the file is given below. customerId, itemId, preference e.g. 1,101,5.0 1,102,3.0 1,103,2.5 2,101,2.0 2,102,2.5 2,103,5.0 2,104,2.0 3,101,2.5 3,104,4.0 3,105,4.5 3,107,5.0 4,101,5.0 4,103,3.0 4,104,4.5 4,106,4.0 5,101,4.0 5,102,3.0 5,103,2.0 5,104,4.0 5,105,3.5 5,106,4.0

The customer Id and item id can be any alphanumaric character(s) and preference values can be in any range. If app developers have used the Review Service. The Recommendation Engine can be used in conjunction with Review. In this case a CSV preference file need not be uploaded. The customerId, itemId and preference will be taken from Review where customerId is mapped with userName, itemId is mapped with itemId and preference with rating. The methods for recommendations based on Reviews are part of the Review service.

In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.

api = App42::ServiceAPI.new("<API_KEY>","<SECRET_KEY>")

After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of RecommenderService, buildRecomenderService() method needs to be called.

recommenderService = api.buildRecommenderService();

Once the API instance has been retrieved, You are ready to use the functions available for that particular API.

The methods available under a particular API will return the domain object (like LoadPreference in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.

preferenceFilePath = "Local file path";
						
recommender =  recommenderService.load_preference_file(preferenceFilePath); /* returns the Recommender object. */   
success = recommender.isResponseSuccess();
jsonResponse = recommender.to_s(); /* returns the response in JSON format. */

The functions available under Recommendation API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is uploading the Preference File which does not have any data, the loadPreferenceFile function will throw the App42Exception (as shown below) with message as "Bad Request" and the appErrorCode as "2805" and the details as "Preference Data is not valid."

preferenceFilePath = "Local file path";
							
begin
  recommender = recommenderService.load_preference_file(preferenceFilePath);
rescue App42Exception => ex
  appErrorCode = ex.app_error_code;
  httpErrorCode = ex.http_error_code;

  if(appErrorCode == 2805)
    #Handle here for Bad Request (InvalidArgumentException: '<e.getMessage()>')

  elsif(appErrorCode == 1401)
    #handle here for Client is not authorized

  else(appErrorCode == 1500)
    #handle here for Internal Server Error
  end

  jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/
end
	{
		"app42Fault": {
			"httpErrorCode": 404,
			"appErrorCode": 2802,
			"message": "Bad Request",
			"details": "Preference Data is not valid."
		}
	}

Below are the HTTP Error Codes and their description, the function under the Recommendation API can throw.

/*
1400 - BAD REQUEST - The Request parameters are invalid
1401 - UNAUTHORIZED - Client is not authorized
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again
*/

Below are the Application Error Codes and their description, the function under the Recommendation API can throw.

/*
2800 - NOT FOUND - Preferences does not exist. 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2803 - NOT FOUND - There are no recommendations for optimize values for 'threshold' and 'howMany'.	
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
2805 - BAD REQUEST - Preference Data is not valid.
*/

Various functions available under Recommendation API has been explained below.

def load_preference_file(preferenceFilePath)

Uploads peference file on the cloud. The preference file should be in CSV format. This preferencefile has to be uploaded once which can be a batch process. New versions of preference file either can be uploaded in a different name or the older one has to be removed and the uploaded in the same name.

 
The csv format for the file is given below. customerId, itemId, preference e.g. 1,101,5.0 1,102,3.0 1,103,2.5 2,101,2.0 2,102,2.5 2,103,5.0 2,104,2.0 3,101,2.5 3,104,4.0 3,105,4.5 3,107,5.0 4,101,5.0 4,103,3.0 4,104,4.5 4,106,4.0 5,101,4.0 5,102,3.0 5,103,2.0 5,104,4.0 5,105,3.5 5,106,4.0

The customer Id and item id can be any alphanumaric character(s) and preference values can be in any range. If the recommendations have to be done based on Reviews then this file need not be uploaded.

Parameters:

name - Name of the Preference File based on which recommendations have to be found

Returns:

The uploaded preference file details.

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/* 
2805 - BAD REQUEST - Preference Data is not valid.
*/
For more details click Exception
preferenceFilePath = "Local file path";	
					
recommender = recommenderService.load_preference_file(preferenceFilePath);  /* returns the Recommender object. */ 
success = recommender.isResponseSuccess();
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true
        }
    }
}
def load_preference_file_stream(inputStream)

Uploads peference file via stream on the cloud. The preference file should be in CSV format. This preference file has to be uploaded once which can be a batch process. New versions of preference file either can be uploaded in a different name or the older one has to be removed and the uploaded in the same name.

 
The csv format for the file is given below. customerId, itemId, preference e.g. 1,101,5.0 1,102,3.0 1,103,2.5 2,101,2.0 2,102,2.5 2,103,5.0 2,104,2.0 3,101,2.5 3,104,4.0 3,105,4.5 3,107,5.0 4,101,5.0 4,103,3.0 4,104,4.5 4,106,4.0 5,101,4.0 5,102,3.0 5,103,2.0 5,104,4.0 5,105,3.5 5,106,4.0

The customer Id and item id can be any alphanumaric character(s) and preference values can be in any range. If the recommendations have to be done based on Reviews then this file need not be uploaded.

Parameters:

name - Name of the Preference File based on which recommendations have to be found

Returns:

The uploaded preference file details.

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/* 
2805 - BAD REQUEST - Preference Data is not valid.
*/
For more details click Exception
inputStream = "Local file path";	
					
recommender = recommenderService.load_preference_file_stream(inputStream);  /* returns the Recommender object. */ 
success = recommender.isResponseSuccess();
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/     
{
    "app42": {
        "response": {
            "success": true
        }
    }
}
def user_based_neighborhood(userId, size, howMany)

User based recommendations based on Neighborhood. Recommendations are found based on similar users in the Neighborhood of the given user. The size of the neighborhood can be found.

Parameters:

userId - The user Id for whom recommendations have to be found
size - Size of the Neighborhood
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
userId = 3;
size = 4567788;
howMany = 2;
						
recommender = recommenderService.user_based_neighborhood(userId, size, howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList = recommender.recommendedItemList();
for  recommendedItem in recommendedItemList do
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "item": 106,
                        "value": 4
                    },
                    {
                        "item": 103,
                        "value": 2.5905366
                    }
                ]
            }
        }
    }
}
def user_based_threshold(userId, threshold, howMany)

User based neighborhood recommendations based on Threshold. Recommendations are found based on Threshold where thereshold represents similarity threshold where user are at least that similar. Threshold values can vary from -1 to 1

Parameters:

userId - The user Id for whom recommendations have to be found
threshold - Threshold size. Values can vary from -1 to 1
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2803 - NOT FOUND - There are no recommendations for optimize values for 'threshold' and 'howMany'.	
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
userId = 1;
threshold = 0.5;
howMany = 2;
							
recommender = recommenderService.user_based_threshold(userId, threshold, howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList = recommender.recommendedItemList();
for  recommendedItem in recommendedItemList do
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "item": 104,
                        "value": 4.257081
                    },
                    {
                        "item": 106,
                        "value": 4
                    }
                ]
            }
        }
    }
}
def user_based_neighborhood_by_similarity(recommenderSimilarity,userId, size, howMany)

User based recommendations based on Neighborhood and Similarity. Recommendations and found based on the similar users in the Neighborhood with the specified Similarity Algorithm. Algorithim can be specified using the constants Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION

Parameters:

recommenderSimilarity - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
userId - The user Id for whom recommendations have to be found
size - Size of the Neighborhood
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
rs = App42::Recommend::RecommenderSimilarity.new();
recommenderSimilarity = rs.enum("EUCLIDEAN_DISTANCE");
userId = 1;
size = 2;
howMany = 2;

recommender = recommenderService.user_based_neighborhood_by_similarity(recommenderSimilarity,userId, size, howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList = recommender.recommendedItemList();
for recommendedItem in recommendedItemList do
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "item": 104,
                        "value": 4.25
                    },
                    {
                        "item": 106,
                        "value": 4
                    }
                ]
            }
        }
    }
}
def user_based_threshold_by_similarity(recommenderSimilarity,userId, threshold, howMany)

User based neighborood recommendations based on Threshold. Recommendations are found based on Threshold where thereshold represents similarity threshold where user are at least that similar. Threshold values can vary from -1 to 1

Parameters:

recommenderSimilarity - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
userId - The user Id for whom recommendations have to be found
threshold - Threshold size. Values can vary from -1 to 1
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2803 - NOT FOUND - There are no recommendations for optimize values for 'threshold' and 'howMany'.	
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
rs = App42::Recommend::RecommenderSimilarity.new();
recommenderSimilarity = rs.enum("EUCLIDEAN_DISTANCE");
userId = 1;
threshold = 0.5;
howMany = 1;
						
recommender = recommenderService.user_based_threshold_by_similarity(recommenderSimilarity,userId, threshold, howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList = recommender.recommendedItemList();
for recommendedItem in recommendedItemList do
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 106,
                    "value": 4
                }
            }
        }
    }
}
def item_based(userId, howMany)

Item based recommendations. Recommendations and found based item similarity of the given user. The size of the neighborhood can be found.

Parameters:

userId - The user Id for whom recommendations have to be found
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
userId = 1;
howMany = 1;
					
recommender = recommenderService.item_based(userId, howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList = recommender.recommendedItemList();
for recommendedItem in recommendedItemList do
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 104,
                    "value": 5
                }
            }
        }
    }
}
def item_based_by_similarity(recommenderSimilarity,userId, howMany)

Item based recommendations. Recommendations and found based one item similarity. Similarity algorithm can be specified. of the given user. The size of the neighborhood can be found.

Parameters:

recommenderSimilarity - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
userId - The user Id for whom recommendations have to be found
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
rs = App42::Recommend::RecommenderSimilarity.new();
recommenderSimilarity = rs.enum("EUCLIDEAN_DISTANCE");
userId = 1;
int howMany = 1;

recommender = recommenderService.item_based_by_similarity(recommenderSimilarity,userId, howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList =  recommender.recommendedItemList();
for  recommendedItem in recommendedItemList do
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 107,
                    "value": 5
                }
            }
        }
    }
}
def slope_one(userId, howMany)

Recommendations based on SlopeOne Algorithm.

Parameters:

userId - The user Id for whom recommendations have to be found
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'  
2803 - BAD REQUEST - There are no recommendations for optimize values for 'threshold' and 'howMany'. 
*/
For more details click Exception
userId = 1;
howMany = 1;
						
recommender = recommenderService.slope_one(userId, howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList =  recommender.recommendedItemList();
for recommendedItem in recommendedItemList do
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 105,
                    "value": 5.75
                }
            }
        }
    }
}
def user_based_neighborhood_for_all(size, howMany)

User based recommendations based on Neighborhood for All Users. Recommendations and found based similar users in the Neighborhood of the given user. The size of the neighborhood can be found.

Parameters:

size - Size of the Neighborhood
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object for all users

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
size = 1;
howMany = 1;
						
recommender = recommenderService.user_based_neighborhood_for_all(size, howMany);  /* returns the Recommender object. */ 
success = recommender.isResponseSuccess();
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "userId": 1,
                        "item": 104,
                        "value": 4.257081
                    },
                    {
                        "userId": 3,
                        "item": 106,
                        "value": 4
                    },
                    {
                        "userId": 4,
                        "item": 102,
                        "value": 3
                    }
                ]
            }
        }
    }
}
def user_based_threshold_for_all(threshold, howMany)

User based neighborood recommendations based on Threshold for all Users. Recommendations are found based on Threshold where thereshold represents similarity threshold where user are at least that similar. Threshold values can vary from -1 to 1

Parameters:

threshold - Threshold size. Values can vary from -1 to 1
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object for all users

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
threshold = 1;
howMany = 3;
						
recommender = recommenderService.user_based_threshold_for_all(threshold, howMany);  /* returns the Recommender object. */ 
success = recommender.isResponseSuccess(); 
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "userId": 1,
                        "item": 104,
                        "value": 4.257081
                    },
                    {
                        "userId": 3,
                        "item": 106,
                        "value": 4
                    },
                    {
                        "userId": 4,
                        "item": 102,
                        "value": 3
                    }
                ]
            }
        }
    }
}
def user_based_neighborhood_by_similarity_for_all(recommenderSimilarity,size, howMany)

User based recommendations based on Neighborhood and Similarity for all Users. Recommendations and found based similar users in the Neighborhood with the specified Similarity Algorithm. Algorithim can be specified using the constants Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION

Parameters:

recommenderSimilarity - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
size - Size of the Neighborhood
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object for all users

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
rs = App42::Recommend::RecommenderSimilarity.new();
recommenderSimilarity = rs.enum("EUCLIDEAN_DISTANCE");						
size = 2;
howMany = 3;	
					
recommender = recommenderService.user_based_neighborhood_by_similarity_for_all(recommenderSimilarity,size, howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList = recommender.recommendedItemList();
for recommendedItem in recommendedItemList do
  puts "userId is #{recommendedItem.userId}";
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "userId": 1,
                        "item": 104,
                        "value": 4.257081
                    },
                    {
                        "userId": 3,
                        "item": 106,
                        "value": 4
                    },
                    {
                        "userId": 4,
                        "item": 102,
                        "value": 3
                    }
                ]
            }
        }
    }
}
def user_based_threshold_by_similarity_for_all(recommenderSimilarity,threshold, howMany)

User based neighborood recommendations based on Threshold for All. Recommendations are found based on Threshold where thereshold represents similarity threshold where user are at least that similar. Threshold values can vary from -1 to 1

Parameters:

recommenderSimilarity - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
threshold - Threshold size. Values can vary from -1 to 1
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object for all

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
rs = App42::Recommend::RecommenderSimilarity.new();
recommenderSimilarity = rs.enum("EUCLIDEAN_DISTANCE");
threshold = 0.5;
howMany = 4;
						
recommender = recommenderService.user_based_threshold_by_similarity_for_all(recommenderSimilarity,threshold, howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList =  recommender.recommendedItemList();
for recommendedItem in recommendedItemList do
  puts "userId is #{recommendedItem.userId}";
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "userId": 1,
                        "item": 106,
                        "value": 4
                    },
                    {
                        "userId": 2,
                        "item": 106,
                        "value": 4
                    },
                    {
                        "userId": 3,
                        "item": 106,
                        "value": 4
                    },
                    {
                        "userId": 4,
                        "item": 105,
                        "value": 3.860392
                    }
                ]
            }
        }
    }
}
def item_based_for_all(howMany)

Item based recommendations for all Users. Recommendations and found based item similarity of the given user. The size of the neighborhood can be found.

Parameters:

howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object for all users

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
howMany = 3;
						
recommender = recommenderService.item_based_for_all(howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList = recommender.recommendedItemList();
for recommendedItem in recommendedItemList do
  puts "userId is #{recommendedItem.userId}";
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "userId": 1,
                        "item": 104,
                        "value": 5
                    },
                    {
                        "userId": 3,
                        "item": 103,
                        "value": 3.2766466
                    },
                    {
                        "userId": 4,
                        "item": 102,
                        "value": 5
                    }
                ]
            }
        }
    }
}
def item_based_by_similarity_for_all(recommenderSimilarity,howMany)

Item based recommendations for all Users. Recommendations and found based one item similarity. Similarity algorithm can be specified. of the given user. The size of the neighborhood can be found.

Parameters:

recommenderSimilarity - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object for all users

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
rs = App42::Recommend::RecommenderSimilarity.new();
recommenderSimilarity = rs.enum("EUCLIDEAN_DISTANCE");
howMany = 5;
						
recommender = recommenderService.item_based_by_similarity_for_all(recommenderSimilarity,howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList = recommender.recommendedItemList();
for recommendedItem in recommendedItemList do
  puts "userId is #{recommendedItem.userId}";
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "userId": 1,
                        "item": 107,
                        "value": 5
                    },
                    {
                        "userId": 2,
                        "item": 106,
                        "value": 2.6748168
                    },
                    {
                        "userId": 3,
                        "item": 102,
                        "value": 3.5901134
                    },
                    {
                        "userId": 4,
                        "item": 107,
                        "value": 4.681818
                    },
                    {
                        "userId": 5,
                        "item": 107,
                        "value": 3.7704918
                    }
                ]
            }
        }
    }
}
def slope_one_for_all(howMany)

Recommendations based on SlopeOne Algorithm for all Users.

Parameters:

howMany - Specifies that how many recommendations have to be found

Returns:

Recommender Object for all users

Response: Recommender Object

Exception:

The method throws the following exception with the error code
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'. 
2802 - BAD REQUEST - InvalidArgumentException: <e.getMessage()>.
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.
*/
For more details click Exception
howMany = 4;	
					
recommender = recommenderService.slope_one_for_all(howMany);  /* returns the Recommender object. */
recommendedItemList = Array.new();
recommendedItemList = recommender.recommendedItemList();
for recommendedItem in recommendedItemList do
  puts "item is #{recommendedItem.userId}";
  puts "item is #{recommendedItem.item}";
  puts "value is #{recommendedItem.value}";
end
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "userId": 1,
                        "item": 105,
                        "value": 5.75
                    },
                    {
                        "userId": 2,
                        "item": 106,
                        "value": 3.1298585
                    },
                    {
                        "userId": 3,
                        "item": 106,
                        "value": 2.976076
                    },
                    {
                        "userId": 4,
                        "item": 105,
                        "value": 4.976859
                    }
                ]
            }
        }
    }
}
def delete_all_preferences()

Delete existing preference file.

Parameters:

N/A

Returns:

App42Response if deleted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/* 
2800 - NOT FOUND - Preferences does not exist.
*/
For more details click Exception
						
response = recommenderService.delete_all_preferences(); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = recommender.to_s(); /* returns the response in JSON format. (as shown below)*/
{
   "app42": {
       "response": {
           "success": true
       }
   }
}