airflow.providers.google.cloud.hooks.translate¶
此模組包含一個 Google Cloud Translate Hook。
異常¶
等待操作尚未完成錯誤。 |
類¶
Google Cloud 翻譯 API 的 Hook。 |
|
使用 V3 客戶端版本的 Google Cloud 翻譯 (高階) 的 Hook。 |
模組內容¶
- exception airflow.providers.google.cloud.hooks.translate.WaitOperationNotDoneYetError[source]¶
基類:
Exception等待操作尚未完成錯誤。
- class airflow.providers.google.cloud.hooks.translate.CloudTranslateHook(gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]¶
基類:
airflow.providers.google.common.hooks.base_google.GoogleBaseHookGoogle Cloud 翻譯 API 的 Hook。
Hook 中所有使用 project_id 的方法必須使用關鍵字引數呼叫,而不是位置引數。
- get_conn()[source]¶
檢索到 Cloud Translate 的連線。
- 返回:
Google Cloud Translate 客戶端物件。
- 返回型別:
google.cloud.translate_v2.Client
- translate(values, target_language, format_=None, source_language=None, model=None)[source]¶
翻譯一個字串或字串列表。
參考 https://cloud.google.com/translate/docs/translating-text
- 引數:
- 返回:
返回一個列表,其中包含每個查詢值的字典。每個字典通常包含三個鍵(並非所有情況下都存在)
`detectedSourceLanguage`: 檢測到的文字語言(以 ISO 639-1 語言程式碼表示)。
`translatedText`: 文字翻譯成目標語言的結果。
`input`: 對應的輸入值。
`model`: 用於翻譯文字的模型。
如果只傳遞單個值,則僅返回一個字典。
- 丟擲:
`ValueError` 如果值和翻譯的數量不同。
- 返回型別:
- class airflow.providers.google.cloud.hooks.translate.TranslateHook(gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]¶
基類:
airflow.providers.google.common.hooks.base_google.GoogleBaseHook,airflow.providers.google.common.hooks.operation_helpers.OperationHelper使用 V3 客戶端版本的 Google Cloud 翻譯 (高階) 的 Hook。
參考相關文件 https://cloud.google.com/translate/docs/editions#advanced。
- get_client()[source]¶
檢索 TranslationService 客戶端。
- 返回:
Google Cloud Translation Service 客戶端物件。
- 返回型別:
google.cloud.translate_v3.TranslationServiceClient
- static wait_for_operation_done(*, operation, timeout=None, initial=3, multiplier=2, maximum=3600)[source]¶
等待長時間執行的操作完成。
呼叫 operation.done() 直到成功或超時,遵循指數退避重試策略。參考 `google.api_core.retry.Retry`。其預期用途是在設計上具有空結果(:`google.protobuf.empty_pb2.Empty`)的 `Operation` 例項上。因此,對此類操作呼叫 operation.result() 會觸發異常 `GoogleAPICallError("Unexpected state: Long-running operation had neither response nor error set.")`,即使操作本身完全正常。
- translate_text(*, project_id=PROVIDE_PROJECT_ID, contents, target_language_code, source_language_code=None, mime_type=None, location=None, model=None, transliteration_config=None, glossary_config=None, labels=None, timeout=DEFAULT, metadata=(), retry=DEFAULT)[source]¶
翻譯提供的文字內容。
- 引數:
project_id (str) – 必需。服務所屬的 Google Cloud 專案的 ID。
contents (collections.abc.Sequence[str]) – 必需。輸入內容的字串格式。建議最大長度為 1024 項,30,000 個碼位。
mime_type (str | None) – 可選。源文字的格式,如果留空,MIME 型別預設為“text/html”。
source_language_code (str | None) – 可選。如果已知輸入文字的 ISO-639 語言程式碼。如果未指定源語言,API 會嘗試自動識別源語言並在響應中返回源語言。
target_language_code (str) – 必需。用於翻譯輸入文字的 ISO-639 語言程式碼
location (str | None) – 可選。進行呼叫的專案或位置。必須引用呼叫者的專案。如果未指定,則使用“global”。使用 AutoML 模型或自定義詞彙表時,需要非 global 位置。模型和詞彙表必須位於同一區域(具有相同的 location-id)。
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` `global`。例如,`projects/{project-number-or-id}/locations/global/models/general/nmt`。
glossary_config (google.cloud.translate_v3.types.TranslateTextGlossaryConfig | None) – 可選。要應用的詞彙表。詞彙表必須位於與模型同一區域(具有相同的 location-id)。
transliteration_config (google.cloud.translate_v3.types.TransliterationConfig | None) – 可選。要應用的音譯配置。
labels (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) – 此請求的超時時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]) – 應隨請求一起作為元資料傳送的字串。
- 返回:
API 響應中的翻譯文字結果。
- 返回型別:
- batch_translate_text(*, project_id=PROVIDE_PROJECT_ID, location, source_language_code, target_language_codes, input_configs, output_config, models=None, glossaries=None, labels=None, timeout=DEFAULT, metadata=(), retry=DEFAULT)[source]¶
翻譯大量文字資料。
- 引數:
project_id (str) – 必需。服務所屬的 Google Cloud 專案的 ID。
location (str) – 可選。進行呼叫的專案或位置。必須引用呼叫者的專案。必須是非 global 的。
source_language_code (str) – 必需。源語言程式碼。
target_language_codes (collections.abc.MutableSequence[str]) – 必需。在此處指定最多 10 個語言程式碼。
models (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)。
input_configs (collections.abc.MutableSequence[google.cloud.translate_v3.types.InputConfig | dict]) – 必需。輸入配置。匹配檔案的總數應 <= 100。總內容大小應 <= 100M Unicode 碼位。檔案必須使用 UTF-8 編碼。
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) – 此請求的超時時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]) – 應隨請求一起作為元資料傳送的字串。
- 返回:
包含批次文字翻譯結果的 Operation 物件,結果會隨著準備就緒而分批返回。
- 返回型別:
- create_dataset(*, project_id=PROVIDE_PROJECT_ID, location, dataset, timeout=DEFAULT, metadata=(), retry=DEFAULT)[source]¶
建立翻譯資料集。
- 引數:
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) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
待建立資料集的 `Operation` 物件。
- 返回型別:
- get_dataset(dataset_id, project_id, location, retry=DEFAULT, timeout=DEFAULT, metadata=())[source]¶
檢索給定 dataset_id 的資料集。
- 引數:
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) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
`automl_translation.Dataset` 例項。
- 返回型別:
google.cloud.translate_v3.types.automl_translation.Dataset
- import_dataset_data(dataset_id, location, input_config, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None, metadata=())[source]¶
將資料匯入翻譯資料集。
- 引數:
dataset_id (str) – 翻譯資料集的 ID。
input_config (dict | google.cloud.translate_v3.types.DatasetInputConfig) – 期望的輸入位置及其特定於域的語義(如果有)。如果提供了 dict,其形式必須與 protobuf 訊息 InputConfig 相同。
project_id (str) – 資料集所在的 Google Cloud 專案 ID,如果為 None,則使用預設 project_id。
location (str) – 專案的位置。
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | None) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
資料匯入的 `Operation` 物件。
- 返回型別:
- list_datasets(project_id, location, retry=DEFAULT, timeout=DEFAULT, metadata=())[source]¶
列出專案中的翻譯資料集。
- 引數:
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) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
pagers.ListDatasetsPager例項,用於檢索資料集列表的可迭代物件。- 返回型別:
google.cloud.translate_v3.services.translation_service.pagers.ListDatasetsPager
- delete_dataset(dataset_id, project_id, location, retry=DEFAULT, timeout=None, metadata=())[source]¶
刪除翻譯資料集及其所有內容。
- 引數:
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) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | None) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
包含資料集刪除結果的 Operation 物件(操作完成後)。
- 返回型別:
- create_model(dataset_id, display_name, project_id, location, retry=DEFAULT, timeout=None, metadata=())[source]¶
透過提供的翻譯資料集訓練建立原生模型。
- 引數:
dataset_id (str) – 用於模型訓練的資料集的 ID。
display_name (str) – 已訓練模型的顯示名稱。可包含 A-Z 和 a-z、下劃線 (_) 以及 ASCII 數字 0-9。
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 | None) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
包含模型建立結果的 Operation 物件(操作完成後)。
- 返回型別:
- get_model(model_id, project_id, location, retry=DEFAULT, timeout=DEFAULT, metadata=())[source]¶
根據給定的 model_id 檢索資料集。
- 引數:
model_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) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
automl_translation.Model 例項。
- 返回型別:
google.cloud.translate_v3.types.automl_translation.Model
- list_models(project_id, location, filter_str=None, page_size=None, retry=DEFAULT, timeout=DEFAULT, metadata=())[source]¶
列出專案中的翻譯模型。
- 引數:
project_id (str) – 模型所在的 Google Cloud 專案的 ID。如果未提供,則使用預設的 project_id。
location (str) – 專案的位置。
filter_str (str | None) – 用於過濾將返回模型的可選表示式。支援的過濾器:
dataset_id=${dataset_id}。page_size (int | None) – 可選的自定義頁面大小值。伺服器返回的結果可能少於請求的數量。
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
pagers.ListDatasetsPager例項,用於檢索資料集列表的可迭代物件。- 返回型別:
google.cloud.translate_v3.services.translation_service.pagers.ListModelsPager
- delete_model(model_id, project_id, location, retry=DEFAULT, timeout=None, metadata=())[source]¶
刪除翻譯模型及其所有內容。
- 引數:
model_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) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | None) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
包含資料集刪除結果的 Operation 物件(操作完成後)。
- 返回型別:
- translate_document(*, project_id=PROVIDE_PROJECT_ID, source_language_code=None, target_language_code, location=None, document_input_config, document_output_config=None, 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, metadata=(), retry=DEFAULT)[source]¶
翻譯提供的文件。
- 引數:
project_id (str) – 必需。服務所屬的 Google Cloud 專案的 ID。
source_language_code (str | None) – 可選。如果已知輸入文件文字的 ISO-639 語言程式碼。如果未指定源語言,API 會嘗試自動識別源語言並在響應中返回源語言。
target_language_code (str) – 必需。用於翻譯輸入文件文字的 ISO-639 語言程式碼。
location (str | None) – 可選。進行呼叫的專案或位置。必須引用呼叫者的專案。如果未指定,則使用“global”。使用 AutoML 模型或自定義詞彙表時,需要非 global 位置。模型和詞彙表必須位於同一區域(具有相同的 location-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_only和pdf_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) – 可選。要應用的詞彙表。詞彙表必須位於與模型同一區域(具有相同的 location-id)。
labels (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) – 此請求的超時時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]) – 應隨請求一起作為元資料傳送的字串。
- 返回:
API 響應中的文件翻譯結果。
- 返回型別:
- batch_translate_document(*, 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, timeout=DEFAULT, metadata=(), retry=DEFAULT)[source]¶
根據提供的配置批次翻譯文件。
- 引數:
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 模型或自定義詞彙表時,需要非 global 位置。模型和詞彙表必須位於同一區域(具有相同的 location-id)。
input_configs (collections.abc.MutableSequence[google.cloud.translate_v3.types.BatchDocumentInputConfig | dict]) – 輸入配置。匹配的檔案總數應 <= 100。要翻譯的總內容大小應 <= 1 億 Unicode 碼點。檔案必須使用 UTF-8 編碼。
output_config (google.cloud.translate_v3.types.BatchDocumentOutputConfig | dict) – 輸出配置。如果兩個輸入配置匹配到同一個檔案(即相同的輸入路徑),則不會為重複輸入生成輸出。
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_only和pdf_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) – 此請求的超時時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]) – 應隨請求一起作為元資料傳送的字串。
- 返回:
API 響應中的批次文件翻譯結果。
- 返回型別:
- create_glossary(project_id, location, glossary_id, input_config, language_pair=None, language_codes_set=None, retry=DEFAULT, timeout=None, metadata=())[source]¶
從輸入原始檔建立詞彙表資源。
- 引數:
project_id (str) – 資料集所在的 Google Cloud 專案 ID。如果未提供,則使用預設 project_id。
location (str) – 專案的位置。
glossary_id (str) – 使用者指定的 ID,用於構建詞彙表資源名稱。
input_config (google.cloud.translate_v3.types.translation_service.GlossaryInputConfig | dict) – 用於構建詞彙表示例的輸入配置。總詞彙表不得超過 1000 萬 Unicode 碼點。輸入檔案表中不應包含標題,因為語言是使用
language_pair或language_codes_set引數指定的。language_pair (google.cloud.translate_v3.types.translation_service.Glossary.LanguageCodePair | dict | None) – 用於詞彙表建立的語言程式碼對。用於構建單向詞彙表。如果指定此引數,則
language_codes_set應為空。language_codes_set (google.cloud.translate_v3.types.translation_service.Glossary.LanguageCodesSet | collections.abc.MutableSequence[str] | None) – 用於建立等效術語集詞彙表的語言程式碼集。意為多語言對映。如果指定此引數,則
language_pair應為空。retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | None) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
包含詞彙表建立結果的 Operation 物件。
- 返回型別:
- get_glossary(project_id, location, glossary_id, retry=DEFAULT, timeout=None, metadata=())[source]¶
根據給定的 ID 獲取詞彙表專案資料。
glossary_id 是詞彙表名稱的子字串,遵循以下格式:
projects/{project-number-or-id}/locations/{location-id}/glossaries/{glossary-id}- 引數:
project_id (str) – 資料集所在的 Google Cloud 專案 ID。如果未提供,則使用預設 project_id。
location (str) – 專案的位置。
glossary_id (str) – 使用者指定的 ID,用於構建詞彙表資源名稱。
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | None) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
獲取到的詞彙表專案。
- 返回型別:
google.cloud.translate_v3.types.translation_service.Glossary
- update_glossary(glossary, new_display_name=None, new_input_config=None, retry=DEFAULT, timeout=None, metadata=())[source]¶
使用提供的值更新詞彙表專案。
只允許更新
display_name和input_config欄位。- 引數:
glossary (google.cloud.translate_v3.types.translation_service.Glossary) – 要更新的詞彙表專案。
new_display_name (str | None) – 要更新的
display_name的新值。new_input_config (google.cloud.translate_v3.types.translation_service.GlossaryInputConfig | dict | None) – 要更新的
input_config的新值。retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | None) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
包含詞彙表更新結果的 Operation 物件。
- 返回型別:
- list_glossaries(project_id, location, page_size=None, page_token=None, filter_str=None, retry=DEFAULT, timeout=None, metadata=())[source]¶
獲取可用詞彙表列表。
- 引數:
project_id (str) – 資料集所在的 Google Cloud 專案 ID。如果未提供,則使用預設 project_id。
location (str) – 專案的位置。
page_size (int | None) – 請求的頁面大小,如果未設定,則伺服器使用適當的預設值。
page_token (str | None) – 標識伺服器應返回的結果頁面的令牌。如果
page_token為空或缺失,則返回第一頁。filter_str (str | None) – 指定列表操作約束的過濾器。透過 “key=value” 格式指定約束,其中 key 必須是
src或tgt,而 value 必須是有效的語言程式碼。對於多個限制,使用 “AND”(僅大寫)連線它們,例如:src=en-US AND tgt=zh-CN。請注意,這裡使用的是精確匹配,這意味著使用 'en-US' 和 'en' 可能會得到不同的結果,這取決於您建立詞彙表時使用的語言程式碼。對於單向詞彙表,src和tgt分別對源語言和目標語言程式碼新增限制。對於等效術語集詞彙表,src和/或tgt對術語集新增限制。例如:src=en-US AND tgt=zh-CN將只選取源語言程式碼精確匹配en-US且目標語言程式碼精確匹配zh-CN的單向詞彙表,但所有在其語言集中包含en-US和zh-CN的等效術語集詞彙表都將被選取。如果缺失,則不執行過濾。retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | None) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
詞彙表列表分頁器物件。
- 返回型別:
google.cloud.translate_v3.services.translation_service.pagers.ListGlossariesPager
- delete_glossary(project_id, location, glossary_id, retry=DEFAULT, timeout=None, metadata=())[source]¶
透過給定 ID 刪除詞彙表項。
- 引數:
project_id (str) – 資料集所在的 Google Cloud 專案 ID。如果未提供,則使用預設 project_id。
location (str) – 專案的位置。
glossary_id (str) – 要刪除的詞彙表 ID。
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用於重試請求的重試物件。如果指定了 `None`,則不會重試請求。
timeout (float | None) – 等待請求完成的時間(秒)。請注意,如果指定了 `retry`,則超時適用於每次單獨的嘗試。
metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供給方法的額外元資料。
- 返回:
Operation 包含詞彙表刪除結果。
- 返回型別: