Skip to content

Commit e89051f

Browse files
Language GAPIC update (googleapis#3699)
1 parent 78e51d9 commit e89051f

File tree

6 files changed

+46
-138
lines changed

6 files changed

+46
-138
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,25 +184,22 @@ def analyze_sentiment(self, document, encoding_type=None, options=None):
184184
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
185185
:exc:`ValueError` if the parameters are invalid.
186186
"""
187-
# Create the request object.
188187
request = language_service_pb2.AnalyzeSentimentRequest(
189188
document=document, encoding_type=encoding_type)
190189
return self._analyze_sentiment(request, options)
191190

192-
def analyze_entities(self, document, encoding_type, options=None):
191+
def analyze_entities(self, document, encoding_type=None, options=None):
193192
"""
194193
Finds named entities (currently proper names and common nouns) in the text
195194
along with entity types, salience, mentions for each entity, and
196195
other properties.
197196
198197
Example:
199198
>>> from google.cloud.gapic.language.v1 import language_service_client
200-
>>> from google.cloud.gapic.language.v1 import enums
201199
>>> from google.cloud.proto.language.v1 import language_service_pb2
202200
>>> client = language_service_client.LanguageServiceClient()
203201
>>> document = language_service_pb2.Document()
204-
>>> encoding_type = enums.EncodingType.NONE
205-
>>> response = client.analyze_entities(document, encoding_type)
202+
>>> response = client.analyze_entities(document)
206203
207204
Args:
208205
document (:class:`google.cloud.proto.language.v1.language_service_pb2.Document`): Input document.
@@ -217,25 +214,22 @@ def analyze_entities(self, document, encoding_type, options=None):
217214
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
218215
:exc:`ValueError` if the parameters are invalid.
219216
"""
220-
# Create the request object.
221217
request = language_service_pb2.AnalyzeEntitiesRequest(
222218
document=document, encoding_type=encoding_type)
223219
return self._analyze_entities(request, options)
224220

225-
def analyze_syntax(self, document, encoding_type, options=None):
221+
def analyze_syntax(self, document, encoding_type=None, options=None):
226222
"""
227223
Analyzes the syntax of the text and provides sentence boundaries and
228224
tokenization along with part of speech tags, dependency trees, and other
229225
properties.
230226
231227
Example:
232228
>>> from google.cloud.gapic.language.v1 import language_service_client
233-
>>> from google.cloud.gapic.language.v1 import enums
234229
>>> from google.cloud.proto.language.v1 import language_service_pb2
235230
>>> client = language_service_client.LanguageServiceClient()
236231
>>> document = language_service_pb2.Document()
237-
>>> encoding_type = enums.EncodingType.NONE
238-
>>> response = client.analyze_syntax(document, encoding_type)
232+
>>> response = client.analyze_syntax(document)
239233
240234
Args:
241235
document (:class:`google.cloud.proto.language.v1.language_service_pb2.Document`): Input document.
@@ -250,25 +244,26 @@ def analyze_syntax(self, document, encoding_type, options=None):
250244
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
251245
:exc:`ValueError` if the parameters are invalid.
252246
"""
253-
# Create the request object.
254247
request = language_service_pb2.AnalyzeSyntaxRequest(
255248
document=document, encoding_type=encoding_type)
256249
return self._analyze_syntax(request, options)
257250

258-
def annotate_text(self, document, features, encoding_type, options=None):
251+
def annotate_text(self,
252+
document,
253+
features,
254+
encoding_type=None,
255+
options=None):
259256
"""
260257
A convenience method that provides all the features that analyzeSentiment,
261258
analyzeEntities, and analyzeSyntax provide in one call.
262259
263260
Example:
264261
>>> from google.cloud.gapic.language.v1 import language_service_client
265-
>>> from google.cloud.gapic.language.v1 import enums
266262
>>> from google.cloud.proto.language.v1 import language_service_pb2
267263
>>> client = language_service_client.LanguageServiceClient()
268264
>>> document = language_service_pb2.Document()
269265
>>> features = language_service_pb2.AnnotateTextRequest.Features()
270-
>>> encoding_type = enums.EncodingType.NONE
271-
>>> response = client.annotate_text(document, features, encoding_type)
266+
>>> response = client.annotate_text(document, features)
272267
273268
Args:
274269
document (:class:`google.cloud.proto.language.v1.language_service_pb2.Document`): Input document.
@@ -284,7 +279,6 @@ def annotate_text(self, document, features, encoding_type, options=None):
284279
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
285280
:exc:`ValueError` if the parameters are invalid.
286281
"""
287-
# Create the request object.
288282
request = language_service_pb2.AnnotateTextRequest(
289283
document=document, features=features, encoding_type=encoding_type)
290284
return self._annotate_text(request, options)

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,22 @@ def analyze_sentiment(self, document, encoding_type=None, options=None):
188188
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
189189
:exc:`ValueError` if the parameters are invalid.
190190
"""
191-
# Create the request object.
192191
request = language_service_pb2.AnalyzeSentimentRequest(
193192
document=document, encoding_type=encoding_type)
194193
return self._analyze_sentiment(request, options)
195194

196-
def analyze_entities(self, document, encoding_type, options=None):
195+
def analyze_entities(self, document, encoding_type=None, options=None):
197196
"""
198197
Finds named entities (currently proper names and common nouns) in the text
199198
along with entity types, salience, mentions for each entity, and
200199
other properties.
201200
202201
Example:
203202
>>> from google.cloud.gapic.language.v1beta2 import language_service_client
204-
>>> from google.cloud.gapic.language.v1beta2 import enums
205203
>>> from google.cloud.proto.language.v1beta2 import language_service_pb2
206204
>>> client = language_service_client.LanguageServiceClient()
207205
>>> document = language_service_pb2.Document()
208-
>>> encoding_type = enums.EncodingType.NONE
209-
>>> response = client.analyze_entities(document, encoding_type)
206+
>>> response = client.analyze_entities(document)
210207
211208
Args:
212209
document (:class:`google.cloud.proto.language.v1beta2.language_service_pb2.Document`): Input document.
@@ -221,24 +218,24 @@ def analyze_entities(self, document, encoding_type, options=None):
221218
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
222219
:exc:`ValueError` if the parameters are invalid.
223220
"""
224-
# Create the request object.
225221
request = language_service_pb2.AnalyzeEntitiesRequest(
226222
document=document, encoding_type=encoding_type)
227223
return self._analyze_entities(request, options)
228224

229-
def analyze_entity_sentiment(self, document, encoding_type, options=None):
225+
def analyze_entity_sentiment(self,
226+
document,
227+
encoding_type=None,
228+
options=None):
230229
"""
231230
Finds entities, similar to ``AnalyzeEntities`` in the text and analyzes
232231
sentiment associated with each entity and its mentions.
233232
234233
Example:
235234
>>> from google.cloud.gapic.language.v1beta2 import language_service_client
236-
>>> from google.cloud.gapic.language.v1beta2 import enums
237235
>>> from google.cloud.proto.language.v1beta2 import language_service_pb2
238236
>>> client = language_service_client.LanguageServiceClient()
239237
>>> document = language_service_pb2.Document()
240-
>>> encoding_type = enums.EncodingType.NONE
241-
>>> response = client.analyze_entity_sentiment(document, encoding_type)
238+
>>> response = client.analyze_entity_sentiment(document)
242239
243240
Args:
244241
document (:class:`google.cloud.proto.language.v1beta2.language_service_pb2.Document`): Input document.
@@ -253,25 +250,22 @@ def analyze_entity_sentiment(self, document, encoding_type, options=None):
253250
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
254251
:exc:`ValueError` if the parameters are invalid.
255252
"""
256-
# Create the request object.
257253
request = language_service_pb2.AnalyzeEntitySentimentRequest(
258254
document=document, encoding_type=encoding_type)
259255
return self._analyze_entity_sentiment(request, options)
260256

261-
def analyze_syntax(self, document, encoding_type, options=None):
257+
def analyze_syntax(self, document, encoding_type=None, options=None):
262258
"""
263259
Analyzes the syntax of the text and provides sentence boundaries and
264260
tokenization along with part of speech tags, dependency trees, and other
265261
properties.
266262
267263
Example:
268264
>>> from google.cloud.gapic.language.v1beta2 import language_service_client
269-
>>> from google.cloud.gapic.language.v1beta2 import enums
270265
>>> from google.cloud.proto.language.v1beta2 import language_service_pb2
271266
>>> client = language_service_client.LanguageServiceClient()
272267
>>> document = language_service_pb2.Document()
273-
>>> encoding_type = enums.EncodingType.NONE
274-
>>> response = client.analyze_syntax(document, encoding_type)
268+
>>> response = client.analyze_syntax(document)
275269
276270
Args:
277271
document (:class:`google.cloud.proto.language.v1beta2.language_service_pb2.Document`): Input document.
@@ -286,25 +280,26 @@ def analyze_syntax(self, document, encoding_type, options=None):
286280
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
287281
:exc:`ValueError` if the parameters are invalid.
288282
"""
289-
# Create the request object.
290283
request = language_service_pb2.AnalyzeSyntaxRequest(
291284
document=document, encoding_type=encoding_type)
292285
return self._analyze_syntax(request, options)
293286

294-
def annotate_text(self, document, features, encoding_type, options=None):
287+
def annotate_text(self,
288+
document,
289+
features,
290+
encoding_type=None,
291+
options=None):
295292
"""
296293
A convenience method that provides all syntax, sentiment, and entity
297294
features in one call.
298295
299296
Example:
300297
>>> from google.cloud.gapic.language.v1beta2 import language_service_client
301-
>>> from google.cloud.gapic.language.v1beta2 import enums
302298
>>> from google.cloud.proto.language.v1beta2 import language_service_pb2
303299
>>> client = language_service_client.LanguageServiceClient()
304300
>>> document = language_service_pb2.Document()
305301
>>> features = language_service_pb2.AnnotateTextRequest.Features()
306-
>>> encoding_type = enums.EncodingType.NONE
307-
>>> response = client.annotate_text(document, features, encoding_type)
302+
>>> response = client.annotate_text(document, features)
308303
309304
Args:
310305
document (:class:`google.cloud.proto.language.v1beta2.language_service_pb2.Document`): Input document.
@@ -320,7 +315,6 @@ def annotate_text(self, document, features, encoding_type, options=None):
320315
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
321316
:exc:`ValueError` if the parameters are invalid.
322317
"""
323-
# Create the request object.
324318
request = language_service_pb2.AnnotateTextRequest(
325319
document=document, features=features, encoding_type=encoding_type)
326320
return self._annotate_text(request, options)

language/tests/gapic/v1/test_language_service_client_v1.py renamed to language/tests/gapic/test_language_service_client_v1.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from google.gax import errors
2020

21-
from google.cloud.gapic.language.v1 import enums
2221
from google.cloud.gapic.language.v1 import language_service_client
2322
from google.cloud.proto.language.v1 import language_service_pb2
2423

@@ -86,15 +85,14 @@ def test_analyze_entities(self, mock_create_stub):
8685

8786
# Mock request
8887
document = language_service_pb2.Document()
89-
encoding_type = enums.EncodingType.NONE
9088

9189
# Mock response
9290
language = 'language-1613589672'
9391
expected_response = language_service_pb2.AnalyzeEntitiesResponse(
9492
language=language)
9593
grpc_stub.AnalyzeEntities.return_value = expected_response
9694

97-
response = client.analyze_entities(document, encoding_type)
95+
response = client.analyze_entities(document)
9896
self.assertEqual(expected_response, response)
9997

10098
grpc_stub.AnalyzeEntities.assert_called_once()
@@ -105,7 +103,7 @@ def test_analyze_entities(self, mock_create_stub):
105103
actual_request = args[0]
106104

107105
expected_request = language_service_pb2.AnalyzeEntitiesRequest(
108-
document=document, encoding_type=encoding_type)
106+
document=document)
109107
self.assertEqual(expected_request, actual_request)
110108

