文档分割器行为

拆分器处理器的输出包含输入文档的拆分信息,包括置信度得分。Document AI API 会输出 Document JSON 对象,并且输出格式使用 entities 字段来表示文档拆分。其他信息取决于分路器的具体类型。

  • Entity.type 指定文档分类。如需查看可识别的证件类型的完整列表,请参阅以下列表

  • Entity.pageAnchor.pageRefs[] 用于指定包含每个子文档的网页。请注意,pageRefs[].page 从零开始,是 document.pages[] 字段的索引。

使用生成式 AI 的拆分器版本不适合拆分超过 500 页的逻辑文档。您可以手动将超过 500 页的逻辑文档拆分为两个或更多文档,然后分别运行拆分器对它们进行分类。

分块器用于识别页面边界,但不会实际为您拆分输入文档。Document AI Toolbox SDK 提供了一些实用函数,这些函数可以根据拆分器处理器的输出拆分输入文档。

已识别的证件类型

[1] 相应表单的解析器不支持此文档类型。这意味着拆分器可以识别并分类此类文档,但 Document AI 不提供用于提取信息的解析器。

输出示例

处理器 输出示例

代码示例

拆分器会识别页面边界,但不会实际拆分输入文档。您可以使用 Document AI 工具箱,通过使用页面边界来实际拆分 PDF 文件。 以下代码示例会打印指定页范围,而不会拆分 PDF:

Java

如需了解详情,请参阅 Document AI Java API 参考文档

如需向 Document AI 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


import com.google.cloud.documentai.v1beta3.Document;
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceSettings;
import com.google.cloud.documentai.v1beta3.ProcessRequest;
import com.google.cloud.documentai.v1beta3.ProcessResponse;
import com.google.cloud.documentai.v1beta3.RawDocument;
import com.google.protobuf.ByteString;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

public class ProcessSplitterDocument {
  public static void processSplitterDocument()
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String location = "your-project-location"; // Format is "us" or "eu".
    String processerId = "your-processor-id";
    String filePath = "path/to/input/file.pdf";
    processSplitterDocument(projectId, location, processerId, filePath);
  }

  public static void processSplitterDocument(
      String projectId, String location, String processorId, String filePath)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // Initialize client that will be used to send requests. This client only needs
    // to be created
    // once, and can be reused for multiple requests. After completing all of your
    // requests, call
    // the "close" method on the client to safely clean up any remaining background
    // resources.
    String endpoint = String.format("%s-documentai.googleapis.com:443", location);
    DocumentProcessorServiceSettings settings =
        DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
      // The full resource name of the processor, e.g.:
      // projects/project-id/locations/location/processor/processor-id
      // You must create new processors in the Cloud Console first
      String name =
          String.format("projects/%s/locations/%s/processors/%s", projectId, location, processorId);