Skip to content

Commit 2082e72

Browse files
Add AnalyzeEntitySentiment method to language v1. (googleapis#3968)
1 parent 138047b commit 2082e72

File tree

5 files changed

+156
-4
lines changed

5 files changed

+156
-4
lines changed

language/google/cloud/language_v1/gapic/language_service_client.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ def __init__(self,
9090
client library metrics. Ultimately serializes to a string
9191
(e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
9292
considered private.
93-
94-
Returns: LanguageServiceClient
9593
"""
9694
# Unless the calling application specifically requested
9795
# OAuth scopes, request everything.
@@ -139,6 +137,9 @@ def __init__(self,
139137
self._analyze_entities = api_callable.create_api_call(
140138
self.language_service_stub.AnalyzeEntities,
141139
settings=defaults['analyze_entities'])
140+
self._analyze_entity_sentiment = api_callable.create_api_call(
141+
self.language_service_stub.AnalyzeEntitySentiment,
142+
settings=defaults['analyze_entity_sentiment'])
142143
self._analyze_syntax = api_callable.create_api_call(
143144
self.language_service_stub.AnalyzeSyntax,
144145
settings=defaults['analyze_syntax'])
@@ -213,6 +214,42 @@ def analyze_entities(self, document, encoding_type=None, options=None):
213214
document=document, encoding_type=encoding_type)
214215
return self._analyze_entities(request, options)
215216

217+
def analyze_entity_sentiment(self,
218+
document,
219+
encoding_type=None,
220+
options=None):
221+
"""
222+
Finds entities, similar to ``AnalyzeEntities`` in the text and analyzes
223+
sentiment associated with each entity and its mentions.
224+
225+
Example:
226+
>>> from google.cloud import language_v1
227+
>>>
228+
>>> client = language_v1.LanguageServiceClient()
229+
>>>
230+
>>> document = {}
231+
>>>
232+
>>> response = client.analyze_entity_sentiment(document)
233+
234+
Args:
235+
document (Union[dict, ~google.cloud.language_v1.types.Document]): Input document.
236+
If a dict is provided, it must be of the same form as the protobuf
237+
message :class:`~google.cloud.language_v1.types.Document`
238+
encoding_type (~google.cloud.language_v1.types.EncodingType): The encoding type used by the API to calculate offsets.
239+
options (~google.gax.CallOptions): Overrides the default
240+
settings for this call, e.g, timeout, retries etc.
241+
242+
Returns:
243+
A :class:`~google.cloud.language_v1.types.AnalyzeEntitySentimentResponse` instance.
244+
245+
Raises:
246+
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
247+
:exc:`ValueError` if the parameters are invalid.
248+
"""
249+
request = language_service_pb2.AnalyzeEntitySentimentRequest(
250+
document=document, encoding_type=encoding_type)
251+
return self._analyze_entity_sentiment(request, options)
252+
216253
def analyze_syntax(self, document, encoding_type=None, options=None):
217254
"""
218255
Analyzes the syntax of the text and provides sentence boundaries and

language/google/cloud/language_v1/gapic/language_service_client_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
"retry_codes_name": "idempotent",
2828
"retry_params_name": "default"
2929
},
30+
"AnalyzeEntitySentiment": {
31+
"timeout_millis": 30000,
32+
"retry_codes_name": "idempotent",
33+
"retry_params_name": "default"
34+
},
3035
"AnalyzeSyntax": {
3136
"timeout_millis": 30000,
3237
"retry_codes_name": "idempotent",

language/google/cloud/language_v1/proto/language_service_pb2.py

Lines changed: 61 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

language/google/cloud/language_v1/proto/language_service_pb2_grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
import grpc
33

4-
import google.cloud.language_v1.proto.language_service_pb2 as google_dot_cloud_dot_language__v1_dot_proto_dot_language__service__pb2
4+
from google.cloud.language_v1.proto import language_service_pb2 as google_dot_cloud_dot_language__v1_dot_proto_dot_language__service__pb2
55

66

77
class LanguageServiceStub(object):

0 commit comments

Comments
 (0)