airflow.providers.google.cloud.operators.translate

此模組包含 Google Translate operators。

模組內容

類別

CloudTranslateTextOperator

翻譯字串或字串清單。

TranslateTextOperator

翻譯適量文字內容,若要翻譯大量文字,請使用 TranslateTextBatchOperator。

TranslateTextBatchOperator

根據提供的輸入,翻譯大量文字內容。

TranslateCreateDatasetOperator

建立 Google Cloud Translate 資料集。

TranslateDatasetsListOperator

取得專案中原生 Google Cloud Translation 資料集清單。

TranslateImportDataOperator

將資料匯入翻譯資料集。

TranslateDeleteDatasetOperator

刪除翻譯資料集及其所有內容。

TranslateCreateModelOperator

建立 Google Cloud Translate 模型。

TranslateModelsListOperator

取得專案中原生 Google Cloud Translation 模型清單。

TranslateDeleteModelOperator

刪除翻譯模型及其所有內容。

TranslateDocumentOperator

翻譯提供的文件。

TranslateDocumentBatchOperator

透過輸入和輸出設定翻譯提供的文件。

class airflow.providers.google.cloud.operators.translate.CloudTranslateTextOperator(*, values, target_language, format_, source_language, model, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[原始碼]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

翻譯字串或字串清單。

另請參閱

如需更多關於如何使用此 operator 的資訊,請參閱指南: CloudTranslateTextOperator

請參閱 https://cloud.google.com/translate/docs/translating-text

Execute 方法會傳回 str 或清單。

這是每個查詢值的字典清單。每個字典通常包含三個鍵(雖然並非所有情況下都會出現所有鍵)

  • detectedSourceLanguage:偵測到的文字語言(以 ISO 639-1 語言代碼表示)。

  • translatedText:文字翻譯成目標語言的結果。

  • input:對應的輸入值。

  • model:用於翻譯文字的模型。

如果僅傳遞單一值,則只會將單一字典設定為 XCom 傳回值。

參數
  • values ( list[str] | str) – 要翻譯的字串或字串清單。

  • target_language ( str) – 要將結果翻譯成的語言。API 要求此參數。

  • format – (選用) texthtml 其中之一,指定輸入文字是純文字還是 HTML。

  • source_language ( str | None) – (選用) 要翻譯的文字語言。

  • model ( str) – (選用) 用於翻譯文字的模型,例如 'base''nmt'

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('values', 'target_language', 'format_', 'source_language', 'model', 'gcp_conn_id',...[原始碼]
execute(context)[原始碼]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateTextOperator(*, contents, source_language_code=None, target_language_code, mime_type=None, location=None, project_id=PROVIDE_PROJECT_ID, model=None, transliteration_config=None, glossary_config=None, labels=None, timeout=DEFAULT, retry=DEFAULT, metadata=(), gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[原始碼]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

翻譯適量文字內容,若要翻譯大量文字,請使用 TranslateTextBatchOperator。

包裝 Google Cloud Translate Text (進階) 功能。請參閱 https://cloud.google.com/translate/docs/advanced/translating-text-v3

如需更多關於如何使用此 operator 的資訊,請參閱指南

TranslateTextOperator.

參數
  • project_id ( str) – 選用。服務所屬的 Google Cloud 專案 ID。

  • location ( str | None) – 選用。服務所屬的 Google Cloud 位置 ID。如果未指定,則使用 'global'。使用 AutoML 模型或自訂詞彙表的要求需要非全域位置。

  • contents ( collections.abc.Sequence[str]) – 必填。要翻譯的內容字串序列。建議限制為 1024 個項目,總共 30,000 個字碼點。

  • mime_type ( str | None) – 選用。來源文字的格式。如果留空,MIME 類型預設為「text/html」。

  • source_language_code ( str | None) – 選用。如果已知,則為輸入文字的 ISO-639 語言代碼。如果未指定,則嘗試自動辨識。

  • target_language_code ( str) – 必填。用於翻譯輸入文字的 ISO-639 語言代碼。

  • model ( str | None) –

    選用。此翻譯要求的 model 類型。如果未提供,將使用預設 Google 模型 (NMT)。格式取決於模型類型

    • AutoML Translation 模型: projects/{project-number-or-id}/locations/{location-id}/models/{model-id}

    • 一般 (內建) 模型: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt

    • Translation LLM 模型: projects/{project-number-or-id}/locations/{location-id}/models/general/translation-llm

    對於全域 (非區域) 請求,請使用 'global' location-id

  • glossary_config ( google.cloud.translate_v3.types.TranslateTextGlossaryConfig | None) – 選用。要套用的詞彙表。

  • transliteration_config (google.cloud.translate_v3.types.TransliterationConfig | None) – 選用。要套用的音譯。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault | None) – 指示應重試哪些錯誤(如果有的話)。

  • timeout ( float | google.api_core.gapic_v1.method._MethodDefault) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('contents', 'target_language_code', 'mime_type', 'source_language_code', 'model',...[原始碼]
execute(context)[原始碼]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateTextBatchOperator(*, project_id=PROVIDE_PROJECT_ID, location, target_language_codes, source_language_code, input_configs, output_config, models=None, glossaries=None, labels=None, metadata=(), timeout=DEFAULT, retry=DEFAULT, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[原始碼]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

根據提供的輸入,翻譯大量文字內容。

包裝 Google Cloud Translate Text (進階) 功能。請參閱 https://cloud.google.com/translate/docs/advanced/batch-translation

如需更多關於如何使用此 operator 的資訊,請參閱指南: TranslateTextBatchOperator

參數
  • project_id ( str) – 選用。服務所屬的 Google Cloud 專案 ID。如果未指定,將使用 Hook project_id。

  • location ( str) – 必填。服務所屬的 Google Cloud 位置 ID (非全域)。

  • source_language_code ( str) – 必填。來源語言代碼。

  • target_language_codes ( collections.abc.MutableSequence[str]) – 必填。此處最多允許 10 個語言代碼。

  • input_configs ( collections.abc.MutableSequence[google.cloud.translate_v3.types.InputConfig | dict]) – 必填。輸入設定。比對的檔案總數應 <=100。內容總大小應 <= 100M Unicode 字碼點。檔案必須使用 UTF-8 編碼。

  • models ( str | None) –

    選用。用於翻譯的模型。Map 的鍵是目標語言代碼。Map 的值是模型名稱。值可以是內建一般模型,也可以是 AutoML Translation 模型。值格式取決於模型類型

    • AutoML Translation 模型: projects/{project-number-or-id}/locations/{location-id}/models/{model-id}

    • 一般 (內建) 模型: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt

    如果 Map 為空,或未針對語言配對請求特定模型,則使用預設 Google 模型 (NMT)。

  • output_config ( google.cloud.translate_v3.types.OutputConfig | dict) – 必填。輸出設定。

  • glossaries ( collections.abc.MutableMapping[str, google.cloud.translate_v3.types.TranslateTextGlossaryConfig] | None) – 選用。要套用於翻譯的詞彙表。它以目標語言代碼作為鍵。

  • labels ( collections.abc.MutableMapping[str, str] | None) – 選用。具有使用者定義中繼資料的標籤。如需更多資訊,請參閱 https://cloud.google.com/translate/docs/advanced/labels

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault | None) – 指示應重試哪些錯誤(如果有的話)。

  • timeout ( float | google.api_core.gapic_v1.method._MethodDefault) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('input_configs', 'target_language_codes', 'source_language_code', 'models', 'glossaries',...[原始碼]
execute(context)[原始碼]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateCreateDatasetOperator(*, project_id=PROVIDE_PROJECT_ID, location, dataset, metadata=(), timeout=DEFAULT, retry=DEFAULT, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[原始碼]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

建立 Google Cloud Translate 資料集。

建立 原生 翻譯資料集,使用 API V3。如需更多關於如何使用此 operator 的資訊,請參閱指南: TranslateCreateDatasetOperator

參數
  • dataset ( dict | google.cloud.translate_v3.types.automl_translation.Dataset) – 要建立的資料集。如果提供 dict,則必須對應於 automl_translation.Dataset 類型。

  • project_id ( str) – 資料集所在的 Google Cloud 專案 ID。如果未提供,則使用預設 project_id。

  • location ( str) – 專案的位置。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault | None) – 指示應重試哪些錯誤(如果有的話)。

  • timeout ( float | google.api_core.gapic_v1.method._MethodDefault) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('dataset', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[原始碼]
execute(context)[原始碼]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateDatasetsListOperator(*, project_id=PROVIDE_PROJECT_ID, location, metadata=(), timeout=DEFAULT, retry=DEFAULT, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[原始碼]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

取得專案中原生 Google Cloud Translation 資料集清單。

取得專案的 原生 翻譯資料集清單,使用 API V3。如需更多關於如何使用此 operator 的資訊,請參閱指南: TranslateDatasetsListOperator

參數
  • project_id ( str) – 資料集所在的 Google Cloud 專案 ID。如果未提供,則使用預設 project_id。

  • location ( str) – 專案的位置。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 指示應重試哪些錯誤(如果有的話)。

  • timeout ( float | google.api_core.gapic_v1.method._MethodDefault) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[原始碼]
execute(context)[source]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateImportDataOperator(*, dataset_id, location, input_config, project_id=PROVIDE_PROJECT_ID, metadata=(), timeout=None, retry=DEFAULT, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

將資料匯入翻譯資料集。

將資料載入至翻譯資料集,使用 API V3。如需更多關於如何使用此運算子的資訊,請參閱指南:TranslateImportDataOperator

參數
  • dataset_id (str) – 要匯入資料的目標原生資料集的 dataset_id。

  • input_config (dict | google.cloud.translate_v3.types.DatasetInputConfig) – 翻譯語言配對檔案的所需輸入位置。如果提供 dict,則必須遵循 DatasetInputConfig 的結構。如果提供 dict,則其格式必須與 protobuf 訊息 InputConfig 相同。

  • project_id ( str) – 資料集所在的 Google Cloud 專案 ID。如果未提供,則使用預設 project_id。

  • location ( str) – 專案的位置。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 指示應重試哪些錯誤(如果有的話)。

  • timeout (float | None) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('dataset_id', 'input_config', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
execute(context)[source]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateDeleteDatasetOperator(*, dataset_id, location, project_id=PROVIDE_PROJECT_ID, metadata=(), timeout=None, retry=DEFAULT, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

刪除翻譯資料集及其所有內容。

刪除翻譯資料集及其資料,使用 API V3。如需更多關於如何使用此運算子的資訊,請參閱指南:TranslateDeleteDatasetOperator

參數
  • dataset_id (str) – 要刪除的目標原生資料集的 dataset_id。

  • location ( str) – 專案的位置。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 指示應重試哪些錯誤(如果有的話)。

  • timeout (float | None) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('dataset_id', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
execute(context)[source]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateCreateModelOperator(*, project_id=PROVIDE_PROJECT_ID, location, dataset_id, display_name, timeout=None, retry=DEFAULT, gcp_conn_id='google_cloud_default', metadata=(), impersonation_chain=None, **kwargs)[source]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

建立 Google Cloud Translate 模型。

建立原生翻譯模型,使用 API V3。如需更多關於如何使用此運算子的資訊,請參閱指南:TranslateCreateModelOperator

參數
  • dataset_id (str) – 用於模型訓練的資料集 ID。

  • project_id ( str) – 資料集所在的 Google Cloud 專案 ID。如果未提供,則使用預設 project_id。

  • location ( str) – 專案的位置。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 指示應重試哪些錯誤(如果有的話)。

  • timeout (float | None) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('dataset_id', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
execute(context)[source]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateModelsListOperator(*, project_id=PROVIDE_PROJECT_ID, location, metadata=(), timeout=DEFAULT, retry=DEFAULT, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

取得專案中原生 Google Cloud Translation 模型清單。

取得專案的原生翻譯模型清單,使用 API V3。如需更多關於如何使用此運算子的資訊,請參閱指南:TranslateModelsListOperator

參數
  • project_id ( str) – 資料集所在的 Google Cloud 專案 ID。如果未提供,則使用預設 project_id。

  • location ( str) – 專案的位置。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 指示應重試哪些錯誤(如果有的話)。

  • timeout ( float | google.api_core.gapic_v1.method._MethodDefault) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
execute(context)[source]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateDeleteModelOperator(*, model_id, location, project_id=PROVIDE_PROJECT_ID, metadata=(), timeout=None, retry=DEFAULT, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

刪除翻譯模型及其所有內容。

刪除翻譯模型及其資料,使用 API V3。如需更多關於如何使用此運算子的資訊,請參閱指南:TranslateDeleteModelOperator

參數
  • model_id (str) – 要刪除的目標原生模型的 model_id。

  • location ( str) – 專案的位置。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 指示應重試哪些錯誤(如果有的話)。

  • timeout (float | None) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('model_id', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
execute(context)[source]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateDocumentOperator(*, location=None, project_id=PROVIDE_PROJECT_ID, source_language_code=None, target_language_code, document_input_config, document_output_config, customized_attribution=None, is_translate_native_pdf_only=False, enable_shadow_removal_native_pdf=False, enable_rotation_correction=False, model=None, glossary_config=None, labels=None, timeout=DEFAULT, retry=DEFAULT, metadata=(), gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

翻譯提供的文件。

包裝 Google Cloud Translation Text (Advanced) 功能。支援廣泛的輸入/輸出檔案類型,請造訪 https://cloud.google.com/translate/docs/advanced/translate-documents 以取得更多詳細資訊。

如需更多關於如何使用此 operator 的資訊,請參閱指南

TranslateDocumentOperator.

參數
  • project_id ( str) – 選用。服務所屬的 Google Cloud 專案 ID。如果未指定,將使用 Hook project_id。

  • source_language_code (str | None) – 選擇性。如果已知,則為輸入文件文字的 ISO-639 語言代碼。如果未指定來源語言,API 會嘗試自動識別來源語言,並在回應中傳回來源語言。

  • target_language_code (str) – 必填。用於翻譯輸入文件文字的 ISO-639 語言代碼。

  • location (str | None) – 選擇性。用於呼叫的專案或位置。必須參考呼叫者的專案。如果未指定,則使用 'global'。使用 AutoML 模型或自訂詞彙表的要求需要非全域位置。模型和詞彙表必須位於相同的區域(具有相同的位置 ID)。

  • document_input_config (google.cloud.translate_v3.types.DocumentInputConfig | dict) – 文件翻譯請求輸入配置。

  • document_output_config (google.cloud.translate_v3.types.DocumentOutputConfig | dict | None) – 選擇性。文件翻譯請求輸出配置。如果未提供,則翻譯後的檔案將僅透過位元組串流傳回,且其輸出 MIME 類型將與輸入檔案的 MIME 類型相同。

  • customized_attribution (str | None) – 選擇性。此旗標用於支援使用者自訂歸屬。如果未提供,預設值為 Machine Translated by Google。自訂歸屬應遵循 https://cloud.google.com/translate/attribution#attribution_and_logos 中的規則

  • is_translate_native_pdf_only (bool) – 選擇性。外部客戶的參數。如果為 true,則線上原生 PDF 翻譯的頁面限制為 300,且僅會翻譯原生 PDF 頁面。

  • enable_shadow_removal_native_pdf (bool) – 選擇性。如果為 true,則使用文字移除伺服器移除原生 PDF 翻譯的背景影像上的陰影文字。僅當 is_translate_native_pdf_onlypdf_native_only 皆為 False 時,才能啟用陰影移除功能。

  • enable_rotation_correction (bool) – 選擇性。如果為 true,則在 DVS 中啟用自動旋轉校正。

  • model ( str | None) –

    選用。此翻譯要求的 model 類型。如果未提供,將使用預設 Google 模型 (NMT)。格式取決於模型類型

    • AutoML Translation 模型: projects/{project-number-or-id}/locations/{location-id}/models/{model-id}

    • 一般 (內建) 模型: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt

    如果未提供,預設的 Google 模型 (NMT) 將用於翻譯。

  • glossary_config ( google.cloud.translate_v3.types.TranslateTextGlossaryConfig | None) – 選用。要套用的詞彙表。

  • transliteration_config – 選擇性。要套用的音譯設定。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault | None) – 指示應重試哪些錯誤(如果有的話)。

  • timeout ( float | google.api_core.gapic_v1.method._MethodDefault) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('source_language_code', 'target_language_code', 'document_input_config',...[source]
execute(context)[source]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

class airflow.providers.google.cloud.operators.translate.TranslateDocumentBatchOperator(*, project_id=PROVIDE_PROJECT_ID, source_language_code, target_language_codes=None, location=None, input_configs, output_config, customized_attribution=None, format_conversions=None, enable_shadow_removal_native_pdf=False, enable_rotation_correction=False, models=None, glossaries=None, metadata=(), timeout=DEFAULT, retry=DEFAULT, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

基底: airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

透過輸入和輸出設定翻譯提供的文件。

每個操作最多支援 10 種目標語言。包裝 Google Cloud Translation Text (Advanced) 功能。請參閱 https://cloud.google.com/translate/docs/advanced/batch-translation

如需更多關於如何使用此運算子的資訊,請參閱指南:TranslateDocumentBatchOperator

參數
  • project_id (str) – 必填。服務所屬的 Google Cloud 專案 ID。

  • source_language_code (str) – 選擇性。如果已知輸入文字的 ISO-639 語言代碼,請使用此參數。如果未指定來源語言,API 會嘗試自動識別來源語言,並在回應中傳回來源語言。

  • target_language_codes (collections.abc.MutableSequence[str] | None) – 必要。用於翻譯輸入文件的 ISO-639 語言代碼。在此處指定最多 10 個語言代碼。

  • location (str | None) – 選擇性。用於呼叫的專案或位置。必須參考呼叫者的專案。如果未指定,則使用 'global'。使用 AutoML 模型或自訂詞彙表的要求需要非全域位置。模型和詞彙表必須位於相同的區域(具有相同的位置 ID)。

  • input_configs (collections.abc.MutableSequence[google.cloud.translate_v3.types.BatchDocumentInputConfig | dict]) – 輸入設定。符合條件的檔案總數應 <= 100。要翻譯的總內容大小應 <= 100M Unicode 字碼指標。檔案必須使用 UTF-8 編碼。

  • output_config (google.cloud.translate_v3.types.BatchDocumentOutputConfig | dict) – 輸出設定。如果 2 個輸入設定符合同一個檔案(即相同的輸入路徑),則不會為重複的輸入產生輸出。

  • format_conversions (collections.abc.MutableMapping[str, str] | None) –

    選擇性。應用於所有輸入檔案的檔案格式轉換對應。對應的鍵是原始 mime_type。對應的值是翻譯後文件的目標 mime_type。支援的檔案格式轉換包括

    • application/pdf 轉換為 application/vnd.openxmlformats-officedocument.wordprocessingml.document

    如果未指定任何內容,輸出檔案將與原始檔案的格式相同。

  • customized_attribution (str | None) – 選擇性。此旗標用於支援使用者自訂歸屬。如果未提供,預設值為 Machine Translated by Google。自訂歸屬應遵循 https://cloud.google.com/translate/attribution#attribution_and_logos 中的規則

  • enable_shadow_removal_native_pdf (bool) – 選擇性。如果為 true,則使用文字移除伺服器移除原生 PDF 翻譯的背景影像上的陰影文字。僅當 is_translate_native_pdf_onlypdf_native_only 皆為 False 時,才能啟用陰影移除功能。

  • enable_rotation_correction (bool) – 選擇性。如果為 true,則在 DVS 中啟用自動旋轉校正。

  • models (collections.abc.MutableMapping[str, str] | None) –

    選擇性。用於翻譯的模型。對應的鍵是目標語言代碼。對應的值是模型名稱。值可以是內建通用模型,或是 AutoML Translation 模型。值的格式取決於模型類型

    • AutoML Translation 模型: projects/{project-number-or-id}/locations/{location-id}/models/{model-id}

    • 通用(內建)模型:projects/{project-number-or-id}/locations/{location-id}/models/general/nmt

    如果對應為空,或者未針對語言對請求特定模型,則會使用預設的 Google 模型 (NMT)。

  • glossaries (collections.abc.MutableMapping[str, google.cloud.translate_v3.types.TranslateTextGlossaryConfig] | None) – 要應用的詞彙表。它以目標語言代碼作為鍵。

  • retry ( google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault | None) – 指示應重試哪些錯誤(如果有的話)。

  • timeout ( float | google.api_core.gapic_v1.method._MethodDefault) – 此請求的逾時時間。

  • metadata ( collections.abc.Sequence[tuple[str, str]]) – 應與請求一起以中繼資料形式傳送的字串。

  • gcp_conn_id ( str) – 用於連線至 Google Cloud 的連線 ID。

  • impersonation_chain ( str | collections.abc.Sequence[str] | None) – 選用的服務帳戶,用於模擬短期憑證,或取得清單中最後一個帳戶的 access_token 所需的鏈結帳戶清單,該帳戶將在請求中被模擬。如果設定為字串,則帳戶必須授予原始帳戶「服務帳戶權杖建立者」IAM 角色。如果設定為序列,則清單中的身分必須授予緊鄰前一個身分「服務帳戶權杖建立者」IAM 角色,清單中的第一個帳戶將此角色授予原始帳戶 (已套用範本)。

template_fields: collections.abc.Sequence[str] = ('input_configs', 'output_config', 'target_language_codes', 'source_language_code', 'models',...[source]
execute(context)[source]

在建立 operator 時衍生。

Context 是與呈現 jinja 範本時使用的字典相同。

請參閱 get_template_context 以取得更多 context。

這篇文章是否對您有幫助?