Add Review Data

Adding reviews with text analysis

Next, you are going to add a feedback section to your website. However, you will also use the Amazon Comprehend service to gather sentiment, key phrases, and entities out of the review. The sentiment will be used to customize the message back to the end user. We will then store the additional entities and phrases so that they can later be analyzed.

AWS Amplify provides the ability to add recommendations by using the amplify add predictions category.

The predictions category in Amplify is an abstraction of several AWS AI Services, including:
Amazon Transcribe - Converts speech to text
Amazon Polly - Converts text to speech
Amazon Rekognition - Performs image and video analysis
Amazon Translate - translates text between languages
Amazon Comprehend - Extracts data from text

Run the following command in your Cloud9 terminal:

amplify add predictions

Next, select Interpret: Add Interactions

Select Interpret Text, enter a name of textInterpret and then choose All: Add Interactions

Choose Auth and Guest users Add Interactions

Add Reviews to our Data API

It is important to save our review data and the analysis of the feedback that we receive from customers, so that we can later apply business intelligence to our data. To do this, we need to add the following code to our graphql.schema file. Open the file located at amplify/backend/api/andypizzashop/schema.graphql

APPEND the following data to the end of the schema file and save schema.graphql:

# Added for reviews
type Review @model {
  id: ID!
  comments: String
  dateAdded: AWSDateTime
  sentiment: String
  username: String
}

type ReviewPhrase @model {
  id: ID!
  phraseText: String
  phraseType: String
  dateAdded: AWSDateTime
  username: String
}

Again, perform an amplify push and Amplify will update AppSync to add the new data model to our api:

amplify push

Add Interactions

Select Yes to the questions for generating the API code, and amplify will push the changes to AWS.

Add Interactions

This will take a few minutes to complete. Once deployment is finished, move on to the next step to add the review functionality to the application.