DocumentAnalysisClient class

Klien untuk berinteraksi dengan fitur analisis layanan Form Recognizer.

Contoh:

Layanan Form Recognizer dan klien mendukung dua sarana autentikasi:

Azure Active Directory

import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new DocumentAnalysisClient(endpoint, credential);

Kunci API (Kunci Langganan)

import { DocumentAnalysisClient, AzureKeyCredential } from "@azure/ai-form-recognizer";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new DocumentAnalysisClient(endpoint, credential);

Konstruktor

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Membuat DocumentAnalysisClient instans dari titik akhir sumber daya dan kunci API statis (KeyCredential),

Contoh:

import { DocumentAnalysisClient, AzureKeyCredential } from "@azure/ai-form-recognizer";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new DocumentAnalysisClient(endpoint, credential);
DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

Buat DocumentAnalysisClient instans dari titik akhir sumber daya dan Azure Identity TokenCredential.

@azure/identity Lihat paket untuk informasi selengkapnya tentang mengautentikasi dengan Azure Active Directory.

Contoh:

import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new DocumentAnalysisClient(endpoint, credential);

Metode

beginAnalyzeDocument(string, FormRecognizerRequestBody, AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>)

Ekstrak data dari input menggunakan model yang diberikan oleh ID uniknya.

Operasi ini mendukung model kustom serta bawaan. Misalnya, untuk menggunakan model faktur bawaan, berikan ID model "prebuilt-invoice", atau untuk menggunakan model tata letak bawaan yang lebih sederhana, berikan ID model "prebuilt-layout".

Bidang yang dihasilkan dalam AnalyzeResult bergantung pada model yang digunakan untuk analisis, dan nilai dalam bidang dokumen yang diekstrak bergantung pada jenis dokumen dalam model (jika ada) dan skema bidang yang sesuai.

Contoh

Metode ini mendukung badan permintaan yang dapat dialirkan (FormRecognizerRequestBody) seperti objek Node.JS ReadableStream , browser Blob, dan ArrayBuffers. Isi isi akan diunggah ke layanan untuk dianalisis.

import * as fs from "fs";

const file = fs.createReadStream("path/to/receipt.pdf");

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
const poller = await client.beginAnalyzeDocument("prebuilt-receipt", file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)
  entities, // extracted entities in the input's content, which are categorized (ex. "Location" or "Organization")
  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
// documentation for information about the document types and field schemas within a model, or use the `getModel`
// operation to view this information programmatically.
console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
beginAnalyzeDocument<Result>(DocumentModel<Result>, FormRecognizerRequestBody, AnalyzeDocumentOptions<Result>)

Ekstrak data dari input menggunakan model yang memiliki skema dokumen yang dikenal dan diketik dengan kuat ( DocumentModel).

Bidang yang diproduksi tergantung AnalyzeResult pada model yang digunakan untuk analisis. Dalam TypeScript, jenis hasil untuk metode ini kelebihan beban disimpulkan dari jenis input DocumentModel.

Contoh

Metode ini mendukung badan permintaan yang dapat dialirkan (FormRecognizerRequestBody) seperti objek Node.JS ReadableStream , browser Blob, dan ArrayBuffers. Isi isi akan diunggah ke layanan untuk dianalisis.

Jika input yang diberikan adalah string, input akan diperlakukan sebagai URL ke lokasi dokumen yang akan dianalisis. Lihat metode beginAnalyzeDocumentFromUrl untuk informasi selengkapnya. Penggunaan metode tersebut lebih disukai saat menggunakan URL, dan dukungan URL hanya disediakan dalam metode ini untuk kompatibilitas mundur.

import * as fs from "fs";

// See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
// DocumentModels for known prebuilts.
import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";

const file = fs.createReadStream("path/to/receipt.pdf");

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model.
const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
// string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
console.log("The type of this receipt is:", receipt.receiptType?.value);
beginAnalyzeDocumentFromUrl(string, string, AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>)

Ekstrak data dari input menggunakan model yang diberikan oleh ID uniknya.

Operasi ini mendukung model kustom serta bawaan. Misalnya, untuk menggunakan model faktur bawaan, berikan ID model "prebuilt-invoice", atau untuk menggunakan model tata letak bawaan yang lebih sederhana, berikan ID model "prebuilt-layout".

Bidang yang dihasilkan dalam AnalyzeResult bergantung pada model yang digunakan untuk analisis, dan nilai dalam bidang dokumen yang diekstrak bergantung pada jenis dokumen dalam model (jika ada) dan skema bidang yang sesuai.

