In this code pattern, you will create an iOS application using the Watson Tone Analyzer service. You will be able to analyze emotions and tones in what people write online, such as in tweets or reviews, and then predict whether they are happy, sad, confident, and more. Monitor customer service and support conversations so you can respond to your customers appropriately and at scale. Enable your chatbot to detect customer tones so you can build dialog strategies to adjust the conversation accordingly.
When you have completed this code pattern, you will understand how to:
As an alternative to the steps below, you can create this project as a starter kit on IBM Cloud, which automatically provisions required services, and injects service credentials into a custom fork of this pattern. Then, you can skip directly to step 4 below.
Ensure you have the required developer tools installed from Apple:
The IBM Cloud Mobile services SDK uses CocoaPods to manage and configure dependencies. To use our latest SDKs you need version 1.1.0.rc.2.
You can install CocoaPods using the following command:
$ sudo gem install cocoapods --pre
If the CocoaPods repository is not configured, run the following command:
$ pod setup
A pre-configured Podfile
is included in the root of this repository. To download and install the required dependencies, run the following command:
$ pod install
Open the Xcode workspace: toneanalyzerios.xcworkspace
. From now on, open the .xcworkspace
file because it contains all the dependencies and configurations.
If you run into any issues during the pod install, it is recommended to run a pod update by using the following commands:
$ pod update
$ pod install
This project uses the Watson Developer Cloud iOS SDK in order to use the Watson Tone Analyzer service.
The Watson Developer Cloud iOS SDK uses Carthage to manage dependencies and build binary frameworks.
You can install Carthage with Homebrew:
$ brew update
$ brew install carthage
A pre-configured Cartfile
is included in the root of this repository. Run the
following command to build the dependencies and frameworks:
$ carthage update --platform iOS
Note: You may have to run
carthage update --platform iOS --no-use-binaries
, if the binary is a lower version than your current version of Swift.
Once the build has completed, the frameworks can be found in the ios_swift/Carthage/Build/iOS/ folder. The Xcode project in this repository already includes framework links to the following frameworks in this directory:
If you build your Carthage frameworks in a separate folder, you will have to drag-and-drop the above frameworks into your project and link them in order to run it successfully.
Use the IBM Cloud Catalog to create a Tone Analyzer service instance on the Lite plan. Make sure to select Use both legacy credentials and IAM to receive the proper credential set for the Cloudant SDK.
When the service has been created, navigate to the Service credentials tab, and create a New credential ⊕ with the default options. Click View credentials. Edit toneanalyzerios/BMSCredentials.plist
in your Xcode project to configure your application with your Cloudant credentials.
You can now run the application on a simulator or physical device. Open the
Xcode workspace, toneanalyzerios.xcworkspace
, and use the play button to run
the app.
The application allows you to use the Watson Tone Analyzer service to analyze text. Tone Analyzer leverages cognitive linguistic analysis to identify a variety of tones at both the sentence and document level. This insight can then used to refine and improve communications. It detects three types of tones, including emotion (anger, disgust, fear, joy and sadness), social propensities (openness, conscientiousness, extroversion, agreeableness, and emotional range), and language styles (analytical, confident and tentative) from text. Enter text in the input text box and then click the Tone Analyzer button to see the results. The results will be shown under each category after the text has been analyzed. The tag visibility will change based on the percentage returned from Watson, but you can click on tag directly to see the exact percentage.
This code pattern is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.