Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google api 谷歌云翻译API:创建词汇表错误_Google Api_Google Translate_Google Api Python Client_Glossary - Fatal编程技术网

Google api 谷歌云翻译API:创建词汇表错误

Google api 谷歌云翻译API:创建词汇表错误,google-api,google-translate,google-api-python-client,glossary,Google Api,Google Translate,Google Api Python Client,Glossary,我尝试使用术语表测试云翻译API。 因此,我创建了一个示例glossary file.csv并将其上传到云存储上。 但是,当我运行测试代码时,出现了一个错误。我的示例词汇表文件中似乎存在问题,但我找不到它 我附上了我的代码、错误消息和术语表文件的屏幕截图。 你能告诉我怎么修吗 我是否可以使用术语表,以便在翻译成另一种语言时使用原始语言 英译韩 我想去加利福尼亚나는 加利福尼亚에 방문하고 싶다. 示例代码 from google.cloud import translate_v3 as tran

我尝试使用术语表测试云翻译API。 因此,我创建了一个示例glossary file.csv并将其上传到云存储上。 但是,当我运行测试代码时,出现了一个错误。我的示例词汇表文件中似乎存在问题,但我找不到它

我附上了我的代码、错误消息和术语表文件的屏幕截图。 你能告诉我怎么修吗

我是否可以使用术语表,以便在翻译成另一种语言时使用原始语言

英译韩 我想去加利福尼亚나는 加利福尼亚에 방문하고 싶다.

示例代码

from google.cloud import translate_v3 as translate
import os

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="my_service_account_json_file_path"

def create_glossary(
    project_id="YOUR_PROJECT_ID",
    input_uri="YOUR_INPUT_URI",
    glossary_id="YOUR_GLOSSARY_ID",
):
    """
    Create a equivalent term sets glossary. Glossary can be words or
    short phrases (usually fewer than five words).
    https://cloud.google.com/translate/docs/advanced/glossary#format-glossary
    """
    client = translate.TranslationServiceClient()

    # Supported language codes: https://cloud.google.com/translate/docs/languages
    source_lang_code = "ko"
    target_lang_code = "en"
    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=[source_lang_code, target_lang_code]
    )

    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)
    # glossary is a custom dictionary Translation API uses
    # to translate the domain-specific terminology.
    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))


create_glossary("my_project_id", "file_path_on_my_cloud_storage_bucket", "test_glossary")
错误消息

Traceback (most recent call last):
  File "C:/Users/ME/py-test/translation_api_test.py", line 120, in <module>
    create_glossary("my_project_id", "file_path_on_my_cloud_storage_bucket", "test_glossary")
  File "C:/Users/ME/py-test/translation_api_test.py", line 44, in create_glossary
    result = operation.result(timeout=90)
  File "C:\Users\ME\py-test\venv\lib\site-packages\google\api_core\future\polling.py", line 127, in result
    raise self._exception
google.api_core.exceptions.GoogleAPICallError: None No glossary entries found in input files. Check your files are not empty. stats = {total_examples = 0, total_successful_examples = 0, total_errors = 3, total_ignored_errors = 3, total_source_text_bytes = 0, total_target_text_bytes = 0, total_text_bytes = 0, text_bytes_by_language_map = []}
词汇表文件


通过将术语表文件的编码更改为UTF-8,我解决了这个问题。
我还发现我可以使用术语表,以便在翻译成另一种语言时使用原始语言。

我通过将术语表文件的编码更改为UTF-8解决了我的问题。
我还发现我可以使用术语表,以便在翻译成另一种语言时使用原始语言。

它解决了我的问题。谢谢。@Drake您能告诉我如何以及在哪里将术语表文件的编码更改为UTF-8吗?@Spark它不在代码中,您需要检查CSV文件的编码,在上传之前,例如使用记事本++。我的是UTF-8-BOM。错误不同,它找不到de语言。它解决了我的问题。谢谢。@Drake您能告诉我如何以及在哪一行代码中将术语表文件的编码更改为UTF-8吗?@Spark它不在代码中,您需要检查您的CSV文件的编码,然后再上载它,例如使用记事本++。我的是UTF-8-BOM。错误不同,它找不到de语言。