Entity Sentiment Analysis combines both entity analysis and sentiment analysis
and attempts to determine the sentiment
(positive or negative) expressed about entities within the text.
Entity sentiment is represented by numerical score and magnitude values and
is determined for each mention of an entity. Those scores are then aggregated
into an overall sentiment score and magnitude for an entity.
For information on
how to interpret the score
and magnitude
sentiment values included in the
analysis, see Interpreting sentiment analysis values.
The following examples show how to query the analyzeEntitySentiment
method.
For each document, you must submit a separate request.
Analyzing Entity Sentiment
Here is an example of analyzing entity sentiment provided as a string:
Protocol
To analyze entity sentiment in a document, make a POST
request to the
documents:analyzeEntitySentiment
REST method and provide
the appropriate request body as shown in the following example.
The example uses the gcloud auth application-default print-access-token
command to obtain an access token for a service account set up for the
project using the Google Cloud Platform gcloud CLI.
For instructions on installing the gcloud CLI,
setting up a project with a service account
see the Quickstart.
curl -X POST \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ -H "Content-Type: application/json; charset=utf-8" \ --data "{ 'document':{ 'type':'PLAIN_TEXT', 'content':'I love R&B music. Marvin Gaye is the best. \'What\'s Going On\' is one of my favorite songs. It was so sad when Marvin Gaye died.' }, 'encodingType':'UTF8' }" "https://language.googleapis.com/v1/documents:analyzeEntitySentiment"
gcloud
Refer to the analyze-entity-sentiment
command for complete details.
To perform entity sentiment analysis, use the gcloud CLI and
use the --content
flag to identify the content to analyze:
gcloud ml language analyze-entity-sentiment \ --content="I love R&B music. Marvin Gaye is the best. 'What's Going On' is one of my favorite songs. It was so sad when Marvin Gaye died."
Go
To learn how to install and use the client library for Natural Language, see Natural Language client libraries. For more information, see the Natural Language Go API reference documentation.
To authenticate to Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for Natural Language, see Natural Language client libraries. For more information, see the Natural Language Java API reference documentation.
To authenticate to Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for Natural Language, see Natural Language client libraries. For more information, see the Natural Language Node.js API reference documentation.
To authenticate to Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To learn how to install and use the client library for Natural Language, see Natural Language client libraries. For more information, see the Natural Language Python API reference documentation.
To authenticate to Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Natural Language reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Natural Language reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Natural Language reference documentation for Ruby.
Analyzing Entity Sentiment from Cloud Storage
Here is an example of analyzing entity sentiment stored in a text file on Cloud Storage:
Protocol
To analyze entity sentiment from a document stored in Cloud Storage,
make a POST
request to the
documents:analyzeEntitySentiment
REST method and provide
the appropriate request body with the path to the document
as shown in the following example.
curl -X POST \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ -H "Content-Type: application/json; charset=utf-8" \ --data "{ 'document':{ 'type':'PLAIN_TEXT', 'gcsContentUri':'gs://<bucket-name>/<object-name>' } }" "https://language.googleapis.com/v1/documents:analyzeEntitySentiment"
gcloud
Refer to the analyze-entity-sentiment
command for complete details.
To perform entity sentiment analysis, use the gcloud CLI and
use the --content
flag to identify the content to analyze:
gcloud ml language analyze-entity-sentiment \ --content-file=gs://<bucket-name>/<object-name>
Java
To learn how to install and use the client library for Natural Language, see Natural Language client libraries. For more information, see the Natural Language Java API reference documentation.
To authenticate to Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for Natural Language, see Natural Language client libraries. For more information, see the Natural Language Node.js API reference documentation.
To authenticate to Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To learn how to install and use the client library for Natural Language, see Natural Language client libraries. For more information, see the Natural Language Python API reference documentation.
To authenticate to Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Natural Language reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Natural Language reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Natural Language reference documentation for Ruby.