Share via


DocumentAnalysisClient class

Un client per l'interazione con le funzionalità di analisi del servizio Riconoscimento modulo.

Esempi:

Il servizio Riconoscimento modulo e i client supportano due metodi di autenticazione:

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

Chiave API (chiave di sottoscrizione)

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

Costruttori

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Creare un'istanza DocumentAnalysisClient da un endpoint della risorsa e una chiave API statica (KeyCredential),

Esempio:

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)

Creare un'istanza DocumentAnalysisClient da un endpoint della risorsa e un'identità TokenCredentialdi Azure.

Per altre informazioni sull'autenticazione con Azure Active Directory, vedere il @azure/identity pacchetto.

Esempio:

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

Metodi

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

Estrarre dati da un input usando un modello specificato dall'ID univoco.

Questa operazione supporta modelli personalizzati e predefiniti. Ad esempio, per usare il modello di fattura predefinito, specificare l'ID modello "precompilt-invoice" o per usare il modello di layout predefinito più semplice, specificare l'ID modello "precompilt-layout".

I campi prodotti nell'oggetto dipendono dal modello utilizzato per l'analisi AnalyzeResult e i valori nei campi dei documenti estratti dipendono dai tipi di documento nel modello (se presenti) e dai relativi schemi di campo.

Esempio

Questo metodo supporta corpi di richiesta trasmessi (FormRecognizerRequestBody), ad esempio oggetti Node.JS ReadableStream , browser Blobe ArrayBuffers. Il contenuto del corpo verrà caricato nel servizio per l'analisi.

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

Estrarre dati da un input usando un modello con uno schema di documento noto fortemente tipizzato ( DocumentModel).

I campi prodotti nell'oggetto dipendono dal modello utilizzato per l'analisi AnalyzeResult . In TypeScript, il tipo del risultato per questo overload del metodo viene dedotto dal tipo dell'input DocumentModel.

Esempio

Questo metodo supporta corpi di richiesta trasmessi (FormRecognizerRequestBody), ad esempio oggetti Node.JS ReadableStream , browser Blobe ArrayBuffers. Il contenuto del corpo verrà caricato nel servizio per l'analisi.

Se l'input fornito è una stringa, verrà considerato come URL per la posizione di un documento da analizzare. Per altre informazioni, vedere il metodo beginAnalyzeDocumentFromUrl . L'uso di questo metodo è preferibile quando si usano GLI URL e il supporto degli URL viene fornito solo in questo metodo per garantire la compatibilità con le versioni precedenti.

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

Estrarre dati da un input usando un modello specificato dall'ID univoco.

Questa operazione supporta modelli personalizzati e predefiniti. Ad esempio, per usare il modello di fattura predefinito, specificare l'ID modello "precompilt-invoice" o per usare il modello di layout predefinito più semplice, specificare l'ID modello "precompilt-layout".

I campi prodotti nell'oggetto dipendono dal modello utilizzato per l'analisi AnalyzeResult e i valori nei campi dei documenti estratti dipendono dai tipi di documento nel modello (se presenti) e dai relativi schemi di campo.

Esempio

Questo metodo supporta l'estrazione di dati da un file in un determinato URL. Il servizio Riconoscimento modulo tenterà di scaricare un file usando l'URL inviato, quindi l'URL deve essere accessibile dalla rete Internet pubblica. Ad esempio, è possibile usare un token di firma di accesso condiviso per concedere l'accesso in lettura a un BLOB in Archiviazione di Azure e il servizio userà l'URL con codifica sas per richiedere il 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>)

Estrarre dati da un input usando un modello con uno schema di documento noto fortemente tipizzato ( DocumentModel).

I campi prodotti nell'oggetto dipendono dal modello utilizzato per l'analisi AnalyzeResult . In TypeScript, il tipo del risultato per questo overload del metodo viene dedotto dal tipo dell'input DocumentModel.

Esempio

Questo metodo supporta l'estrazione di dati da un file in un determinato URL. Il servizio Riconoscimento modulo tenterà di scaricare un file usando l'URL inviato, quindi l'URL deve essere accessibile dalla rete Internet pubblica. Ad esempio, è possibile usare un token di firma di accesso condiviso per concedere l'accesso in lettura a un BLOB in Archiviazione di Azure e il servizio userà l'URL con codifica sas per richiedere il 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)

Classificare un documento usando un classificatore personalizzato specificato dal relativo ID.

Questo metodo produce un'operazione a esecuzione prolungata (poller) che genererà infine un oggetto AnalyzeResult. Si tratta dello stesso tipo di beginAnalyzeDocument e beginAnalyzeDocumentFromUrl, ma il risultato conterrà solo un piccolo subset dei relativi campi. Verrà popolato solo il campo e pages il documents campo e verranno restituite solo informazioni minime sulla pagina. Il documents campo conterrà informazioni su tutti i documenti identificati e sull'oggetto docType classificato come .

Esempio

Questo metodo supporta corpi di richiesta trasmessi (FormRecognizerRequestBody), ad esempio oggetti Node.JS ReadableStream , browser Blobe ArrayBuffers. Il contenuto del corpo verrà caricato nel servizio per l'analisi.

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)

