App42 Cloud API

PHP 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(long userId, int howMany) it uses PearsonCorrelationSimilarity. In the method itemBasedBySimilarity(String similarity,long userId, int 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(String preferenceFilePath) in csv format. This prefernce file 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 = new ServiceAPI("<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 Recommender 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";

$loadPreference = $recommenderService -> loadPreferenceFile($preferenceFilePath); /* returns the Recommender object. */
$success = $loadPreference-> isResponseSuccess();
$jsonResponse = $loadPreference-> toString(); /* 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";

try{
	$recommender = $recommenderService->loadPreferenceFile($preferenceFilePath);
} catch(App42Exception $ex) {
	$appErrorCode = $ex->getAppErrorCode();
	$httpErrorCode = $ex->getHttpErrorCode();
	if(appErrorCode == 2805)
{
    // Handle here for Bad Request (Preference Data is not valid)
}
   
     else if(appErrorCode == 1401){
    // handle here for Client is not authorized
}
    else if(appErrorCode == 1500){
    // handle here for Internal Server Error
}

	 $jsonText = $ex->getMessage(); /* returns the Exception text in JSON format. (as shown below)*/	
}
                            
	{
		"app42Fault": {
			"httpErrorCode": 404,
			"appErrorCode": 2802,
			"message": "Bad Request",
			"details": "InvalidArgumentException: <e.getMessage()>"
		}
	}							

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.

function loadPreferenceFile($preferenceFilePath)

Uploads peference file on the cloud. The preference file should be in CSV format. This prefernce 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:

preferenceFilePath - Path of the preference file to be loaded

Returns:

The uploaded preference file details.

Response: App42Response Object

Exception:

This method throws following exception.
/* 
2805- BAD REQUEST - Preference Data is not valid.	
*/ 		        
For more details click Exception
$preferenceFilePath = "Local file path";
						
$recommender = $recommenderService-> loadPreferenceFile($preferenceFilePath);  /* returns the Recommender object. */ 
$success = $recommender->isResponseSuccess();  
$jsonResponse = $recommender->toString(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "fileName": "FileName03"
            }
        }
    }
} 
function userBasedNeighborhood($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:

Recommendations

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany' 
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.  
*/ 	        
For more details click Exception
$userId = 3;
$size = 4567788 ;
$howMany = 2;
						
$recommender = $recommenderService-> userBasedNeighborhood($userId, $size, $howMany);  /* returns the Recommender object. */ 
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "item": 106,
                        "value": 4
                    },
                    {
                        "item": 103,
                        "value": 2.5905366
                    }
                ]
            }
        }
    }
} 
function userBasedThreshold($userId, $threshold, $howMany)

User based neighborood recommendations based on Threshold. Recommendations are found based on Threshold where thereshold represents similarity threshold where user are atleast 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:

Recommendations

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>'
2803 - BAD REQUEST - There are no recommendations for optimize values for 'threshold' and 'howMany'.  
2804 - NOT FOUND - InvalidArgumentException: NoSuchUserException : UserId '<e.getMessage()>'	
*/ 		        
For more details click Exception
$userId = 1;
$threshold = 0.5;
$howMany = 2;
						