111109
@mock.patch('google.gax.config.API_ERRORS', (CustomException, ))
@@ -119,13 +117,11 @@ def test_analyze_entities_exception(self, mock_create_stub):
119117

120118
# Mock request
121119
document = language_service_pb2.Document()
122-
encoding_type = enums.EncodingType.NONE
123120

124121
# Mock exception response
125122
grpc_stub.AnalyzeEntities.side_effect = CustomException()
126123

127-
self.assertRaises(errors.GaxError, client.analyze_entities, document,
128-
encoding_type)
124+
self.assertRaises(errors.GaxError, client.analyze_entities, document)
129125

130126
@mock.patch('google.gax.config.create_stub', spec=True)
131127
def test_analyze_syntax(self, mock_create_stub):
@@ -137,15 +133,14 @@ def test_analyze_syntax(self, mock_create_stub):
137133

138134
# Mock request
139135
document = language_service_pb2.Document()
140-
encoding_type = enums.EncodingType.NONE
141136

142137
# Mock response
143138
language = 'language-1613589672'
144139
expected_response = language_service_pb2.AnalyzeSyntaxResponse(
145140
language=language)
146141
grpc_stub.AnalyzeSyntax.return_value = expected_response
147142

148-
response = client.analyze_syntax(document, encoding_type)
143+
response = client.analyze_syntax(document)
149144
self.assertEqual(expected_response, response)
150145

