Search in sources :

Example 1 with PersonalizeRuntimeClient

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

the class PersonalizeDemoOnMovieLens20M method main.

public static void main(String[] args) throws Exception {
    // Pre-flight step - 1
    // Set credentials provider, s3 and personalize clients
    // AWSStaticCredentialsProvider cred = getCredentialsProvider();
    S3Client s3Client = S3Client.builder().region(region).build();
    PersonalizeEventsClient personalizeEventsClient = PersonalizeEventsClient.builder().region(region).build();
    PersonalizeClient personalizeClient = PersonalizeClient.builder().region(region).build();
    PersonalizeRuntimeClient personalizeRuntimeClient = PersonalizeRuntimeClient.builder().region(region).build();
    IamClient iamClient = IamClient.builder().region(Region.AWS_GLOBAL).build();
    // Pre-flight step - 2
    // Identify your datasets and export them to S3 bucket
    DatasetProvider datasetProvider = new MovieLensDatasetProvider();
    datasetProvider.exportDatasetToS3(DatasetType.INTERACTIONS, s3Client, S3_BUCKET, true);
    // Pre-flight step - 3
    // Personalize needs the ability to assume Roles in AWS in order to have the permissions to execute certain tasks, the lines below grant that.
    DemoUtils.ensurePersonalizePermissionsOnS3Bucket(s3Client, S3_BUCKET);
    // Pre-flight step - 4
    // Ensure S3 bucket is accessible by Personalize
    String role = PREFIX + "-role";
    String roleArn = DemoUtils.createPersonalizeRole(iamClient, role);
    // Step 1
    // Create dataset group
    // Create dataset schemas
    // Create datasets
    String datasetGroupArn = createSchemaAndDatasets(personalizeClient, datasetProvider, roleArn);
    // step 2
    // create solution and solution version
    final String userPersonalizationRecipeArn = "arn:aws:personalize:::recipe/aws-user-personalization";
    final String userPersonalizationSolutionName = PREFIX + "-user-personalization-solution";
    final String awsUserPersonalizeSVArn = createSolutionAndSolutionVersion(personalizeClient, datasetGroupArn, userPersonalizationRecipeArn, userPersonalizationSolutionName);
    System.out.println("AWS User Personalization solution and solution version created");
    final String simsRecipeArn = "arn:aws:personalize:::recipe/aws-sims";
    final String simsSolutionName = PREFIX + "-sims-solution";
    final String simsSVArn = createSolutionAndSolutionVersion(personalizeClient, datasetGroupArn, simsRecipeArn, simsSolutionName);
    System.out.println("SIMS solution and solution version created");
    // step 3
    // setup campaign
    final String userPersonalizationCampaignName = PREFIX + "-user-personalization-campaign";
    final CampaignManager userPersonalizationCM = new CampaignManager(personalizeClient, userPersonalizationCampaignName, awsUserPersonalizeSVArn);
    final String userPersonalizationCampaignArn = userPersonalizationCM.createAndWaitForResource(true);
    System.out.println("AWS User Personalization campaign deployed");
    final String simsCampaignName = PREFIX + "-sims-campaign";
    final CampaignManager simsCM = new CampaignManager(personalizeClient, simsCampaignName, simsSVArn);
    final String simsCampaignArn = simsCM.createAndWaitForResource(true);
    System.out.println("SIMS campaign deployed");
    // Step 4
    // Create event tracker for real time events
    // AmazonPersonalizeEvents personalizeEvents = AmazonPersonalizeEventsClientBuilder.standard().withCredentials(cred).build();
    final String eventTrackerName = PREFIX + "-event-tracker";
    final EventTrackerManager etm = new EventTrackerManager(personalizeClient, eventTrackerName, datasetGroupArn);
    final String eventTackerArn = etm.createAndWaitForResource(true);
    final String eventTrackingId = etm.getTrackingId(eventTackerArn);
    System.out.println("Event tracker created");
    // step 5
    // create runtime client for demo
    runWebDemo(personalizeRuntimeClient, personalizeEventsClient, userPersonalizationCampaignArn, simsCampaignArn, eventTrackingId, datasetProvider);
}
Also used : PersonalizeClient(software.amazon.awssdk.services.personalize.PersonalizeClient) PersonalizeRuntimeClient(software.amazon.awssdk.services.personalizeruntime.PersonalizeRuntimeClient) IamClient(software.amazon.awssdk.services.iam.IamClient) CampaignManager(com.amazonaws.personalize.client.resource.CampaignManager) MovieLensDatasetProvider(com.amazonaws.personalize.client.datasets.MovieLensDatasetProvider) S3Client(software.amazon.awssdk.services.s3.S3Client) PersonalizeEventsClient(software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient) EventTrackerManager(com.amazonaws.personalize.client.resource.EventTrackerManager) DatasetProvider(com.amazonaws.personalize.client.datasets.DatasetProvider) MovieLensDatasetProvider(com.amazonaws.personalize.client.datasets.MovieLensDatasetProvider)