Classificare un documento da un URL usando un classificatore personalizzato specificato dal relativo ID.

Questo metodo produce un'operazione a esecuzione prolungata (poller) che genererà infine un oggetto AnalyzeResult. Si tratta dello stesso tipo di beginAnalyzeDocument e beginAnalyzeDocumentFromUrl, ma il risultato conterrà solo un piccolo subset dei relativi campi. Verrà popolato solo il campo e pages il documents campo e verranno restituite solo informazioni minime sulla pagina. Il documents campo conterrà informazioni su tutti i documenti identificati e sull'oggetto docType classificato come .

Esempio

Questo metodo supporta l'estrazione di dati da un file in un determinato URL. Il servizio Riconoscimento modulo tenterà di scaricare un file usando l'URL inviato, quindi l'URL deve essere accessibile dalla rete Internet pubblica. Ad esempio, è possibile usare un token di firma di accesso condiviso per concedere l'accesso in lettura a un BLOB in Archiviazione di Azure e il servizio userà l'URL con codifica sas per richiedere il 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);
}

Dettagli costruttore

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Creare un'istanza DocumentAnalysisClient da un endpoint della risorsa e una chiave API statica (KeyCredential),

Esempio:

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)

Parametri

endpoint

string

URL dell'endpoint di un'istanza di Servizi cognitivi di Azure

credential
KeyCredential

KeyCredential contenente la chiave di sottoscrizione dell'istanza di Servizi cognitivi

options
DocumentAnalysisClientOptions

impostazioni facoltative per la configurazione di tutti i metodi nel client

DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

Creare un'istanza DocumentAnalysisClient da un endpoint della risorsa e un'identità TokenCredentialdi Azure.

Per altre informazioni sull'autenticazione con Azure Active Directory, vedere il @azure/identity pacchetto.

Esempio:

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)

Parametri

endpoint

string

URL dell'endpoint di un'istanza di Servizi cognitivi di Azure

credential
TokenCredential

un'istanza tokenCredential dal @azure/identity pacchetto

options
DocumentAnalysisClientOptions

impostazioni facoltative per la configurazione di tutti i metodi nel client

Dettagli metodo

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

Estrarre dati da un input usando un modello specificato dall'ID univoco.

Questa operazione supporta modelli personalizzati e predefiniti. Ad esempio, per usare il modello di fattura predefinito, specificare l'ID modello "precompilt-invoice" o per usare il modello di layout predefinito più semplice, specificare l'ID modello "precompilt-layout".

I campi prodotti nell'oggetto dipendono dal modello utilizzato per l'analisi AnalyzeResult e i valori nei campi dei documenti estratti dipendono dai tipi di documento nel modello (se presenti) e dai relativi schemi di campo.

Esempio

Questo metodo supporta corpi di richiesta trasmessi (FormRecognizerRequestBody), ad esempio oggetti Node.JS ReadableStream , browser Blobe ArrayBuffers. Il contenuto del corpo verrà caricato nel servizio per l'analisi.

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

Parametri

modelId

string

ID univoco (nome) del modello all'interno della risorsa del client

document
FormRecognizerRequestBody

FormRecognizerRequestBody che verrà caricato con la richiesta

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

impostazioni facoltative per l'operazione di analisi e il poller

Restituisce

un'operazione a esecuzione prolungata (poller) che alla fine produrrà un AnalyzeResult

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

Estrarre dati da un input usando un modello con uno schema di documento noto fortemente tipizzato ( DocumentModel).

I campi prodotti nell'oggetto dipendono dal modello utilizzato per l'analisi AnalyzeResult . In TypeScript, il tipo del risultato per questo overload del metodo viene dedotto dal tipo dell'input DocumentModel.

Esempio

Questo metodo supporta corpi di richiesta trasmessi (FormRecognizerRequestBody), ad esempio oggetti Node.JS ReadableStream , browser Blobe ArrayBuffers. Il contenuto del corpo verrà caricato nel servizio per l'analisi.

Se l'input fornito è una stringa, verrà considerato come URL per la posizione di un documento da analizzare. Per altre informazioni, vedere il metodo beginAnalyzeDocumentFromUrl . L'uso di questo metodo è preferibile quando si usano GLI URL e il supporto degli URL viene fornito solo in questo metodo per garantire la compatibilità con le versioni precedenti.

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

Parametri

model

DocumentModel<Result>

DocumentModel che rappresenta il modello da utilizzare per l'analisi e il tipo di output previsto

document
FormRecognizerRequestBody

FormRecognizerRequestBody che verrà caricato con la richiesta

options

AnalyzeDocumentOptions<Result>

impostazioni facoltative per l'operazione di analisi e il poller

Restituisce

Promise<AnalysisPoller<Result>>

operazione a esecuzione prolungata (poller) che genererà alla fine un AnalyzeResult oggetto con documenti con il tipo di risultato associato al modello di input

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

