Analyzing text-based content posted on Twitter in Pega 7.1.9
You can use Pega 7 Platform text analytics to analyze text-based content in news feeds, emails, and postings on social media streams such as Facebook, Twitter, and YouTube. This tutorial explains how to configure the Pega 7 Platform to analyze the text-based content of tweets.
Companies around the world use Twitter as a marketing communications tool. Twitter users engage in conversations and use hashtags to discuss various topics. These conversations can include customer complaints, questions about products or services, and recommendations. By using the text analytics capability of the Pega 7 Platform, companies can analyze particular tweets to reveal authors' intentions and sentiment, influence enterprise decisions, and get strategic insights.
- Prerequisites
- Creating an instance of the Twitter data set
- Creating an instance of the Free Text Model rule
- Creating an instance of the Data Flow rule
- Analyzing tweets
Prerequisites
- Register a Twitter app for your Twitter account on the Twitter apps portal. This step is required to obtain OAuth settings (Consumer key, Consumer secret, Access token, Access token secret).
- Optional: Obtain a Klout Score API key from the Klout website. Klout is a widely used metric that determines the breadth and strength of a person's online social influence.
- Add the PEGA-NLP ruleset to your application.
Creating an instance of the Twitter data set
Create a Twitter data set called TwitterData to connect with the Twitter API. When specifying numerous keywords and authors, take into consideration Twitter Rest API limitations. For more information, read the documentation about the Twitter REST APIs.
- In Designer Studio, click the menu and switch to your application.
- In the App Explorer, click <app_name> > Data Model > Data Set.
- Right-click Twitter and click Create.
- Name the data set TwitterData.
- From the Type list, select Twitter.
- Specify the context where you want to create the data set:
- In the Data-Social-Twitter class. field, select the
- Click .
- On the Twitter tab, complete the Access details section with the OAuth settings from the Twitter app that you created:
- Consumer key
- Consumer secret
- Access token
- Access token secret
- Optional: Provide the Klout Score API key.
- Optional: In the Add keyword and enter the words that you want to find in tweets. section, click
- In the section, you can also enter Twitter user names (for example @JohnSmith) that you want to find in tweets.
- Optional: In the Add author, and enter the names of users whose tweets you want to analyze.
Complete the or section; otherwise, you analyze all the tweets on the platform. section, click
- Optional: In the Authors section, click Add author and enter the names of users whose tweets you want to ignore.
- Click Save.
Creating an instance of the Free Text Model rule
Create a Free Text Model rule called SampleModel and configure it to analyze sentiment only. For more information, see Free Text Model rule.
- In the Records Explorer, click Decision > Free Text Model.
- Click Create.
- Name the rule SampleModel.
- Specify the context where you want to create the rule:
- In the Data-Social-Twitter class.
You do not need to create the SampleModel rule in the same class as the TwitterData data set, but it must be in the Data-Social-Twitter class hierarchy. You can use the top-level class or the base class. field, select the
- In the Data-Social-Twitter class.
- Click .
- Enable sentiment analysis:
- Select the Enable sentiment analysis check box.
- In the pySentimentLexicon. field, select
- In the pySentimentModels. field, select
- Click the I/O Mapping tab.
- In the field, set the .pyText property.
- In the .NLPOutcome NLPOutcomeproperty.
If the property does not exist, create it as a single-page property defined on the Data-NLP-Outcome class. field, set the - Click .
Creating an instance of the Data Flow rule
Create a data flow called NLPProcess to reference the SampleModel rule and process tweets handled by the TwitterData data set.
- In the Records Explorer, click Data Model > Data Flow.
- Click Create.
- Name the rule NLPProcess.
- Specify the context where you want to create the rule:
- In the Data-Social-Twitter class. field, select the
- Click .
- Double-click the Source shape.
- In Source properties dialog box, from the list, select
- From the TwitterData and click Submit. list, select
- Navigate to the Source shape and click the green Add icon.
- From the list, select Free Text Model.
- Double-click the Free Text Model shape.
- In the Free Text Model properties dialog box, in the field, reference the SampleModel rule.
- Click Submit.
- Navigate to the Free Text Model shape and click the green Add icon.
- From the list, select Filter.
- Double-click the Filter shape.
- Name the shape Sentiment.
- In the Filter conditions section, specify the following condition: .NLPOutcome.pyOverallSentiment = "negative"The outcome property that you use in the filter must be the same as the one that you specified in the SampleModel rule.
- Click Submit.
- Click the Destination shape.
- In the Destination properties dialog box, from the Destination list, select Activity.
- In the Activity field, reference the following activity: pxSaveSummaryForReporting.
- Click Submit.
- Click Save.
Analyzing tweets
Activate the NLPProcess data flow and keep it active until it processes some records (tweets).
- In Designer Studio, click the Application menu and switch to your application.
- Open the NLPProcess data flow.
- Click Actions > Run.
- In the Data Flow Test Run dialog box, click Activate.
- Wait until the data flow processes some records.
You created the NLPProcess data flow, which uses the TwitterData data set and the SampleModel rule. The TwitterData data set allows you to filter tweets according to the keywords that you specified in it. The SampleModel rule checks the overall sentiment of the tweets' text-based content. At the end, the tweets with negative sentiment are saved in the pxSaveSummaryForReporting property. You can use a report definition to retrieve information from this property.