airflow.providers.google.cloud.operators.translate

此模块包含 Google Translate 操作符。

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

通过输入和输出配置翻译提供的文档。

TranslateCreateGlossaryOperator

创建一个 Google Cloud Translation 术语表。

TranslateUpdateGlossaryOperator

使用提供的值更新术语表项。

TranslateListGlossariesOperator

获取项目中的翻译术语表列表。

TranslateDeleteGlossaryOperator

删除一个 Google Cloud Translation 术语表。

模块内容

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)[source]

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

翻译字符串或字符串列表。

另请参阅

有关如何使用此操作符的更多信息,请参阅指南: CloudTranslateTextOperator

参阅 https://cloud.google.com/translate/docs/translating-text

Execute 方法返回 str 或 list。

这是每个查询值的字典列表。每个字典通常包含三个键(尽管并非所有情况都存在)

  • 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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('values', 'target_language', 'format_', 'source_language', 'model', 'gcp_conn_id',...[source]
values[source]
target_language[source]
format_[source]
source_language[source]
model[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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)[source]

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

翻译适量的文本内容,对于大量文本请使用 TranslateTextBatchOperator。

封装了 Google Cloud Translate Text(高级)功能。参阅 https://cloud.google.com/translate/docs/advanced/translating-text-v3

有关如何使用此操作符的更多信息,请参阅指南

TranslateTextOperator.

参数:
  • project_id (str) – 可选。服务所属的 Google Cloud 项目 ID。如果未提供,则使用默认 project_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

    • 翻译 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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('contents', 'target_language_code', 'mime_type', 'source_language_code', 'model',...[source]
project_id = None[source]
contents[source]
source_language_code = None[source]
target_language_code[source]
mime_type = None[source]
location = None[source]
labels = None[source]
model = None[source]
transliteration_config = None[source]
glossary_config = None[source]
metadate = ()[source]
timeout[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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)[source]

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

根据提供的输入翻译大量文本内容。

封装了 Google Cloud Translate Text(高级)功能。参阅 https://cloud.google.com/translate/docs/advanced/batch-translation

有关如何使用此操作符的更多信息,请参阅指南: 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 (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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('input_configs', 'target_language_codes', 'source_language_code', 'models', 'glossaries',...[source]
project_id = None[source]
location[source]
target_language_codes[source]
source_language_code[source]
input_configs[source]
output_config[source]
models = None[source]
glossaries = None[source]
labels = None[source]
metadata = ()[source]
timeout[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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)[source]

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

创建一个 Google Cloud Translate 数据集。

使用 API V3 创建原生翻译数据集。有关如何使用此操作符的更多信息,请参阅指南:TranslateCreateDatasetOperator

参数:
  • dataset (dict | google.cloud.translate_v3.types.automl_translation.Dataset) – 要创建的数据集。如果提供了字典,则必须与 automl_translation.Dataset 类型对应。如果提供了字典,则必须与 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 | 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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('dataset', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
project_id = None[source]
location[source]
dataset[source]
metadata = ()[source]
timeout[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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)[source]

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

获取项目中原生的 Google Cloud Translation 数据集列表。

使用 API V3 获取项目的原生翻译数据集列表。有关如何使用此操作符的更多信息,请参阅指南: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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

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

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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) – 期望的翻译语言对文件的输入位置。如果提供了字典,则必须遵循 DatasetInputConfig 的结构。如果提供了字典,则必须与 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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

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

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

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

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('dataset_id', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
project_id = None[source]
location[source]
dataset_id[source]
display_name[source]
metadata = ()[source]
timeout = None[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

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

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

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

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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=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, retry=DEFAULT, metadata=(), gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

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

翻译提供的文档。

封装了 Google Cloud Translate Text(高级)功能。支持多种输入/输出文件类型,详情请访问 https://cloud.google.com/translate/docs/advanced/translate-documents

有关如何使用此操作符的更多信息,请参阅指南

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 模型或自定义词汇表的请求需要非全局位置。模型和词汇表必须位于同一区域(具有相同的 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_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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('source_language_code', 'target_language_code', 'document_input_config',...[source]
project_id = None[source]
source_language_code = None[source]
target_language_code[source]
document_input_config[source]
document_output_config[source]
customized_attribution = None[source]
is_translate_native_pdf_only = False[source]
enable_shadow_removal_native_pdf = False[source]
enable_rotation_correction = False[source]
location = None[source]
labels = None[source]
model = None[source]
glossary_config = None[source]
metadate = ()[source]
timeout[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_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 Translate Text (高级) 功能。参见 https://cloud.google.com/translate/docs/advanced/batch-translation

有关如何使用此 Operator 的更多信息,请参阅指南: 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 模型或自定义词汇表的请求需要非全局位置。模型和词汇表必须位于同一区域(具有相同的 location-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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('input_configs', 'output_config', 'target_language_codes', 'source_language_code', 'models',...[source]
project_id = None[source]
location = None[source]
target_language_codes = None[source]
source_language_code[source]
input_configs[source]
output_config[source]
customized_attribution = None[source]
format_conversions = None[source]
enable_shadow_removal_native_pdf = False[source]
enable_rotation_correction = False[source]
models = None[source]
glossaries = None[source]
metadata = ()[source]
timeout[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_context。

class airflow.providers.google.cloud.operators.translate.TranslateCreateGlossaryOperator(*, project_id=PROVIDE_PROJECT_ID, location, glossary_id, input_config, language_pair=None, language_codes_set=None, 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 Translation 术语表。

使用 API V3 创建翻译词汇表。有关如何使用此 Operator 的更多信息,请参阅指南: TranslateCreateGlossaryOperator

参数:
  • glossary_id (str) – 用户指定的 ID,用于构建词汇表资源名称。

  • input_config (google.cloud.translate_v3.types.translation_service.GlossaryInputConfig | dict) – 用于构建词汇表的示例输入配置。总词汇表不得超过 10M Unicode 代码点。输入文件中不应包含表头,因为语言信息已通过 language_pairlanguage_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 应为空。

  • 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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('glossary_id', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
project_id = None[source]
location[source]
glossary_id[source]
input_config[source]
language_pair = None[source]
language_codes_set = None[source]
metadata = ()[source]
timeout = None[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_context。

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

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

使用提供的值更新术语表项。

使用翻译 API V3 更新翻译词汇表。仅允许更新 display_nameinput_config 字段。

有关如何使用此 Operator 的更多信息,请参阅指南: TranslateUpdateGlossaryOperator

参数:
  • glossary_id (str) – 用户指定的 ID,用于构建词汇表资源名称。

  • input_config – 用于构建词汇表的示例的输入配置。词汇表总大小不得超过 10M Unicode 码位。输入文件表格中不应包含标题行,因为语言已通过 language_pairlanguage_codes_set 参数指定。

  • language_pair – 用于创建词汇表的语言代码对。用于构建单向词汇表。如果指定此参数,则 language_codes_set 应为空。

  • language_codes_set – 用于创建等效术语集词汇表的语言代码集。表示多种语言映射。如果指定此参数,则 language_pair 应为空。

  • 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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('glossary_id', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
project_id = None[source]
location[source]
glossary_id[source]
new_display_name[source]
new_input_config = None[source]
metadata = ()[source]
timeout = None[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_context。

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

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

获取项目中的翻译术语表列表。

使用 Translation API V3 列出翻译词汇表。

有关如何使用此 Operator 的更多信息,请参阅指南:TranslateListGlossariesOperator

参数:
  • project_id (str) – 词汇表所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • page_size (int | None) – 请求的页大小,如果未设置,服务器将使用适当的默认值。

  • page_token (str | None) – 标识服务器应返回的结果页面的令牌。如果 page_token 为空或缺失,则返回第一页。

  • filter_str (str | None) – 指定列表操作约束的过滤器。通过“key=value”的格式指定约束,其中 key 必须是 srctgt,value 必须是有效的语言代码。对于多个限制,使用“AND”(仅限大写)连接,例如:src=en-US AND tgt=zh-CN。请注意,此处使用的是精确匹配,这意味着使用“en-US”和“en”可能会导致不同的结果,这取决于您创建词汇表时使用的语言代码。对于单向词汇表,srctgt 分别对源语言代码和目标语言代码添加限制。对于等效术语集词汇表,src 和/或 tgt 对术语集添加限制。例如:src=en-US AND tgt=zh-CN 将仅选取源语言代码和目标语言代码精确匹配 en-USzh-CN 的单向词汇表,但将选取其语言集中包含 en-USzh-CN 的所有等效术语集词汇表。如果缺失,则不执行过滤。

  • 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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
project_id = None[source]
location[source]
page_size = None[source]
page_token = None[source]
filter_str = None[source]
metadata = ()[source]
timeout = None[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_context。

class airflow.providers.google.cloud.operators.translate.TranslateDeleteGlossaryOperator(*, project_id=PROVIDE_PROJECT_ID, location, glossary_id, 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 Translation 术语表。

使用 API V3 删除翻译词汇表。有关如何使用此 Operator 的更多信息,请参阅指南:TranslateDeleteGlossaryOperator

参数:
  • glossary_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 所需的账号链列表,该账号将在请求中被模拟。如果设置为字符串,则该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接前一个身份 Service Account Token Creator IAM 角色,列表中的第一个账号授予发起账号此角色(模板化)。

template_fields: collections.abc.Sequence[str] = ('glossary_id', 'location', 'project_id', 'gcp_conn_id', 'impersonation_chain')[source]
glossary_id[source]
project_id = None[source]
location[source]
metadata = ()[source]
timeout = None[source]
retry[source]
gcp_conn_id = 'google_cloud_default'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建操作符时派生。

Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参阅 get_template_context。

此条目是否有帮助?