copyright | lastupdated | subcollection | ||
---|---|---|---|---|
|
2019-03-07 |
personality-insights |
{:shortdesc: .shortdesc} {:new_window: target="_blank"} {:tip: .tip} {:important: .important} {:note: .note} {:deprecated: .deprecated} {:pre: .pre} {:codeblock: .codeblock} {:screen: .screen} {:javascript: .ph data-hd-programlang='javascript'} {:go: .ph data-hd-programlang='go'} {:java: .ph data-hd-programlang='java'} {:python: .ph data-hd-programlang='python'} {:swift: .ph data-hd-programlang='swift'} {:download: .download} {:apikey: data-credential-placeholder='apikey'} {:url: data-credential-placeholder='url'} {:hide-dashboard: .hide-dashboard}
{: #gettingStarted}
The {{site.data.keyword.personalityinsightsfull}} service derives insights about personality characteristics from social media, enterprise data, or other digital communications. This tutorial can help you get started quickly with the {{site.data.keyword.personalityinsightsshort}} service. The examples show you how to call the service's POST /v3/profile
method with different types of input and how to request different types of output and output formats.
{: shortdesc}
The tutorial uses {{site.data.keyword.cloud}} Identity and Access Management (IAM) API keys for authentication. Older service instances might continue to use the {username}
and {password}
from their existing Cloud Foundry service credentials for authentication. Authenticate by using the approach that is right for your service instance. For more information about the service's use of IAM authentication, see the 30 October 2018 service update in the release notes.
{: important}
{: #before-you-begin}
- {: hide-dashboard} Create an instance of the service:
- {: hide-dashboard} Go to the {{site.data.keyword.personalityinsightsshort}} {: new_window} page in the {{site.data.keyword.cloud_notm}} Catalog.
- {: hide-dashboard} Sign up for a free {{site.data.keyword.cloud_notm}} account or log in.
- {: hide-dashboard} Click Create.
- Copy the credentials to authenticate to your service instance:
- {: hide-dashboard} From the {{site.data.keyword.cloud_notm}} dashboard {: new_window}, click on your {{site.data.keyword.personalityinsightsshort}} service instance to go to the {{site.data.keyword.personalityinsightsshort}} service dashboard page.
- On the Manage page, click Show to view your credentials.
- Copy the
API Key
andURL
values.
- Make sure that you have the
curl
command.- The examples use the
curl
command 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 yourPATH
environment variable.
- The examples use the
When you enter a command, replace {apikey}
and {url}
with your actual API key and URL. Omit the braces, which indicate a variable value, from the command. An actual value resembles the following example:
{: hide-dashboard}
curl -X POST -u "apikey:L_HALhLVIksh1b73l97LSs6R_3gLo4xkujAaxm7i-b9x"
. . .
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13"
{:pre} {: hide-dashboard}
{: #example1}
The first example passes the plain text file profile.txt
to the POST /v3/profile
method and requests a JSON response.
-
Download the sample file profile.txt .
-
Issue the following command to send the file to the
/v3/profile
method and request a JSON response.- The
Content-Type
header specifies that the input is plain text,text/plain
. Thecharset
parameter included with the header identifies the character encoding of the input text. - The
Accept
header specifiesapplication/json
to indicate that JSON output is requested. - {: hide-dashboard} Replace
{apikey}
and{url}
with your information. - Modify
{path_to_file}
to specify the location of theprofile.txt
file.
curl -X POST -u "apikey:{apikey}"{: apikey} \ --header "Content-Type: text/plain;charset=utf-8" \ --header "Accept: application/json" \ --data-binary @{path_to_file}profile.txt \ "{url}/v3/profile?version=2017-10-13"{: url}
{: pre}
- The
The service returns a JSON Profile
object that includes basic metadata such as the number of words in the input, the language model with which the input was processed, and any warnings associated with the input. For more information, see The Profile object.
The profile includes information about the Big Five personality, Needs, and Values characteristics for the author as inferred from the input text. The service reports a percentile
, or normalized score, for each characteristic. The service computes the percentile by comparing the author's results with the results from a sample population. For more information, see Personality characteristics output.
{: #example2}
The second example passes the JSON file profile.json
to the /v3/profile
method, again requesting a JSON response. The example requests consumption preferences and raw scores for a more detailed analysis of the input.
-
Download the sample file profile.json , which contains a collection of Twitter messages.
-
Issue the following command to send the file to the
/v3/profile
method. The example specifiesapplication/json
for theContent-Type
andAccept
headers; thecharset
parameter is not needed for JSON input. The example sets theconsumption_preferences
andraw_scores
query parameters totrue
.curl -X POST -u "apikey:{apikey}"{: apikey} \ --header "Content-Type: application/json" \ --header "Accept: application/json" \ --data-binary @{path_to_file}profile.json \ "{url}/v3/profile?version=2017-10-13&consumption_preferences=true&raw_scores=true"{: url}
{: pre}
The service returns a JSON profile that includes the metadata and characteristics returned with the previous example. For each characteristic, the service also includes a raw_score
, which represents the author's score for the characteristic based solely on the input text, without comparing the results to a sample population.
Because the input content includes timestamps, the service also reports behavioral characteristics. These are temporal characteristics that indicate the percentage
of the content items that were created on each day of the week and hour of the day. For more information, see Behavioral output.
The service also reports scores for its collection of consumption preferences. The scores indicate the author's likelihood to prefer different products, services, and activities based on the inferred characteristics. For more information, see Consumption preferences output.
{: #example3}
The third example is similar to the second: it passes the same JSON content and requests the same results. But this example specifies text/csv
for the Accept
header to request the response in comma-separated values (CSV) format. It uses the --output
option of the curl
command to direct the results to a file named profile.csv
. The example sets the csv_headers
query parameter to true
to request that column headers be returned with the output.
-
Issue the following command to send the JSON file to the
/v3/profile
method. TheContent-Type
header identifies the input content asapplication/json
, and theAccept
header requests CSV output,text/csv
.curl -X POST -u "apikey:{apikey}"{: apikey} \ --header "Content-Type: application/json" \ --header "Accept: text/csv" \ --data-binary @{path_to_file}profile.json \ --output profile.csv \ "{url}/v3/profile?version=2017-10-13&consumption_preferences=true&raw_scores=true&csv_headers=true"{: url}
{: pre}
For a detailed description of the CSV response and headers, see Understanding a CSV profile.
{: #gsns}
- Learn more about Requesting a profile and about Understanding a JSON profile and Understanding a CSV profile.
- Learn about the Big Five, Needs, and Values Personality models.
- Learn more about the API in the API reference {: new_window}
- Explore the Node.js sample application {: new_window} to learn more about application development with the service.