Skip to content
Merged
Changes from 1 commit
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(unicode(json.dumps(result)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unicode doesn't exist on python 3, what you really want here is:

json.dump(result, f)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python 2.7's json.dump seems to use f.write and json.dump(result, f) still returns the following error:

TypeError: write() argument 1 must be unicode, not str


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