Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
update to use v1 client [(#1216)](GoogleCloudPlatform/python-docs-sam…
Browse files Browse the repository at this point in the history
…ples#1216)

* update to use v1 client

* set ensure_ascii=False
  • Loading branch information
dizcology authored and busunkim96 committed Sep 29, 2020
1 parent e6a5196 commit 03897e3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions samples/snippets/classify_text/classify_text_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
import json
import os

from google.cloud import language_v1beta2
from google.cloud.language_v1beta2 import enums
from google.cloud.language_v1beta2 import types

from google.cloud import language
import numpy
import six
# [END classify_text_tutorial_import]
Expand All @@ -40,11 +37,11 @@
def classify(text, verbose=True):
"""Classify the input text into categories. """

language_client = language_v1beta2.LanguageServiceClient()
language_client = language.LanguageServiceClient()

document = types.Document(
document = language.types.Document(
content=text,
type=enums.Document.Type.PLAIN_TEXT)
type=language.enums.Document.Type.PLAIN_TEXT)
response = language_client.classify_text(document)
categories = response.categories

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

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

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

0 comments on commit 03897e3

Please sign in to comment.