Search in sources :

Example 1 with GetRecommendationsRequest

use of software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest in project aws-doc-sdk-examples by awsdocs.

the class AmazonPersonalizeRecommender method getItemsForUser.

public List<Item> getItemsForUser(String userId) {
    List<Item> list = new ArrayList<>();
    try {
        GetRecommendationsRequest recommendationsRequest = GetRecommendationsRequest.builder().campaignArn(userPersonalizationCampaignArn).numResults(20).userId(userId).build();
        GetRecommendationsResponse recommendationsResponse = personalizeRuntimeClient.getRecommendations(recommendationsRequest);
        List<PredictedItem> items = recommendationsResponse.itemList();
        for (PredictedItem item : items) {
            list.add(new Item(item.itemId(), itemIdToNameMap.get(item.itemId())));
        }
    } catch (AwsServiceException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return list;
}
Also used : PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) GetRecommendationsRequest(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest) PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) ArrayList(java.util.ArrayList) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) GetRecommendationsResponse(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsResponse)

Example 2 with GetRecommendationsRequest

use of software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest in project aws-doc-sdk-examples by awsdocs.

the class AmazonPersonalizeRecommender method getItemsForItem.

public List<Item> getItemsForItem(String itemId) {
    List<Item> list = new ArrayList<>();
    try {
        GetRecommendationsRequest simsRequest = GetRecommendationsRequest.builder().campaignArn(simsCampaignArn).itemId(itemId).build();
        GetRecommendationsResponse simsResponse = personalizeRuntimeClient.getRecommendations(simsRequest);
        List<PredictedItem> items = simsResponse.itemList();
        for (PredictedItem item : items) {
            list.add(new Item(item.itemId(), itemIdToNameMap.get(item.itemId())));
        }
    } catch (AwsServiceException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return list;
}
Also used : PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) GetRecommendationsRequest(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest) PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) ArrayList(java.util.ArrayList) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) GetRecommendationsResponse(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsResponse)

Example 3 with GetRecommendationsRequest

use of software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest in project aws-doc-sdk-examples by awsdocs.

the class FilterRecommendations method getFilteredRecs.

// snippet-start:[personalize.java2.filter_recommendations.main]
public static void getFilteredRecs(PersonalizeRuntimeClient personalizeRuntimeClient, String campaignArn, String userId, String filterArn, String parameter1Name, String parameter1Value1, String parameter1Value2, String parameter2Name, String parameter2Value) {
    try {
        Map<String, String> filterValues = new HashMap<>();
        filterValues.put(parameter1Name, String.format("\"%1$s\",\"%2$s\"", parameter1Value1, parameter1Value2));
        filterValues.put(parameter2Name, String.format("\"%1$s\"", parameter2Value));
        GetRecommendationsRequest recommendationsRequest = GetRecommendationsRequest.builder().campaignArn(campaignArn).numResults(20).userId(userId).filterArn(filterArn).filterValues(filterValues).build();
        GetRecommendationsResponse recommendationsResponse = personalizeRuntimeClient.getRecommendations(recommendationsRequest);
        List<PredictedItem> items = recommendationsResponse.itemList();
        for (PredictedItem item : items) {
            System.out.println("Item Id is : " + item.itemId());
            System.out.println("Item score is : " + item.score());
        }
    } catch (PersonalizeRuntimeException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetRecommendationsRequest(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest) HashMap(java.util.HashMap) PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) PersonalizeRuntimeException(software.amazon.awssdk.services.personalizeruntime.model.PersonalizeRuntimeException) GetRecommendationsResponse(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsResponse)

Example 4 with GetRecommendationsRequest

use of software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest in project aws-doc-sdk-examples by awsdocs.

the class GetRecommendations method getRecs.

// snippet-start:[personalize.java2.get_recommendations.main]
public static void getRecs(PersonalizeRuntimeClient personalizeRuntimeClient, String campaignArn, String userId) {
    try {
        GetRecommendationsRequest recommendationsRequest = GetRecommendationsRequest.builder().campaignArn(campaignArn).numResults(20).userId(userId).build();
        GetRecommendationsResponse recommendationsResponse = personalizeRuntimeClient.getRecommendations(recommendationsRequest);
        List<PredictedItem> items = recommendationsResponse.itemList();
        for (PredictedItem item : items) {
            System.out.println("Item Id is : " + item.itemId());
            System.out.println("Item score is : " + item.score());
        }
    } catch (AwsServiceException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetRecommendationsRequest(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest) PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) GetRecommendationsResponse(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsResponse)

Aggregations

GetRecommendationsRequest (software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest)4 GetRecommendationsResponse (software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsResponse)4 PredictedItem (software.amazon.awssdk.services.personalizeruntime.model.PredictedItem)4 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 PersonalizeRuntimeException (software.amazon.awssdk.services.personalizeruntime.model.PersonalizeRuntimeException)1