我正在尝试对一些文本进行分类并具有以下代码:
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
def classify_text(text):
"""Classifies content categories of the provided text."""
client = language.LanguageServiceClient()
if isinstance(text, six.binary_type):
text = text.decode('utf-8')
document = types.Document(
content=text.encode('utf-8'),
type=enums.Document.Type.PLAIN_TEXT)
categories = client.classify_text(document).categories
for category in categories:
print(u'=' * 20)
print(u'{:<16}: {}'.format('name', category.name))
print(u'{:<16}: {}'.format('confidence', category.confidence))
但是当我打电话时:classify_text('Hello')
,我得到:
AttributeError: 'LanguageServiceClient' object has no attribute 'classify_text'
我似乎在这里找不到关于这个错误的任何问题。有谁知道这里发生了什么?