Perilaku pemisah dokumen

Output pemroses pemisah berisi informasi pemisahan untuk dokumen input, termasuk skor keyakinan. Document AI API menghasilkan objek JSON Document, dan format output menggunakan kolom entities untuk merepresentasikan pemisahan dokumen. Informasi tambahan bergantung pada jenis pemisah tertentu.

  • Entity.type menentukan klasifikasi dokumen. Untuk mengetahui daftar lengkap jenis dokumen yang dapat diidentifikasi, lihat daftar berikut.

  • Entity.pageAnchor.pageRefs[] menentukan halaman yang berisi setiap sub-dokumen. Perhatikan bahwa pageRefs[].page berbasis nol dan merupakan indeks ke dalam kolom document.pages[].

Versi pemisah yang menggunakan AI generatif tidak dirancang untuk memisahkan dokumen logis yang panjangnya lebih dari 500 halaman. Anda dapat memisahkan dokumen logis secara manual yang panjangnya lebih dari 500 halaman menjadi dua dokumen atau lebih, lalu menjalankan pemisah untuk setiap dokumen secara terpisah guna mengklasifikasikannya.

Pemisah mengidentifikasi batas halaman, tetapi tidak benar-benar memisahkan dokumen input untuk Anda. SDK Document AI Toolbox menyediakan fungsi utilitas yang dapat memisahkan dokumen input berdasarkan output dari prosesor pemisah.

Jenis dokumen yang diidentifikasi

[1] Parser yang sesuai untuk formulir ini tidak mendukung jenis dokumen ini. Artinya, pemisah dapat mengidentifikasi dan mengklasifikasikan dokumen jenis ini, tetapi Document AI tidak menyediakan parser untuk mengekstrak informasi.

Contoh output

Prosesor Contoh output

Contoh kode

Pemisah mengidentifikasi batas halaman, tetapi tidak benar-benar memisahkan dokumen input untuk Anda. Anda dapat menggunakan Toolbox Document AI untuk memisahkan file PDF secara fisik menggunakan batas halaman. Contoh kode berikut mencetak rentang halaman tanpa membagi PDF:

Java

Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Java Document AI.

Untuk melakukan autentikasi ke Document AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


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);

      // Read the file.
      byte[] imageFileData = Files.readAllBytes(Paths.get(filePath));

      // Convert the image data to a Buffer and base64 encode it.
      ByteString content = ByteString.copyFrom(imageFileData);

      RawDocument document =
          RawDocument.newBuilder().setContent(content).setMimeType("application/pdf").build();

      // Configure the process request.
      ProcessRequest request =
          ProcessRequest.newBuilder().setName(name).setRawDocument(document).build();

      // Recognizes text entities in the PDF document
      ProcessResponse result = client.processDocument(request);
      Document documentResponse = result.getDocument();

      System.out.println("Document processing complete.");

      // Read the splitter output from the document splitter processor:
      // https://cloud.google.com/document-ai/docs/processors-list#processor_doc-splitter
      // This processor only provides text for the document and information on how
      // to split the document on logical boundaries. To identify and extract text,
      // form elements, and entities please see other processors like the OCR, form,
      // and specalized processors.
      List<Document.Entity> entities = documentResponse.getEntitiesList();
      System.out.printf("Found %d subdocuments:\n", entities.size());
      for (Document.Entity entity : entities) {
        float entityConfidence = entity.getConfidence();
        String pagesRangeText = pageRefsToString(entity.getPageAnchor().getPageRefsList());
        String subdocumentType = entity.getType();
        if (subdocumentType.isEmpty()) {
          System.out.printf(
              "%.2f%% confident that %s a subdocument.\n", entityConfidence * 100, pagesRangeText);
        } else {
          System.