App42 Cloud API

Java and Groovy 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 preference 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.

	ServiceAPI 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 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.

String preferenceFilePath = "Local file path";
			
App42Response response = recommenderService.loadPreferenceFile(preferenceFilePath); /* returns the App42Response object. */  
boolean success = response.isResponseSuccess();  
String jsonResponse = response.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 recommender = recommenderService.loadPreferenceFile(preferenceFilePath);
}
catch(App42Exception ex) 
{
	int appErrorCode = ex.getAppErrorCode();
	int 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
	}
	String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/	
}            
	{
		"app42Fault": {
			"httpErrorCode": 404,
			"appErrorCode": 2805,
			"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.

public App42Response loadPreferenceFile(String preferenceFilePath) throws App42Exception

Uploads peference file 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:

preferenceFilePath - Path of the preference file to be loaded

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
String preferenceFilePath = "Local file path";

App42Response response = recommenderService.loadPreferenceFile(preferenceFilePath);  /* returns the App42Response  object. */ 
boolean  success = response.isResponseSuccess();  
String jsonResponse = response.toString() /* returns the response in JSON format. (as shown below)*/      
{
    "app42": {
        "response": {
            "success": true
        }
    }
} 
public App42Response loadPreferenceFile(InputStream inputStream) throws App42Exception

Uploads peference file on the cloud via Stream. 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:

inputStream - InputStream of the file to be load.

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
String preferenceFilePath = "Local file path";
FileInputStream fileInputStream = null;

try 
{
	fileInputStream = new FileInputStream(preferenceFilePath);
}
catch (FileNotFoundException e) 
{
	e.printStackTrace();
}
App42Response response = recommenderService.loadPreferenceFile(fileInputStream);  /* returns the App42Response  object. */ 
boolean  success = response.isResponseSuccess();  
String jsonResponse = response.toString() /* returns the response in JSON format. (as shown below)*/     
{
    "app42": {
        "response": {
            "success": true
        }
    }
} 
public Recommender userBasedNeighborhood(long userId, int size, int howMany) throws App42Exception

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
long userId = 3;
int size = 4567788 ;
int howMany = 2;

Recommender recommender = recommenderService.userBasedNeighborhood(userId, size, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String 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
                    }
                ]
            }
        }
    }
} 
public Recommender userBasedThreshold(long userId,double threshold, int howMany) throws App42Exception

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
long userId = 1;
double threshold = 0.5;
int howMany = 2;					

Recommender recommender = recommenderService.userBasedThreshold(userId, threshold, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
	System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String 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
                    }
                ]
            }
        }
    }
}
public Recommender userBasedNeighborhoodBySimilarity(RecommenderSimilarity recommenderSimilarity, long userId, int size, int howMany) throws App42Exception

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
RecommenderSimilarity recommenderSimilarity = RecommenderSimilarity.EUCLIDEAN_DISTANCE;		
long userId = 1;
int size = 2;
int howMany = 2;						

Recommender recommender = recommenderService.userBasedNeighborhoodBySimilarity(recommenderSimilarity, userId, size, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("item is " + recommendedItem.getItem());
    System.out.println("value is " + recommendedItem.getValue());
}
String 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
                    }
                ]
            }
        }
    }
}
public Recommender userBasedThresholdBySimilarity(RecommenderSimilarity recommenderSimilarity, long userId, double threshold, int howMany) throws App42Exception

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
RecommenderSimilarity recommenderSimilarity = RecommenderSimilarity.EUCLIDEAN_DISTANCE;
long userId = 1;
double threshold = 0.5;
int howMany = 1;

Recommender recommender = recommenderService.userBasedThresholdBySimilarity(recommenderSimilarity, userId, threshold, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("item is " + recommendedItem.getItem());
  	System.out.println("value is " + recommendedItem.getValue());
}
String jsonResponse = recommender.toString(); /* returns the response in JSON format. (as shown below)*/      
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 106,
                    "value": 4
                }
            }
        }
    }
}
public Recommender itemBased(long userId, int howMany) throws App42Exception

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
long userId = 1;
int howMany = 1;

Recommender recommender = recommenderService.itemBased(userId, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String jsonResponse = recommender.toString(); /* returns the response in JSON format. (as shown below)*/       
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 104,
                    "value": 5
                }
            }
        }
    }
}
public Recommender itemBasedBySimilarity(RecommenderSimilarity recommenderSimilarity, long userId, int howMany) throws App42Exception

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
   
