0

Google Cloud CLOUD NATURAL LANGUAGE API (entity_extraction) 为 begin_offset 返回 -1(在 nodejs 和 python 上)。我是否缺少任何参数

from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types

client = language.LanguageServiceClient()

text = u'Dr. James went to NYU yesterday'
document = types.Document(
    content=text,
    type=enums.Document.Type.PLAIN_TEXT)

results = client.analyze_entities(document=document).entities
print(results[0].mentions[0].text.begin_offset)
4

1 回答 1

1

传入一个 EncodingType。这是一个例子:https ://github.com/GoogleCloudPlatform/python-docs-samples/blob/c359be8e635806f4c4986e6c643c67bac5e857da/language/cloud-client/v1/snippets.py#L208

于 2018-09-28T05:27:43.160 回答