Skip to content

Commit f81cbcc

Browse files
Add analyze_entity_sentiment (googleapis#3999)
1 parent a042a91 commit f81cbcc

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

docs/language/usage.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ The Google Natural Language API has three supported methods
5555

5656
- `analyzeEntities`_
5757
- `analyzeSentiment`_
58+
- `analyzeEntitySentiment`_
5859
- `annotateText`_
5960

6061
and each method uses a :class:`~.language_v1.types.Document` for representing
@@ -113,6 +114,7 @@ to content stored in `Google Cloud Storage`_.
113114
114115
.. _analyzeEntities: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeEntities
115116
.. _analyzeSentiment: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeSentiment
117+
.. _analyzeEntitySentiment: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeEntitySentiment
116118
.. _annotateText: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/annotateText
117119
.. _Google Cloud Storage: https://cloud.google.com/storage/
118120

@@ -197,6 +199,45 @@ analyzes the sentiment of the provided text. This method returns a
197199
want ``UTF32``.
198200

199201

202+
************************
203+
Analyze Entity Sentiment
204+
************************
205+
206+
The :meth:`~.language_v1.LanguageServiceClient.analyze_entity_sentiment`
207+
method is effectively the amalgamation of
208+
:meth:`~.language_v1.LanguageServiceClient.analyze_entities` and
209+
:meth:`~.language_v1.LanguageServiceClient.analyze_sentiment`.
210+
This method returns a
211+
:class:`~.language_v1.types.AnalyzeEntitySentimentResponse`.
212+
213+
.. code-block:: python
214+
215+
>>> document = language.types.Document(
216+
... content='Mona said that jogging is very fun.',
217+
... type='PLAIN_TEXT',
218+
... )
219+
>>> response = client.analyze_sentiment(
220+
... document=document,
221+
... encoding_type='UTF32',
222+
... )
223+
>>> entities = response.entities
224+
>>> entities[0].name
225+
'Mona'
226+
>>> entities[1].name
227+
'jogging'
228+
>>> entities[1].sentiment.magnitude
229+
0.8
230+
>>> entities[1].sentiment.score
231+
0.8
232+
233+
.. note::
234+
235+
It is recommended to send an ``encoding_type`` argument to Natural
236+
Language methods, so they provide useful offsets for the data they return.
237+
While the correct value varies by environment, in Python you *usually*
238+
want ``UTF32``.
239+
240+
200241
*************
201242
Annotate Text
202243
*************

0 commit comments

Comments
 (0)