151146
grpc_stub.AnalyzeSyntax.assert_called_once()
@@ -156,7 +151,7 @@ def test_analyze_syntax(self, mock_create_stub):
156151
actual_request = args[0]
157152

158153
expected_request = language_service_pb2.AnalyzeSyntaxRequest(
159-
document=document, encoding_type=encoding_type)
154+
document=document)
160155
self.assertEqual(expected_request, actual_request)
161156

162157
@mock.patch('google.gax.config.API_ERRORS', (CustomException, ))
@@ -170,13 +165,11 @@ def test_analyze_syntax_exception(self, mock_create_stub):
170165

171166
# Mock request
172167
document = language_service_pb2.Document()
173-
encoding_type = enums.EncodingType.NONE
174168

175169
# Mock exception response
176170
grpc_stub.AnalyzeSyntax.side_effect = CustomException()
177171

178-
self.assertRaises(errors.GaxError, client.analyze_syntax, document,
179-
encoding_type)
172+
self.assertRaises(errors.GaxError, client.analyze_syntax, document)
180173

181174
@mock.patch('google.gax.config.create_stub', spec=True)
182175
def test_annotate_text(self, mock_create_stub):
@@ -189,15 +182,14 @@ def test_annotate_text(self, mock_create_stub):
189182
# Mock request
190183
document = language_service_pb2.Document()
191184
features = language_service_pb2.AnnotateTextRequest.Features()
192-
encoding_type = enums.EncodingType.NONE
193185

