Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions language/google/cloud/language_v1/gapic/language_service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ def __init__(self,
client library metrics. Ultimately serializes to a string
(e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
considered private.

Returns: LanguageServiceClient
"""
# Unless the calling application specifically requested
# OAuth scopes, request everything.
Expand Down Expand Up @@ -139,6 +137,9 @@ def __init__(self,
self._analyze_entities = api_callable.create_api_call(
self.language_service_stub.AnalyzeEntities,
settings=defaults['analyze_entities'])
self._analyze_entity_sentiment = api_callable.create_api_call(
self.language_service_stub.AnalyzeEntitySentiment,
settings=defaults['analyze_entity_sentiment'])
self._analyze_syntax = api_callable.create_api_call(
self.language_service_stub.AnalyzeSyntax,
settings=defaults['analyze_syntax'])
Expand Down Expand Up @@ -213,6 +214,42 @@ def analyze_entities(self, document, encoding_type=None, options=None):
document=document, encoding_type=encoding_type)
return self._analyze_entities(request, options)

def analyze_entity_sentiment(self,
document,
encoding_type=None,
options=None):
"""
Finds entities, similar to ``AnalyzeEntities`` in the text and analyzes
sentiment associated with each entity and its mentions.

Example:
>>> from google.cloud import language_v1
>>>
>>> client = language_v1.LanguageServiceClient()
>>>
>>> document = {}
>>>
>>> response = client.analyze_entity_sentiment(document)

Args:
document (Union[dict, ~google.cloud.language_v1.types.Document]): Input document.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.language_v1.types.Document`
encoding_type (~google.cloud.language_v1.types.EncodingType): The encoding type used by the API to calculate offsets.
options (~google.gax.CallOptions): Overrides the default
settings for this call, e.g, timeout, retries etc.

Returns:
A :class:`~google.cloud.language_v1.types.AnalyzeEntitySentimentResponse` instance.

Raises:
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
:exc:`ValueError` if the parameters are invalid.
"""
request = language_service_pb2.AnalyzeEntitySentimentRequest(
document=document, encoding_type=encoding_type)
return self._analyze_entity_sentiment(request, options)

def analyze_syntax(self, document, encoding_type=None, options=None):
"""
Analyzes the syntax of the text and provides sentence boundaries and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"retry_codes_name": "idempotent",
"retry_params_name": "default"
},
"AnalyzeEntitySentiment": {
"timeout_millis": 30000,
"retry_codes_name": "idempotent",
"retry_params_name": "default"
},
"AnalyzeSyntax": {
"timeout_millis": 30000,
"retry_codes_name": "idempotent",
Expand Down
62 changes: 61 additions & 1 deletion language/google/cloud/language_v1/proto/language_service_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
import grpc

import google.cloud.language_v1.proto.language_service_pb2 as google_dot_cloud_dot_language__v1_dot_proto_dot_language__service__pb2
from google.cloud.language_v1.proto import language_service_pb2 as google_dot_cloud_dot_language__v1_dot_proto_dot_language__service__pb2


class LanguageServiceStub(object):
Expand Down
Loading