StartGcpVisionAnnotateFilesOperation

文档中心 › 组件索引 › StartGcpVisionAnnotateFilesOperation

StartGcpVisionAnnotateFilesOperation Processor

类型全限定名:cn.org.acal.lynxus.processors.gcp.vision.StartGcpVisionAnnotateFilesOperation

所属 Bundle:cn.org.acal.lynxus:lynxus-gcp-nar:2.11.8

描述

对文件输入触发 Vision 操作。 它后面应该是 GetGcpVisionAnnotateFilesOperationStatus 处理器,以便监视操作状态。

标签

GoogleCloudMachine LearningVision

属性

下表中,加粗的属性为必填项;其余为可选项。表格同时标注默认值、是否支持表达式语言,以及是否为敏感属性(值会被加密)。

名称默认值可选值描述
JSON Payload{ "requests": [ { "inputConfig": { "gcsSource": { "uri": "gs://${gcs.bucket}/${filename}" }, "mimeType": "application/pdf" }, "features": [{ "type": "${vision-feature-type}", "maxResults": 4 }], "outputConfig": { "gcsDestination": { "uri": "gs://${output-bucket}/${filename}/" }, "batchSize": 2 } }] }AWS 机器学习服务的 JSON 请求。 当未指定此属性时,处理器将使用 FlowFile 内容进行请求。
支持表达式语言:是(使用 FlowFile 属性与环境/系统变量求值)
GCP Credentials Provider Service控制器服务 API:
GCPCredentialsService
cn.org.acal.lynxus-lynxus-gcp-services-api-nar-2.11.8
用于获取 Google Cloud Platform 凭据的Controller Service。
输出存储桶Vision 作业输出将持久化的 GCS 存储桶名称。此属性的值在配置了 JSON Payload 属性时适用。JSON Payload 属性值可以使用表达式语言引用 ${output-bucket} 的值
支持表达式语言:是(使用 FlowFile 属性与环境/系统变量求值)
Vision 功能类型TEXT_DETECTIONGCP Vision 功能类型。此属性的值在配置了 JSON Payload 属性时适用。JSON Payload 属性值可以使用表达式语言引用 ${vision-feature-type} 的值
支持表达式语言:是(使用 FlowFile 属性与环境/系统变量求值)

关系 (Relationships)

名称描述自动终止
failureFlowFiles被路由到故障关系否
successFlowFiles被路由到成功关系否

写入的 FlowFile 属性

名称描述
operationKeyVision 服务器返回的操作的唯一标识符。

状态管理

该组件不存储状态。

受限 (Restricted)

该组件不受限。

详细说明

Google Vision

Google Cloud Vision - 启动文件标注操作

前提条件

  • 确保已启用 Vision API,且你使用的账户有权使用它
  • 确保输入文件位于 GCS 桶中

用法

StartGcpVisionAnnotateFilesOperation 用于触发文件标注操作。该 Processor 应与 GetGcpVisionAnnotateFilesOperationStatus Processor 配对使用。输出 FlowFile 包含 Vision 服务器返回的针对该请求的 原始响应。响应为 JSON 格式,包含结果和附加元数据,具体参见 Google Vision API 参考文档。

负载(Payload)

JSON Payload 是 Google Vision REST API 参考文档 中记载的 JSON 格式请求。负载可以通过 JSON Payload 属性或 FlowFile 内容提供给 Processor,属性的优先级高于 FlowFile 内容。 如果想使用 FlowFile 内容作为负载,请确保删除该属性的默认值。 JSON 负载模板示例:

{
  "requests": [
    {
      "inputConfig": {
        "gcsSource": {
          "uri": "gs://${gcs.bucket}/${filename}"
        },
        "mimeType": "application/pdf"
      },
      "features": [
        {
          "type": "${vision-feature-type}",
          "maxResults": 4
        }
      ],
      "outputConfig": {
        "gcsDestination": {
          "uri": "gs://${output-bucket}/${filename}/"
        },
        "batchSize": 2
      }
    }
  ]
}

Feature 类型

  • TEXT_DETECTION: 针对图像的光学字符识别(OCR);识别文本并转换为 机器编码文本。识别并提取图像中的 UTF-8 文本。
  • DOCUMENT_TEXT_DETECTION: 针对文件(PDF/TIFF)或密集文本图像的光学 字符识别(OCR);密集文本识别并转换为机器编码文本。

更多细节参见 Google Vision Feature List

示例:如何搭建一个简单的文件标注流程

前提条件

  • 创建输入桶和输出桶
  • 输入文件应位于 GCS 桶中
  • 该桶中除输入文件外不能包含其他内容
  • 把 ListGCSBucket Processor 的 bucket 属性设为你的输入桶名称
  • 保持 StartGcpVisionAnnotateFilesOperation 中 JSON PAYLOAD 属性的默认值
  • 在 StartGcpVisionAnnotateFilesOperation 中,把 Output Bucket 属性设为你的输出桶名称
  • 为所有 GCP 相关的 Processor 配置 GCP Credentials Provider Service

执行步骤:

  • ListGCSBucket Processor 在首次运行时返回桶中的文件列表。
  • ListGCSBucket 在后续运行中只返回新增项。
  • StartGcpVisionAnnotateFilesOperation Processor 根据 JSON 负载触发 GCP Vision 文件标注任务。
  • StartGcpVisionAnnotateFilesOperation Processor 会填充 operationKey FlowFile Attribute。
  • GetGcpVisionAnnotateFilesOperationStatus Processor 会周期性查询任务状态。