194186
# Mock response
195187
language = 'language-1613589672'
196188
expected_response = language_service_pb2.AnnotateTextResponse(
197189
language=language)
198190
grpc_stub.AnnotateText.return_value = expected_response
199191

200-
response = client.annotate_text(document, features, encoding_type)
192+
response = client.annotate_text(document, features)
201193
self.assertEqual(expected_response, response)
202194

203195
grpc_stub.AnnotateText.assert_called_once()
@@ -208,7 +200,7 @@ def test_annotate_text(self, mock_create_stub):
208200
actual_request = args[0]
209201

210202
expected_request = language_service_pb2.AnnotateTextRequest(
211-
document=document, features=features, encoding_type=encoding_type)
203+
document=document, features=features)
212204
self.assertEqual(expected_request, actual_request)
213205

214206
@mock.patch('google.gax.config.API_ERRORS', (CustomException, ))
@@ -223,10 +215,9 @@ def test_annotate_text_exception(self, mock_create_stub):
223215
# Mock request
224216
document = language_service_pb2.Document()
225217
features = language_service_pb2.AnnotateTextRequest.Features()
226-
encoding_type = enums.EncodingType.NONE
227218

228219
# Mock exception response
229220
grpc_stub.AnnotateText.side_effect = CustomException()
230221

231222
self.assertRaises(errors.GaxError, client.annotate_text, document,
232-
features, encoding_type)
223+
features)

0 commit comments

Comments
 (0)