This is the code from my NEXT 2018 talk of the same title.
In the demo, I use Google Forms, Cloud Natural Language, Google Sheets, and Apps Script to analyze vacation rental reviews. I use Cloud Natural Languages's Entity Sentiment Analysis method, which combines both entity analysis and sentiment analysis and attempts to determine the sentiment (positive or negative) expressed about entities within the text.
A video of the talk is available on YouTube.
-
Create a Google Form modeled after this template: Post-stay review form template.
-
Choose to collect form responses in a spreasheet following the instructions in this support article.
-
Access the response spreadsheet and add two additional tabs. Name these tabs "Review Data" and "Entity Sentiment Data", and add headers in row 1 exactly as in this template: Post-stay reviews spreadsheet template.
- From your response spreadsheet, access the Script Editor from the Tools menu.
- Create three script files preprocess.gs, nlcall.gs, and apikey.gs.
- Click Save.
- The API call to Cloud Natural Language (in nlcall.gs) requires a Google Cloud Platform account and project. You can sign up for the Free Trial of Google Cloud Platform at https://cloud.google.com/free/.
- Once you have a project, enable the Google Natural Language API and create an API key.
- Copy the API key into apikey.gs, replacing YOUR_KEY_HERE but maintaining the quotes.
- From the Edit menu within the Script Editor, choose Current Project Triggers.
- Choose to run "onFormSubmit", "From spreadsheet", "On form submit". Set notifications to immediately (for any debugging; you may change this later).
Now's your chance to try it out!
- Open the Google Form and submit a response (you may submit your own text, or use the reviews from the Boston Airbnb Open Data on Kaggle.
- Check to see the response populates on both the "Form Responses" tab and the "Review Data" tab.
- Confirm that columns F and G of the "Review Data" tab have populated with the formula to detect the text language and translate non-English text into English (these are part of preprocess.gs).
- Finally, from the 'Demo Tools' menu in the responses sheet, select 'Mark Entities and Sentiment' (if you do not see this menu, reload the spreadsheet). This will kick off the markEntitySentiment function from nlcall.gs. You should see column H in the "Review Data" tab start to populate each row as "complete", while the API response data received back from Cloud Natural Lanaguage (entities and their sentiment) are flowing into the "Entity Sentiment Data" tab.
Bonus: Once you have processed your data, you may consider visualizing it using Data Studio. You can view my Data Studio report if you like.
For more detailed information on a similar demo, check out my blog post "Analyzing text in a Google Sheet using Cloud Natural Language API and Apps Script"
Let me know if you run into any problems!
NOTE: This is not an official Google product.