首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌云翻译: num_valid_languages_in_csv =1

谷歌云翻译: num_valid_languages_in_csv =1
EN

Stack Overflow用户
提问于 2020-01-08 01:37:01
回答 2查看 406关注 0票数 0

尝试将词汇表添加到Google Cloud Translate,但收到以下错误:

代码语言:javascript
复制
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文件(如下所示)是使用等价术语集的示例provided by Google创建的。

代码语言:javascript
复制
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

这是上传到谷歌云存储。然后,我尝试创建一个在线术语表,使at可用于云翻译应用编程接口,同样是通过用于等效术语集的code provided by Google

代码语言:javascript
复制
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的使用经验也不是很丰富,很容易遗漏一些东西。)

EN

回答 2

Stack Overflow用户

发布于 2020-01-08 02:07:07

由于某种原因,它要求CSV中的第一列为空。

代码语言:javascript
复制
,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

不知道为什么,但它现在起作用了。

票数 2
EN

Stack Overflow用户

发布于 2021-04-11 18:20:24

Google Cloud Translate Advanced中有两种类型的词汇表。

第一个是Unidirectional Glossaries这只是一对简单的源语言和目标语言的TSV、CSV或TMX格式。列标题不是必需的。

CSV格式的示例数据

代码语言:javascript
复制
account,cuenta
directions,indicaciones

还有一个你目前正在使用的,他们把它命名为"Equivalent term sets"。此格式仅适用于CSV格式。如果要创建具有两种以上语言的词汇表,则可以使用此格式。在此类型的词汇表中,标题是必需的。

CSV格式的示例数据:

代码语言:javascript
复制
first language,Second language,pos,description
account,cuenta,noun,A user's account. Do not use as verb.

或者,当有3种语言时:

代码语言:javascript
复制
first language,Second language,third language,pos,description
word in first language,word in second language, word in third language,noun,some information

正如您所看到的,在这种类型的术语表中有两个额外的列:"pos“和"description".因此,如果您使用这种类型的术语表,则至少应该有4列(当只有一对语言时)。

还有,在你的情况下。您显然需要单向类型的术语表,而不是等价的术语集。

在上面的代码中,应该使用language_pair而不是language_codes_set。您可以看到sample REST request here (虽然Python示例代码中缺少它)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59633423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档