Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

Analyzing text-based content posted on Twitter in Pega 7.1.9

Updated on September 6, 2017

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.

This tutorial takes approximately 30-40 minutes to complete.

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.

Do not use one instance of the Twitter data set in multiple data flows. If you stop one of the data flows, the Twitter data set in other data flows will also be stopped.
  1. In Designer Studio, click the Application menu and switch to your application.
  2. In the App Explorer, click <app_name> > Data Model > Data Set.
  3. Right-click Twitter and click Create.
  4. Name the data set TwitterData.
  5. From the Type list, select Twitter.
  6. Specify the context where you want to create the data set:
    • In the Apply to (class) field, select the Data-Social-Twitter class.
  7. Click Create and open.
  8. 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
  9. Optional: Provide the Klout Score API key.
  10. Optional: In the Keyword section, click Add keyword and enter the words that you want to find in tweets.
  11. In the Keyword section, you can also enter Twitter user names (for example @JohnSmith) that you want to find in tweets.
  12. Optional: In the Timeline section, click Add author, and enter the names of users whose tweets you want to analyze.
    Complete the Keyword or Timeline section; otherwise, you analyze all the tweets on the platform.
  13. Optional: In the Authors section, click Add author and enter the names of users whose tweets you want to ignore.
  14. Click Save.
If tweets are not fetched instantly from the Twitter data sets, synchronize the network clocks.

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.

  1. In the Records Explorer, click Decision > Free Text Model.
  2. Click Create.
  3. Name the rule SampleModel.
  4. Specify the context where you want to create the rule:
    • In the Apply to (class) field, select 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.
  5. Click Create and open.
  6. Enable sentiment analysis:
    1. Select the Enable sentiment analysis check box.
    2. In the Lexicon field, select pySentimentLexicon.
    3. In the Sentiment model field, select pySentimentModels.
  7. Click the I/O Mapping tab.
  8. In the Input text field, set the .pyText property.
  9. In the Outcome field, set the .NLPOutcome NLPOutcomeproperty.
    If the property does not exist, create it as a single-page property defined on the Data-NLP-Outcome class.
  10. Click Save.

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.

Create the NLPProcess data flow in the same class as the TwitterData data set.
  1. In the Records Explorer, click Data Model > Data Flow.
  2. Click Create.
  3. Name the rule NLPProcess.
  4. Specify the context where you want to create the rule:
    • In the Apply to (class) field, select the Data-Social-Twitter class.
  5. Click Create and open.
  6. Double-click the Source shape.
    1. In Source properties dialog box, from the Source list, select Data set.
    2. From the Data set list, select TwitterData and click Submit.
  7. Navigate to the Source shape and click the green Add icon.
  8. From the list, select Free Text Model.
  9. Double-click the Free Text Model shape.
    1. In the Free Text Model properties dialog box, in the Free Text Model field, reference the SampleModel rule.
    2. Click Submit.
  10. Navigate to the Free Text Model shape and click the green Add icon.
  11. From the list, select Filter.
  12. Double-click the Filter shape.
    1. Name the shape Sentiment.
    2. 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.
    3. Click Submit.
  13. Click the Destination shape.
    1. In the Destination properties dialog box, from the Destination list, select Activity.
    2. In the Activity field, reference the following activity: pxSaveSummaryForReporting.
    3. Click Submit.
  14. Click Save.

Analyzing tweets

Activate the NLPProcess data flow and keep it active until it processes some records (tweets).

  1. In Designer Studio, click the Application menu and switch to your application.
  2. Open the NLPProcess data flow.
  3. Click Actions > Run.
  4. In the Data Flow Test Run dialog box, click Activate.
  5. 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.

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us