copyright | lastupdated | ||
---|---|---|---|
|
2017-11-03 |
{:shortdesc: .shortdesc} {:new_window: target="_blank"} {:tip: .tip} {:pre: .pre} {:codeblock: .codeblock} {:screen: .screen} {:javascript: .ph data-hd-programlang='javascript'} {:java: .ph data-hd-programlang='java'} {:python: .ph data-hd-programlang='python'} {:swift: .ph data-hd-programlang='swift'} {:download: .download}
In this short tutorial, we introduce {{site.data.keyword.nlushort}} by analyzing some sample text for sentiment. {:shortdesc}
{: #before-you-begin}
- Create an instance of the service:
- {: download} If you're seeing this, you created your service instance. Now get your credentials.
- Create a project from a service:
- Go to the {{site.data.keyword.watson}} Developer Console Services {: new_window} page.
- Select {{site.data.keyword.nlushort}}, click Add Services, and either sign up for a free {{site.data.keyword.Bluemix_notm}} account or log in.
- Type
sentiment-tutorial
as the project name and click Create Project.
- Copy the credentials to authenticate to your service instance:
- {: download} From the service dashboard (what you're looking at):
- Click the Service credentials tab.
- Click View credentials under Actions.
- Copy the
username
,password
, andurl
values. {: download}
- From your sentiment-tutorial project in the Developer Console, copy the
username
,password
, andurl
values for"natural_language_understanding"
from the Credentials section.
- {: download} From the service dashboard (what you're looking at):
- Make sure you have cURL:
- The examples use cURL to call methods of the HTTP interface. Install the version for your operating system from curl.haxx.se {: new_window}. Install the version that supports the Secure Sockets Layer (SSL) protocol. Make sure to include the installed binary file on your
PATH
environment variable.
- The examples use cURL to call methods of the HTTP interface. Install the version for your operating system from curl.haxx.se {: new_window}. Install the version that supports the Secure Sockets Layer (SSL) protocol. Make sure to include the installed binary file on your
If you use {{site.data.keyword.Bluemix_dedicated_notm}}, create your service instance from the {{site.data.keyword.nlushort}} {: new_window} page in the Catalog. For details about how to find your service credentials, see Service credentials for Watson services {: new_window}.
{: #analyze-sample}
First, analyze the sentiment of some sample text. Open a command-line interface and run the following command to call the GET /v1/analyze
method, which analyzes the sample text for sentiment and keywords. Replace {username}
and {password}
with the service credentials you copied in the previous step:
curl --user "{username}":"{password}" \
"https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27&text=I%20still%20have%20a%20dream%2C%20a%20dream%20deeply%20rooted%20in%20the%20American%20dream%20%E2%80%93%20one%20day%20this%20nation%20will%20rise%20up%20and%20live%20up%20to%20its%20creed%2C%20%22We%20hold%20these%20truths%20to%20be%20self%20evident%3A%20that%20all%20men%20are%20created%20equal.&features=sentiment,keywords"
{:pre}
{: #analyze-keywords}
The previous call returned sentiment information for the whole text. Now expand the results to return sentiment analysis specifically on each of the keywords. Include the keywords.sentiment parameter and set it to true
. Replace {username}
and {password}
with your information.
curl --user "{username}":"{password}" \
"https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27&text=I%20still%20have%20a%20dream%2C%20a%20dream%20deeply%20rooted%20in%20the%20American%20dream%20%E2%80%93%20one%20day%20this%20nation%20will%20rise%20up%20and%20live%20up%20to%20its%20creed%2C%20%22We%20hold%20these%20truths%20to%20be%20self%20evident%3A%20that%20all%20men%20are%20created%20equal.&features=sentiment,keywords&keywords.sentiment=true"
{:pre}
{: #analyze-phrase}
Now target specific content to see a sentence-level or phrase-level analysis (instead of a document or keyword analysis) by including the phrase the%20American%20dream%20
in the sentiment.targets parameter. Don't forget to replace {username}
and {password}
with your information.
curl --user "{username}":"{password}" \
"https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27&text=I%20still%20have%20a%20dream%2C%20a%20dream%20deeply%20rooted%20in%20the%20American%20dream%20one%20day%20this%20nation%20will%20rise%20up%20and%20live%20up%20to%20its%20creed%20We%20hold%20these%20truths%20to%20be%20self%20evident%3A%20that%20all%20men%20are%20created%20equal.&features=sentiment,keywords&keywords.sentiment=true&sentiment.targets=the%20American%20dream"
{:pre}
{: #next-steps}
You're done! This tutorial barely scratches the surface of what you can accomplish with {{site.data.keyword.nlushort}}. For more information about the features of the API, see these resources:
- View the API Reference {: new_window} for details and examples of each of the parameters.
- Learn how to identify custom entities and relations.