RecommenderSimilarity recommenderSimilarity = RecommenderSimilarity.EUCLIDEAN_DISTANCE;
long userId = 1;
int howMany = 1;
						
Recommender recommender = recommenderService.itemBasedBySimilarity(recommenderSimilarity, userId, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
   	System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String jsonResponse = recommender.toString(); /* returns the response in JSON format. (as shown below)*/      
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 107,
                    "value": 5
                }
            }
        }
    }
}
public Recommender slopeOne( long userId, int howMany) throws App42Exception

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
long userId = 1;
int howMany = 1;	
					
Recommender recommender = recommenderService.slopeOne(userId, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
   	System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String jsonResponse = recommender.toString(); /* returns the response in JSON format. (as shown below)*/     
{
    "app42": {
        "response": {
            "success": true,
            "recommender": {
                "recommended": {
                    "item": 105,
                    "value": 5.75
                }
            }
        }
    }
}
public Recommender userBasedNeighborhoodForAll(int size, int howMany) throws App42Exception

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
int size = 1;
int howMany = 1;						

Recommender recommender = recommenderService.userBasedNeighborhoodForAll(size, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("userId is " + recommendedItem.getUserId());
    System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String 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
                    }
                ]
            }
        }
    }
}
public Recommender userBasedThresholdForAll(double threshold, int howMany) throws App42Exception

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
double threshold = 1;
int howMany = 3;

Recommender recommender = recommenderService.userBasedThresholdForAll(threshold, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("userId is " + recommendedItem.getUserId());
    System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String 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
                    }
                ]
            }
        }
    }
}
public Recommender userBasedNeighborhoodBySimilarityForAll(RecommenderSimilarity recommenderSimilarity, int size, int howMany) throws App42Exception

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
RecommenderSimilarity recommenderSimilarity = RecommenderSimilarity.EUCLIDEAN_DISTANCE;
int size = 2;
int howMany = 3;						

Recommender recommender = recommenderService.userBasedNeighborhoodBySimilarityForAll(recommenderSimilarity, size, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("userId is " + recommendedItem.getUserId());
	System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
} 
String 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
                    }
                ]
            }
        }
    }
}
public Recommender userBasedThresholdBySimilarityForAll(RecommenderSimilarity recommenderSimilarity, double threshold, int howMany) throws App42Exception

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
RecommenderSimilarity recommenderSimilarity = RecommenderSimilarity.EUCLIDEAN_DISTANCE;
double threshold = 0.5;
int howMany = 4;
					
Recommender recommender = recommenderService.userBasedThresholdBySimilarityForAll(recommenderSimilarity, threshold, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("userId is " + recommendedItem.getUserId());
	System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}	
String 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
                    }
                ]
            }
        }
    }
}
public Recommender itemBasedForAll(int howMany) throws App42Exception

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
int howMany = 3;					

Recommender recommender = recommenderService.itemBasedForAll(howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("userId is " + recommendedItem.getUserId());
	System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String 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
                    }
                ]
            }
        }
    }
}
public Recommender itemBasedBySimilarityForAll(RecommenderSimilarity recommenderSimilarity, int howMany) throws App42Exception

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
 
RecommenderSimilarity recommenderSimilarity = RecommenderSimilarity.EUCLIDEAN_DISTANCE;
int howMany = 5;

Recommender recommender = recommenderService.itemBasedBySimilarityForAll(recommenderSimilarity, howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("userId is " + recommendedItem.getUserId());
	System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String 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
                    }
                ]
            }
        }
    }
}
public Recommender slopeOneForAll(int howMany) throws App42Exception

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
int howMany = 4;

Recommender recommender = recommenderService.slopeOneForAll(howMany);  /* returns the Recommender object. */ 
ArrayList<Recommender.RecommendedItem> recommendedItemList =  recommender.getRecommendedItemList(); 
for(Recommender.RecommendedItem recommendedItem : recommendedItemList)
{
    System.out.println("userId is " + recommendedItem.getUserId());
	System.out.println("item is " + recommendedItem.getItem());
	System.out.println("value is " + recommendedItem.getValue());
}
String 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
                    }
                ]
            }
        }
    }
}
public App42Response deleteAllPreferences() throws App42Exception

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


App42Response response = recommenderService.deleteAllPreferences(); /* returns the App42Response object. */
boolean  success = response.isResponseSuccess();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/         
{
   "app42": {
       "response": {
           "success": true
       }
   }
}