Skip to content
Merged
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
13 changes: 5 additions & 8 deletions language/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