Example 2 with PersonalizeRuntimeClient

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

the class GetPersonalizedRanking method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    GetPersonalizedRanking <campaignArn> <userId> <items>\n\n" + "Where:\n" + "    campaignArn - The ARN of the campaign.\n" + "    userId - The user ID to provide recommendations for.\n" + "    itemList - A comma delimited list of items to rank for the user\n\n";
    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String campaignArn = args[0];
    String userId = args[1];
    ArrayList<String> items = new ArrayList<>(Arrays.asList(args[2].split("\\s*,\\s*")));
    Region region = Region.US_EAST_1;
    PersonalizeRuntimeClient personalizeRuntimeClient = PersonalizeRuntimeClient.builder().region(region).build();
    getRankedRecs(personalizeRuntimeClient, campaignArn, userId, items);
    personalizeRuntimeClient.close();
}
Also used : PersonalizeRuntimeClient(software.amazon.awssdk.services.personalizeruntime.PersonalizeRuntimeClient) ArrayList(java.util.ArrayList) Region(software.amazon.awssdk.regions.Region)

Example 3 with PersonalizeRuntimeClient

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

the class GetRecommendations method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    GetRecommendations <campaignArn> <userId>\n\n" + "Where:\n" + "    campaignArn - The ARN of the campaign.\n\n" + "    userId - The user ID to provide recommendations for\n\n";
    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String campaignArn = args[0];
    String userId = args[1];
    Region region = Region.US_EAST_1;
    PersonalizeRuntimeClient personalizeRuntimeClient = PersonalizeRuntimeClient.builder().region(region).build();
    getRecs(personalizeRuntimeClient, campaignArn, userId);
    personalizeRuntimeClient.close();
}
Also used : PersonalizeRuntimeClient(software.amazon.awssdk.services.personalizeruntime.PersonalizeRuntimeClient) Region(software.amazon.awssdk.regions.Region)

Example 4 with PersonalizeRuntimeClient

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

the class FilterRecommendations method main.

public static void main(String[] args) {
    // This example shows how to use a filter with an expression that has
    // two placeholder parameters, and passes two values to the first and one to the second.
    // in the GetRecommendations request.
    // Your filter may not have the same number of parameters or you may not want to use two values.
    // Change the following code and the PersonalizeTest.java code based on the number of parameters
    // your expression uses and the values you want to pass.
    final String USAGE = "\n" + "Usage:\n" + "    GetRecommendations <campaignArn> <userId> <filterArn> <parameter1Name> " + "       <parameter1Value1> <parameter1Value2> <parameter2Name> <parameter2Value>\n\n" + "Where:\n" + "    campaignArn - The Amazon Resource Name (ARN) of the campaign.\n\n" + "    userId - The user ID to provide recommendations for." + "    filterArn - The ARN of the filter to use." + "    parameter1Name - The name of the first placeholder parameter in the filter." + "    parameter1Value1 - The first value to pass to the first parameter." + "    parameter1Value2 - The second value to pass to the first parameter." + "    parameter2Name = The name of the second placeholder parameter in the filter." + "    parameter2Value = The value to pass to the second parameter\n\n";
    if (args.length != 8) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String campaignArn = args[0];
    String userId = args[1];
    String filterArn = args[2];
    String parameter1Name = args[3];
    String parameter1Value1 = args[4];
    String parameter1Value2 = args[5];
    String parameter2Name = args[6];
    String parameter2Value = args[7];
    Region region = Region.US_EAST_1;
    PersonalizeRuntimeClient personalizeRuntimeClient = PersonalizeRuntimeClient.builder().region(region).build();
    getFilteredRecs(personalizeRuntimeClient, campaignArn, userId, filterArn, parameter1Name, parameter1Value1, parameter1Value2, parameter2Name, parameter2Value);
    personalizeRuntimeClient.close();
}
Also used : PersonalizeRuntimeClient(software.amazon.awssdk.services.personalizeruntime.PersonalizeRuntimeClient) Region(software.amazon.awssdk.regions.Region)

Aggregations

PersonalizeRuntimeClient (software.amazon.awssdk.services.personalizeruntime.PersonalizeRuntimeClient)4 Region (software.amazon.awssdk.regions.Region)3 DatasetProvider (com.amazonaws.personalize.client.datasets.DatasetProvider)1 MovieLensDatasetProvider (com.amazonaws.personalize.client.datasets.MovieLensDatasetProvider)1 CampaignManager (com.amazonaws.personalize.client.resource.CampaignManager)1 EventTrackerManager (com.amazonaws.personalize.client.resource.EventTrackerManager)1 ArrayList (java.util.ArrayList)1 IamClient (software.amazon.awssdk.services.iam.IamClient)1 PersonalizeClient (software.amazon.awssdk.services.personalize.PersonalizeClient)1 PersonalizeEventsClient (software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient)1 S3Client (software.amazon.awssdk.services.s3.S3Client)1