Skip to content

Commit 981ddd9

Browse files
dizcologyJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
update to use v1 client [(#1216)](GoogleCloudPlatform/python-docs-samples#1216)
* update to use v1 client * set ensure_ascii=False
1 parent 6edb9e0 commit 981ddd9

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

samples/snippets/classify_text/classify_text_tutorial.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
import json
2828
import os
2929

30-
from google.cloud import language_v1beta2
31-
from google.cloud.language_v1beta2 import enums
32-
from google.cloud.language_v1beta2 import types
33-
30+
from google.cloud import language
3431
import numpy
3532
import six
3633
# [END classify_text_tutorial_import]
@@ -40,11 +37,11 @@
4037
def classify(text, verbose=True):
4138
"""Classify the input text into categories. """
4239

43-
language_client = language_v1beta2.LanguageServiceClient()
40+
language_client = language.LanguageServiceClient()
4441

45-
document = types.Document(
42+
document = language.types.Document(
4643
content=text,
47-
type=enums.Document.Type.PLAIN_TEXT)
44+
type=language.enums.Document.Type.PLAIN_TEXT)
4845
response = language_client.classify_text(document)
4946
categories = response.categories
5047

@@ -90,7 +87,7 @@ def index(path, index_file):
9087
print('Failed to process {}'.format(file_path))
9188

9289
with io.open(index_file, 'w', encoding='utf-8') as f:
93-
f.write(json.dumps(result))
90+
f.write(json.dumps(result, ensure_ascii=False))
9491

9592
print('Texts indexed in file: {}'.format(index_file))
9693
return result

0 commit comments

Comments
 (0)