$recommender = $recommenderService-> userBasedThreshold($userId, $threshold, $howMany);  /* returns the Recommender object. */    
$recommendedItemList =  $recommender-> getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "item": 104,
                        "value": 4.257081
                    },
                    {
                        "item": 106,
                        "value": 4
                    }
                ]
            }
        }
    }
}
function userBasedNeighborhoodBySimilarity($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:

Recommendations

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany' 
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>. 
*/ 		        
For more details click Exception
recommenderSimilarity = RecommenderSimilarity::EUCLIDEAN_DISTANCE;		
$userId = 1;
$size = 2;
$howMany = 2;
						
$recommender = $recommenderService->userBasedNeighborhoodBySimilarity($recommenderSimilarity,$userId, $size, $howMany);  /* returns the Recommender object. */ 
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": [
                    {
                        "item": 104,
                        "value": 4.25
                    },
                    {
                        "item": 106,
                        "value": 4
                    }
                ]
            }
        }
    }
}
function userBasedThresholdBySimilarity($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 atleast 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:

Recommendations

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>'
2803 - BAD REQUEST - There are no recommendations for optimize values for 'threshold' and 'howMany'. 
2804 - NOT FOUND - InvalidArgumentException: NoSuchUserException : UserId '<e.getMessage()>'	
*/ 		       
For more details click Exception
recommenderSimilarity = RecommenderSimilarity::EUCLIDEAN_DISTANCE;
$userId = 1;
$threshold = 0.5;
$howMany = 1;
						
$recommender = $recommenderService->userBasedThresholdBySimilarity($recommenderSimilarity,$userId, $threshold, $howMany);  /* returns the Recommender object. */ 
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 106,
                    "value": 4
                }
            }
        }
    }
}
function itemBased($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:

Recommendations

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.   
*/ 		       
$userId = 1;
$howMany = 1;
						
$recommender = $recommenderService->itemBased($userId, $howMany);  /* returns the Recommender object. */ 
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 104,
                    "value": 5
                }
            }
        }
    }
}
function itemBasedBySimilarity($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:

Recommendations

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.   
*/ 		       
For more details click Exception
recommenderSimilarity = RecommenderSimilarity::EUCLIDEAN_DISTANCE;
$userId = 1;
$howMany = 1;
						
$recommender = $recommenderService->itemBasedBySimilarity($recommenderSimilarity,$userId, $howMany);  /* returns the Recommender object. */ 
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 107,
                    "value": 5
                }
            }
        }
    }
}
function slopeOne($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:

Recommendations

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.   
*/ 		        
For more details click Exception
$userId = 1;
$howMany = 1;
						
$recommender = $recommenderService->slopeOne($userId, $howMany);  /* returns the Recommender object. */ 
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 105,
                    "value": 5.75
                }
            }
        }
    }
}
function userBasedNeighborhoodForAll($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:

Recommendations for All users

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'  
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.  
*/ 	        
For more details click Exception
$size = 1;
$howMany = 1;
						
$recommender = $recommenderService->userBasedNeighborhoodForAll($size, $howMany);  /* returns the Recommender object. */ 
$success = $recommender->isResponseSuccess();  
$jsonResponse = $recommender->toString(); /* 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
                    }
                ]
            }
        }
    }
}
function userBasedThresholdForAll($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 atleast 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:

Recommendations for all Users

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'  
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.  
*/ 		        
For more details click Exception
$threshold = 1;
$howMany = 3;
						
$recommender = $recommenderService->userBasedThresholdForAll($threshold, $howMany);  /* returns the Recommender object. */ 
$recommendedItemList =  $recommender->getRecommendedItemList(); 
$success = $recommender->isResponseSuccess();
$jsonResponse = $recommender->toString(); /* 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
                    }
                ]
            }
        }
    }
}
function userBasedNeighborhoodBySimilarityForAll($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:

Recommendations for all Users

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'  
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.  
*/ 		        
For more details click Exception
$recommenderSimilarity = RecommenderSimilarity::EUCLIDEAN_DISTANCE;
$size = 2;
$howMany = 3;		
						
$recommender = $recommenderService->userBasedNeighborhoodBySimilarityForAll($recommenderSimilarity,$size, $howMany);  /* returns the Recommender object. */ 
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* 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
                    }
                ]
            }
        }
    }
}
function userBasedThresholdBySimilarityForAll($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 atleast 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:

Recommendations for All

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'  
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.   
*/ 		        
For more details click Exception
$recommenderSimilarity = RecommenderSimilarity::EUCLIDEAN_DISTANCE;
$threshold = 0.5;
$howMany = 4;

$recommender = $recommenderService->userBasedThresholdBySimilarityForAll($recommenderSimilarity,$threshold, $howMany);  /* returns the Recommender object. */ 
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print("userId is" . $recommendedItem->getUserId());
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* 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
                    }
                ]
            }
        }
    }
}
function itemBasedForAll($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:

Recommendations for all Users

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'  
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.   
*/ 		        
For more details click Exception
$howMany = 3;
						
$recommender = $recommenderService->itemBasedForAll($howMany);  /* returns the Recommender object. */    
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print("userId is" . $recommendedItem->getUserId());
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* 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
                    }
                ]
            }
        }
    }
}
function itemBasedBySimilarityForAll($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:

Recommendations for all Users

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'  
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.   
*/ 		        
For more details click Exception
$recommenderSimilarity = RecommenderSimilarity::EUCLIDEAN_DISTANCE;
$howMany = 5;
						
$recommender = $recommenderService->itemBasedBySimilarityForAll($recommenderSimilarity,$howMany);  /* returns the Recommender object. */  
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print("userId is" . $recommendedItem->getUserId());
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* 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
                    }
                ]
            }
        }
    }
}
function slopeOneForAll($howMany)

Recommendations based on SlopeOne Algorithm for all Users.

Parameters:

howMany - Specifies that how many recommendations have to be found

Returns:

Recommendations for all Users

Response: Recommender Object

Exception:

This method throws following exception.
/* 
2801 - NOT FOUND - There are no recommendations for optimize values for 'size' and 'howMany'  
2802 - NOT FOUND - InvalidArgumentException: '<e.getMessage()>' 
2804 - BAD REQUEST - InvalidArgumentException: NoSuchUserException : UserId <e.getMessage()>.   
*/ 		        
For more details click Exception
$howMany = 4;
						
$recommender = $recommenderService->slopeOneForAll($howMany);  /* returns the Recommender object. */    
$recommendedItemList =  $recommender->getRecommendedItemList(); 
foreach( $recommendedItemList as $recommendedItem ){
print("userId is" . $recommendedItem->getUserId());
print_r("value is" . $recommendedItem->getValue());
print_r("item is" . $recommendedItem->getItem());
}
$jsonResponse = $recommender->toString(); /* 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
                    }
                ]
            }
        }
    }
}
function deleteAllPreferences()

Delete existing preference file.

Parameters:

N/A

Returns:

App42Response if deleted successfully

Response: App42Response Object

Exception:

This method throws following exception.
/* 
2800 - BAD REQUEST - Preferences does not exist.
*/ 		        
For more details click Exception
$recommender = $recommenderService->deleteAllPreferences();  /* returns the Recommender object. */ 
$success = $response->isResponseSuccess();
$jsonResponse = $recommender->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
   "app42": {
       "response": {
           "success": true
       }
   }
}