尝试向 Google Cloud Translate 添加词汇表,但收到以下错误:
Traceback (most recent call last):
File "Python_SetGlossary.py", line 36, in <module>
result = operation.result(timeout=90)
File "C:\Programming Installs\Python\lib\site-packages\google\api_core\future\polling.py", line 127, in result
raise self._exception
google.api_core.exceptions.GoogleAPICallError: None Failed to parse content of input file. Error: Not enough valid languages in CSV file. Must have terms for at least two different languages. num_valid_languages_in_csv = 1
CSV 文件(如下)是使用Google为等效术语集提供的示例创建的。
en,fr,pos
Canadian Meteorological Service of Environment Canada,Service météorologique d'Environnement Canada,noun
Jacques Cartier Strait,détroit de Jacques-Cartier,noun
the St. Lawrence Global Observatory,l'Observatoire global du Saint-Laurent,noun
St. Lawrence Global Observatory,Observatoire global du Saint-Laurent,noun
这已上传到 Google Cloud Storage。然后,我尝试再次通过Google为等效术语集提供的代码,将 at 提供给 Cloud Translation API,从而创建一个在线词汇表。
from google.cloud import translate_v3 as translate
# def sample_create_glossary(project_id, input_uri, glossary_id):
"""Create Glossary"""
client = translate.TranslationServiceClient()
# TODO(developer): Uncomment and set the following variables
project_id = 'testtranslate'
glossary_id = 'glossary-en-fr-bidirectional'
input_uri = 'gs://bidirectional-en-fr/bidirectional-glossary.csv'
location = 'us-central1' # The location of the glossary
name = client.glossary_path(
project_id,
location,
glossary_id)
language_codes_set = translate.types.Glossary.LanguageCodesSet(
language_codes=['en', 'fr'])
gcs_source = translate.types.GcsSource(
input_uri=input_uri)
input_config = translate.types.GlossaryInputConfig(
gcs_source=gcs_source)
glossary = translate.types.Glossary(
name=name,
language_codes_set=language_codes_set,
input_config=input_config)
parent = client.location_path(project_id, location)
operation = client.create_glossary(parent=parent, glossary=glossary)
result = operation.result(timeout=90)
print('Created: {}'.format(result.name))
print('Input Uri: {}'.format(result.input_config.gcs_source.input_uri))
谁能帮我弄清楚发生了什么/我做错了什么?(或者谷歌做错了什么。他们的一些文档肯定是可疑的。但我对 Python 也不是特别有经验,很容易遗漏一些东西。)