Skip to content

Latest commit

 

History

History
89 lines (68 loc) · 6.03 KB

getting-started.md

File metadata and controls

89 lines (68 loc) · 6.03 KB
copyright lastupdated
years
2015, 2017
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}

Getting started tutorial

In this short tutorial, we introduce {{site.data.keyword.nlushort}} by analyzing some sample text for sentiment. {:shortdesc}

Before you begin

{: #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:
      1. Go to the {{site.data.keyword.watson}} Developer Console Services External link icon{: new_window} page.
      2. Select {{site.data.keyword.nlushort}}, click Add Services, and either sign up for a free {{site.data.keyword.Bluemix_notm}} account or log in.
      3. 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):
      1. Click the Service credentials tab.
      2. Click View credentials under Actions.
      3. Copy the username, password, and url values. {: download}
    • From your sentiment-tutorial project in the Developer Console, copy the username, password, and url values for "natural_language_understanding" from the Credentials section.
  • 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 External link icon{: 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.

If you use {{site.data.keyword.Bluemix_dedicated_notm}}, create your service instance from the {{site.data.keyword.nlushort}} External link icon{: new_window} page in the Catalog. For details about how to find your service credentials, see Service credentials for Watson services External link icon{: new_window}.

Step 1: Analyze sample content for sentiment

{: #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}

Step 2: Return keyword information

{: #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}

Step 3: Target a phrase

{: #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

{: #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: