Search in sources :

Example 1 with PersonalizeRuntimeException

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

the class GetPersonalizedRanking method getRankedRecs.

// snippet-start:[personalize.java2.get_personalized_ranking.main]
public static List<PredictedItem> getRankedRecs(PersonalizeRuntimeClient personalizeRuntimeClient, String campaignArn, String userId, ArrayList<String> items) {
    try {
        GetPersonalizedRankingRequest rankingRecommendationsRequest = GetPersonalizedRankingRequest.builder().campaignArn(campaignArn).userId(userId).inputList(items).build();
        GetPersonalizedRankingResponse recommendationsResponse = personalizeRuntimeClient.getPersonalizedRanking(rankingRecommendationsRequest);
        List<PredictedItem> rankedItems = recommendationsResponse.personalizedRanking();
        int rank = 1;
        for (PredictedItem item : rankedItems) {
            System.out.println("Item ranked at position " + rank + " details");
            System.out.println("Item Id is : " + item.itemId());
            System.out.println("Item score is : " + item.score());
            System.out.println("---------------------------------------------");
            rank++;
        }
        return rankedItems;
    } catch (PersonalizeRuntimeException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return null;
}
Also used : PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) GetPersonalizedRankingResponse(software.amazon.awssdk.services.personalizeruntime.model.GetPersonalizedRankingResponse) PersonalizeRuntimeException(software.amazon.awssdk.services.personalizeruntime.model.PersonalizeRuntimeException) GetPersonalizedRankingRequest(software.amazon.awssdk.services.personalizeruntime.model.GetPersonalizedRankingRequest)

Example 2 with PersonalizeRuntimeException

use of software.amazon.awssdk.services.personalizeruntime.model.PersonalizeRuntimeException 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)

Aggregations

PersonalizeRuntimeException (software.amazon.awssdk.services.personalizeruntime.model.PersonalizeRuntimeException)2 PredictedItem (software.amazon.awssdk.services.personalizeruntime.model.PredictedItem)2 HashMap (java.util.HashMap)1 GetPersonalizedRankingRequest (software.amazon.awssdk.services.personalizeruntime.model.GetPersonalizedRankingRequest)1 GetPersonalizedRankingResponse (software.amazon.awssdk.services.personalizeruntime.model.GetPersonalizedRankingResponse)1 GetRecommendationsRequest (software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest)1 GetRecommendationsResponse (software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsResponse)1