Estrarre dati da un input usando un modello specificato dall'ID univoco.

Questa operazione supporta modelli personalizzati e predefiniti. Ad esempio, per usare il modello di fattura predefinito, specificare l'ID modello "precompilt-invoice" o per usare il modello di layout predefinito più semplice, specificare l'ID modello "precompilt-layout".

I campi prodotti nell'oggetto dipendono dal modello utilizzato per l'analisi AnalyzeResult e i valori nei campi dei documenti estratti dipendono dai tipi di documento nel modello (se presenti) e dai relativi schemi di campo.

Esempio

Questo metodo supporta l'estrazione di dati da un file in un determinato URL. Il servizio Riconoscimento modulo tenterà di scaricare un file usando l'URL inviato, quindi l'URL deve essere accessibile dalla rete Internet pubblica. Ad esempio, è possibile usare un token di firma di accesso condiviso per concedere l'accesso in lettura a un BLOB in Archiviazione di Azure e il servizio userà l'URL con codifica sas per richiedere il 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>>>

Parametri

modelId

string

ID univoco (nome) del modello all'interno della risorsa del client

documentUrl

string

URL (stringa) a un documento di input accessibile dalla rete Internet pubblica

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

impostazioni facoltative per l'operazione di analisi e il poller

Restituisce

un'operazione a esecuzione prolungata (poller) che alla fine produrrà un AnalyzeResult

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

Estrarre dati da un input usando un modello con uno schema di documento noto fortemente tipizzato ( DocumentModel).

I campi prodotti nell'oggetto dipendono dal modello utilizzato per l'analisi AnalyzeResult . In TypeScript, il tipo del risultato per questo overload del metodo viene dedotto dal tipo dell'input DocumentModel.

Esempio

Questo metodo supporta l'estrazione di dati da un file in un determinato URL. Il servizio Riconoscimento modulo tenterà di scaricare un file usando l'URL inviato, quindi l'URL deve essere accessibile dalla rete Internet pubblica. Ad esempio, è possibile usare un token di firma di accesso condiviso per concedere l'accesso in lettura a un BLOB in Archiviazione di Azure e il servizio userà l'URL con codifica sas per richiedere il 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>>

Parametri

model

DocumentModel<Result>

DocumentModel che rappresenta il modello da utilizzare per l'analisi e il tipo di output previsto

documentUrl

string

URL (stringa) a un documento di input accessibile dalla rete Internet pubblica

options

AnalyzeDocumentOptions<Result>

impostazioni facoltative per l'operazione di analisi e il poller

Restituisce

Promise<AnalysisPoller<Result>>

un'operazione a esecuzione prolungata (poller) che alla fine produrrà un AnalyzeResult

beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

Classificare un documento usando un classificatore personalizzato specificato dal relativo ID.

Questo metodo produce un'operazione a esecuzione prolungata (poller) che genererà infine un oggetto AnalyzeResult. Si tratta dello stesso tipo di beginAnalyzeDocument e beginAnalyzeDocumentFromUrl, ma il risultato conterrà solo un piccolo subset dei relativi campi. Verrà popolato solo il campo e pages il documents campo e verranno restituite solo informazioni minime sulla pagina. Il documents campo conterrà informazioni su tutti i documenti identificati e sull'oggetto docType classificato come .

Esempio

Questo metodo supporta corpi di richiesta trasmessi (FormRecognizerRequestBody), ad esempio oggetti Node.JS ReadableStream , browser Blobe ArrayBuffers. Il contenuto del corpo verrà caricato nel servizio per l'analisi.

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

Parametri

classifierId

string

ID del classificatore personalizzato da usare per l'analisi

document
FormRecognizerRequestBody

documento da classificare

options
ClassifyDocumentOptions

opzioni per l'operazione di classificazione

Restituisce

un'operazione a esecuzione prolungata (poller) che alla fine produrrà un AnalyzeResult

beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

Classificare un documento da un URL usando un classificatore personalizzato specificato dal relativo ID.

Questo metodo produce un'operazione a esecuzione prolungata (poller) che genererà infine un oggetto AnalyzeResult. Si tratta dello stesso tipo di beginAnalyzeDocument e beginAnalyzeDocumentFromUrl, ma il risultato conterrà solo un piccolo subset dei relativi campi. Verrà popolato solo il campo e pages il documents campo e verranno restituite solo informazioni minime sulla pagina. Il documents campo conterrà informazioni su tutti i documenti identificati e sull'oggetto docType classificato come .

Esempio

Questo metodo supporta l'estrazione di dati da un file in un determinato URL. Il servizio Riconoscimento modulo tenterà di scaricare un file usando l'URL inviato, quindi l'URL deve essere accessibile dalla rete Internet pubblica. Ad esempio, è possibile usare un token di firma di accesso condiviso per concedere l'accesso in lettura a un BLOB in Archiviazione di Azure e il servizio userà l'URL con codifica sas per richiedere il 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>>>

Parametri

classifierId

string

ID del classificatore personalizzato da usare per l'analisi

documentUrl

string

URL del documento da classificare

Restituisce