Contoh

Metode ini mendukung ekstraksi data dari file di URL tertentu. Layanan Form Recognizer akan mencoba mengunduh file menggunakan URL yang dikirimkan, sehingga URL harus dapat diakses dari internet publik. Misalnya, token SAS dapat digunakan untuk memberikan akses baca ke blob di Azure Storage, dan layanan akan menggunakan URL yang dikodekan SAS untuk meminta file.

// the URL must be publicly accessible
const url = "<receipt document url>";

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
const poller = await client.beginAnalyzeDocument("prebuilt-receipt", url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
// documentation for information about the document types and field schemas within a model, or use the `getModel`
// operation to view this information programmatically.
console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
beginAnalyzeDocumentFromUrl<Result>(DocumentModel<Result>, string, AnalyzeDocumentOptions<Result>)

Ekstrak data dari input menggunakan model yang memiliki skema dokumen yang dikenal dan diketik dengan kuat ( DocumentModel).

Bidang yang diproduksi tergantung AnalyzeResult pada model yang digunakan untuk analisis. Dalam TypeScript, jenis hasil untuk metode ini kelebihan beban disimpulkan dari jenis input DocumentModel.

Contoh

Metode ini mendukung ekstraksi data dari file di URL tertentu. Layanan Form Recognizer akan mencoba mengunduh file menggunakan URL yang dikirimkan, sehingga URL harus dapat diakses dari internet publik. Misalnya, token SAS dapat digunakan untuk memberikan akses baca ke blob di Azure Storage, dan layanan akan menggunakan URL yang dikodekan SAS untuk meminta file.

// See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
// DocumentModels for known prebuilts.
import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";

// the URL must be publicly accessible
const url = "<receipt document url>";

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model.
const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
// string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
console.log("The type of this receipt is:", receipt.receiptType?.value);
beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

Mengklasifikasikan dokumen menggunakan pengklasifikasi kustom yang diberikan oleh ID-nya.

Metode ini menghasilkan operasi jangka panjang (poller) yang pada akhirnya akan menghasilkan AnalyzeResult. Ini adalah jenis yang sama dengan beginAnalyzeDocument dan beginAnalyzeDocumentFromUrl, tetapi hasilnya hanya akan berisi subset kecil dari bidangnya. Hanya bidang dan pages bidang yang documents akan diisi, dan hanya informasi halaman minimal yang akan dikembalikan. Bidang documents akan berisi informasi tentang semua dokumen yang diidentifikasi dan yang diklasifikasikan docType sebagai.

Contoh

Metode ini mendukung badan permintaan yang dapat dialirkan (FormRecognizerRequestBody) seperti objek Node.JS ReadableStream , browser Blob, dan ArrayBuffers. Isi isi akan diunggah ke layanan untuk dianalisis.

import * as fs from "fs";

const file = fs.createReadStream("path/to/file.pdf");

const poller = await client.beginClassifyDocument("<classifier ID>", file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain only basic information for classifiers
  documents // extracted documents and their types
} = await poller.pollUntilDone();

// We'll print the documents and their types
for (const { docType } of documents) {
  console.log("The type of this document is:", docType);
}
beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

Mengklasifikasikan dokumen dari URL menggunakan pengklasifikasi kustom yang diberikan oleh ID-nya.

Metode ini menghasilkan operasi jangka panjang (poller) yang pada akhirnya akan menghasilkan AnalyzeResult. Ini adalah jenis yang sama dengan beginAnalyzeDocument dan beginAnalyzeDocumentFromUrl, tetapi hasilnya hanya akan berisi subset kecil dari bidangnya. Hanya bidang dan pages bidang yang documents akan diisi, dan hanya informasi halaman minimal yang akan dikembalikan. Bidang documents akan berisi informasi tentang semua dokumen yang diidentifikasi dan yang diklasifikasikan docType sebagai.

Contoh

Metode ini mendukung ekstraksi data dari file di URL tertentu. Layanan Form Recognizer akan mencoba mengunduh file menggunakan URL yang dikirimkan, sehingga URL harus dapat diakses dari internet publik. Misalnya, token SAS dapat digunakan untuk memberikan akses baca ke blob di Azure Storage, dan layanan akan menggunakan URL yang dikodekan SAS untuk meminta file.

// the URL must be publicly accessible
const url = "<file url>";

const poller = await client.beginClassifyDocument("<classifier ID>", url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain only basic information for classifiers
  documents // extracted documents and their types
} = await poller.pollUntilDone();

// We'll print the documents and their types
for (const { docType } of documents) {
  console.log("The type of this document is:", docType);
}

Detail Konstruktor

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Membuat DocumentAnalysisClient instans dari titik akhir sumber daya dan kunci API statis (KeyCredential),

Contoh:

import { DocumentAnalysisClient, AzureKeyCredential } from "@azure/ai-form-recognizer";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new DocumentAnalysisClient(endpoint, credential);
new DocumentAnalysisClient(endpoint: string, credential: KeyCredential, options?: DocumentAnalysisClientOptions)

Parameter

endpoint

string

URL titik akhir instans Azure Cognitive Services

credential
KeyCredential

KeyCredential yang berisi kunci langganan instans Cognitive Services

options
DocumentAnalysisClientOptions

pengaturan opsional untuk mengonfigurasi semua metode di klien

DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

Buat DocumentAnalysisClient instans dari titik akhir sumber daya dan Azure Identity TokenCredential.

@azure/identity Lihat paket untuk informasi selengkapnya tentang mengautentikasi dengan Azure Active Directory.

Contoh:

import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new DocumentAnalysisClient(endpoint, credential);
new DocumentAnalysisClient(endpoint: string, credential: TokenCredential, options?: DocumentAnalysisClientOptions)

Parameter

endpoint

string

URL titik akhir instans Azure Cognitive Services

credential
TokenCredential

instans TokenCredential dari @azure/identity paket

options
DocumentAnalysisClientOptions

pengaturan opsional untuk mengonfigurasi semua metode di klien

Detail Metode

beginAnalyzeDocument(string, FormRecognizerRequestBody, AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>)

Ekstrak data dari input menggunakan model yang diberikan oleh ID uniknya.

Operasi ini mendukung model kustom serta bawaan. Misalnya, untuk menggunakan model faktur bawaan, berikan ID model "prebuilt-invoice", atau untuk menggunakan model tata letak bawaan yang lebih sederhana, berikan ID model "prebuilt-layout".

Bidang yang dihasilkan dalam AnalyzeResult bergantung pada model yang digunakan untuk analisis, dan nilai dalam bidang dokumen yang diekstrak bergantung pada jenis dokumen dalam model (jika ada) dan skema bidang yang sesuai.

Contoh

Metode ini mendukung badan permintaan yang dapat dialirkan (FormRecognizerRequestBody) seperti objek Node.JS ReadableStream , browser Blob, dan ArrayBuffers. Isi isi akan diunggah ke layanan untuk dianalisis.

import * as fs from "fs";

const file = fs.createReadStream("path/to/receipt.pdf");

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
const poller = await client.beginAnalyzeDocument("prebuilt-receipt", file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)
  entities, // extracted entities in the input's content, which are categorized (ex. "Location" or "Organization")
  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
// documentation for information about the document types and field schemas within a model, or use the `getModel`
// operation to view this information programmatically.
console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
function beginAnalyzeDocument(modelId: string, document: FormRecognizerRequestBody, options?: AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>): Promise<AnalysisPoller<AnalyzeResult<AnalyzedDocument>>>

Parameter

modelId

string

ID unik (nama) model dalam sumber daya klien ini

document
FormRecognizerRequestBody

FormRecognizerRequestBody yang akan diunggah dengan permintaan

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

pengaturan opsional untuk operasi analisis dan poller

Mengembalikan

operasi jangka panjang (poller) yang pada akhirnya akan menghasilkan AnalyzeResult

beginAnalyzeDocument<Result>(DocumentModel<Result>, FormRecognizerRequestBody, AnalyzeDocumentOptions<Result>)

Ekstrak data dari input menggunakan model yang memiliki skema dokumen yang dikenal dan diketik dengan kuat ( DocumentModel).

Bidang yang diproduksi tergantung AnalyzeResult pada model yang digunakan untuk analisis. Dalam TypeScript, jenis hasil untuk metode ini kelebihan beban disimpulkan dari jenis input DocumentModel.

Contoh

Metode ini mendukung badan permintaan yang dapat dialirkan (FormRecognizerRequestBody) seperti objek Node.JS ReadableStream , browser Blob, dan ArrayBuffers. Isi isi akan diunggah ke layanan untuk dianalisis.

Jika input yang diberikan adalah string, input akan diperlakukan sebagai URL ke lokasi dokumen yang akan dianalisis. Lihat metode beginAnalyzeDocumentFromUrl untuk informasi selengkapnya. Penggunaan metode tersebut lebih disukai saat menggunakan URL, dan dukungan URL hanya disediakan dalam metode ini untuk kompatibilitas mundur.

import * as fs from "fs";

// See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
// DocumentModels for known prebuilts.
import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";

const file = fs.createReadStream("path/to/receipt.pdf");

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model.
const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
// string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
console.log("The type of this receipt is:", receipt.receiptType?.value);
function beginAnalyzeDocument<Result>(model: DocumentModel<Result>, document: FormRecognizerRequestBody, options?: AnalyzeDocumentOptions<Result>): Promise<AnalysisPoller<Result>>

Parameter

model

DocumentModel<Result>

DocumentModel yang mewakili model yang akan digunakan untuk analisis dan jenis output yang diharapkan

document
FormRecognizerRequestBody

FormRecognizerRequestBody yang akan diunggah dengan permintaan

options

AnalyzeDocumentOptions<Result>

pengaturan opsional untuk operasi analisis dan poller

Mengembalikan

Promise<AnalysisPoller<Result>>

operasi jangka panjang (poller) yang pada akhirnya akan menghasilkan AnalyzeResult dengan dokumen yang memiliki jenis hasil yang terkait dengan model input

beginAnalyzeDocumentFromUrl(string, string, AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>)

Ekstrak data dari input menggunakan model yang diberikan oleh ID uniknya.

Operasi ini mendukung model kustom serta bawaan. Misalnya, untuk menggunakan model faktur bawaan, berikan ID model "prebuilt-invoice", atau untuk menggunakan model tata letak bawaan yang lebih sederhana, berikan ID model "prebuilt-layout".

Bidang yang dihasilkan dalam AnalyzeResult bergantung pada model yang digunakan untuk analisis, dan nilai dalam bidang dokumen yang diekstrak bergantung pada jenis dokumen dalam model (jika ada) dan skema bidang yang sesuai.

Contoh

Metode ini mendukung ekstraksi data dari file di URL tertentu. Layanan Form Recognizer akan mencoba mengunduh file menggunakan URL yang dikirimkan, sehingga URL harus dapat diakses dari internet publik. Misalnya, token SAS dapat digunakan untuk memberikan akses baca ke blob di Azure Storage, dan layanan akan menggunakan URL yang dikodekan SAS untuk meminta file.

// the URL must be publicly accessible
const url = "<receipt document url>";

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
const poller = await client.beginAnalyzeDocument("prebuilt-receipt", url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
// documentation for information about the document types and field schemas within a model, or use the `getModel`
// operation to view this information programmatically.
console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
function beginAnalyzeDocumentFromUrl(modelId: string, documentUrl: string, options?: AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>): Promise<AnalysisPoller<AnalyzeResult<AnalyzedDocument>>>

Parameter

modelId

string

ID unik (nama) model dalam sumber daya klien ini

documentUrl

string

URL (string) ke dokumen input yang dapat diakses dari internet publik

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

pengaturan opsional untuk operasi analisis dan poller

Mengembalikan

operasi jangka panjang (poller) yang pada akhirnya akan menghasilkan AnalyzeResult

beginAnalyzeDocumentFromUrl<Result>(DocumentModel<Result>, string, AnalyzeDocumentOptions<Result>)

Ekstrak data dari input menggunakan model yang memiliki skema dokumen yang dikenal dan diketik dengan kuat ( DocumentModel).

Bidang yang diproduksi tergantung AnalyzeResult pada model yang digunakan untuk analisis. Dalam TypeScript, jenis hasil untuk metode ini kelebihan beban disimpulkan dari jenis input DocumentModel.

Contoh

Metode ini mendukung ekstraksi data dari file di URL tertentu. Layanan Form Recognizer akan mencoba mengunduh file menggunakan URL yang dikirimkan, sehingga URL harus dapat diakses dari internet publik. Misalnya, token SAS dapat digunakan untuk memberikan akses baca ke blob di Azure Storage, dan layanan akan menggunakan URL yang dikodekan SAS untuk meminta file.

// See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
// DocumentModels for known prebuilts.
import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";

// the URL must be publicly accessible
const url = "<receipt document url>";

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model.
const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
// string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
console.log("The type of this receipt is:", receipt.receiptType?.value);
function beginAnalyzeDocumentFromUrl<Result>(model: DocumentModel<Result>, documentUrl: string, options?: AnalyzeDocumentOptions<Result>): Promise<AnalysisPoller<Result>>

Parameter

model

DocumentModel<Result>

DocumentModel yang mewakili model yang akan digunakan untuk analisis dan jenis output yang diharapkan

documentUrl

string

URL (string) ke dokumen input yang dapat diakses dari internet publik

options

AnalyzeDocumentOptions<Result>

pengaturan opsional untuk operasi analisis dan poller

Mengembalikan

Promise<AnalysisPoller<Result>>

operasi jangka panjang (poller) yang pada akhirnya akan menghasilkan AnalyzeResult

beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

Mengklasifikasikan dokumen menggunakan pengklasifikasi kustom yang diberikan oleh ID-nya.

Metode ini menghasilkan operasi jangka panjang (poller) yang pada akhirnya akan menghasilkan AnalyzeResult. Ini adalah jenis yang sama dengan beginAnalyzeDocument dan beginAnalyzeDocumentFromUrl, tetapi hasilnya hanya akan berisi subset kecil dari bidangnya. Hanya bidang dan pages bidang yang documents akan diisi, dan hanya informasi halaman minimal yang akan dikembalikan. Bidang documents akan berisi informasi tentang semua dokumen yang diidentifikasi dan yang diklasifikasikan docType sebagai.

Contoh

Metode ini mendukung badan permintaan yang dapat dialirkan (FormRecognizerRequestBody) seperti objek Node.JS ReadableStream , browser Blob, dan ArrayBuffers. Isi isi akan diunggah ke layanan untuk dianalisis.

import * as fs from "fs";

const file = fs.createReadStream("path/to/file.pdf");

const poller = await client.beginClassifyDocument("<classifier ID>", file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain only basic information for classifiers
  documents // extracted documents and their types
} = await poller.pollUntilDone();

// We'll print the documents and their types
for (const { docType } of documents) {
  console.log("The type of this document is:", docType);
}
function beginClassifyDocument(classifierId: string, document: FormRecognizerRequestBody, options?: ClassifyDocumentOptions): Promise<AnalysisPoller<AnalyzeResult<AnalyzedDocument>>>

Parameter

classifierId

string

ID pengklasifikasi kustom yang akan digunakan untuk analisis

document
FormRecognizerRequestBody

dokumen yang akan diklasifikasikan

options
ClassifyDocumentOptions

opsi untuk operasi klasifikasi

Mengembalikan

operasi jangka panjang (poller) yang pada akhirnya akan menghasilkan AnalyzeResult

beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

Mengklasifikasikan dokumen dari URL menggunakan pengklasifikasi kustom yang diberikan oleh ID-nya.

Metode ini menghasilkan operasi jangka panjang (poller) yang pada akhirnya akan menghasilkan AnalyzeResult. Ini adalah jenis yang sama dengan beginAnalyzeDocument dan beginAnalyzeDocumentFromUrl, tetapi hasilnya hanya akan berisi subset kecil dari bidangnya. Hanya bidang dan pages bidang yang documents akan diisi, dan hanya informasi halaman minimal yang akan dikembalikan. Bidang documents akan berisi informasi tentang semua dokumen yang diidentifikasi dan yang diklasifikasikan docType sebagai.

Contoh

Metode ini mendukung ekstraksi data dari file di URL tertentu. Layanan Form Recognizer akan mencoba mengunduh file menggunakan URL yang dikirimkan, sehingga URL harus dapat diakses dari internet publik. Misalnya, token SAS dapat digunakan untuk memberikan akses baca ke blob di Azure Storage, dan layanan akan menggunakan URL yang dikodekan SAS untuk meminta file.

// the URL must be publicly accessible
const url = "<file url>";

const poller = await client.beginClassifyDocument("<classifier ID>", url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain only basic information for classifiers
  documents // extracted documents and their types
} = await poller.pollUntilDone();

// We'll print the documents and their types
for (const { docType } of documents) {
  console.log("The type of this document is:", docType);
}
function beginClassifyDocumentFromUrl(classifierId: string, documentUrl: string, options?: ClassifyDocumentOptions): Promise<AnalysisPoller<AnalyzeResult<AnalyzedDocument>>>

Parameter

classifierId

string

ID pengklasifikasi kustom yang akan digunakan untuk analisis

documentUrl

string

URL dokumen yang akan diklasifikasikan

Mengembalikan