use of software.amazon.awssdk.services.personalizeruntime.model.GetPersonalizedRankingResponse 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;
}
Aggregations