DocumentAnalysisClient class

Ein Client für die Interaktion mit den Analysefeatures des Formularerkennung-Diensts.

Beispiele:

Der Formularerkennung-Dienst und Clients unterstützen zwei Methoden der Authentifizierung:

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

API-Schlüssel (Abonnementschlüssel)

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

Konstruktoren

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Erstellen eines DocumentAnalysisClient instance aus einem Ressourcenendpunkt und einem statischen API-Schlüssel (KeyCredential),

Beispiel:

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)

Erstellen Sie eine DocumentAnalysisClient instance aus einem Ressourcenendpunkt und eine Azure Identity TokenCredential.

Weitere Informationen zur Authentifizierung mit Azure Active Directory finden Sie im @azure/identity Paket.

Beispiel:

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

Methoden

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

Extrahieren Sie Daten aus einer Eingabe mithilfe eines Modells, das durch die eindeutige ID angegeben wird.

Dieser Vorgang unterstützt sowohl benutzerdefinierte als auch vordefinierte Modelle. Um z. B. das vordefinierte Rechnungsmodell zu verwenden, geben Sie die Modell-ID "prebuilt-invoice" an, oder um das einfachere vordefinierte Layoutmodell zu verwenden, geben Sie die Modell-ID "prebuilt-layout" an.

Die in erzeugten AnalyzeResult Felder hängen vom Modell ab, das für die Analyse verwendet wird, und die Werte in den Feldern aller extrahierten Dokumente hängen von den Dokumenttypen im Modell (sofern vorhanden) und den entsprechenden Feldschemas ab.

Beispiele

Diese Methode unterstützt streambare Anforderungstexte (FormRecognizerRequestBody), z. B. Node.JS-Objekte ReadableStream , Browser Blobs und ArrayBuffers. Der Inhalt des Texts wird zur Analyse in den Dienst hochgeladen.

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

Extrahieren sie Daten aus einer Eingabe mithilfe eines Modells, das über ein bekanntes, stark typisiertes Dokumentschema ( documentModel) verfügt.

Die im erzeugten AnalyzeResult Felder hängen vom Modell ab, das für die Analyse verwendet wird. In TypeScript wird der Typ des Ergebnisses für diese Methodenüberladung vom Typ der Eingabe DocumentModelabgeleitet.

Beispiele

Diese Methode unterstützt streambare Anforderungstexte (FormRecognizerRequestBody), z. B. Node.JS-Objekte ReadableStream , Browser Blobs und ArrayBuffers. Der Inhalt des Texts wird zur Analyse in den Dienst hochgeladen.

Wenn es sich bei der bereitgestellten Eingabe um eine Zeichenfolge handelt, wird sie als URL zum Speicherort eines zu analysierenden Dokuments behandelt. Weitere Informationen finden Sie unter der beginAnalyzeDocumentFromUrl-Methode . Die Verwendung dieser Methode wird bei verwendung von URLs bevorzugt, und DIE URL-Unterstützung wird nur in dieser Methode aus Gründen der Abwärtskompatibilität bereitgestellt.

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

Extrahieren Sie Daten aus einer Eingabe mithilfe eines Modells, das durch die eindeutige ID angegeben wird.

Dieser Vorgang unterstützt sowohl benutzerdefinierte als auch vordefinierte Modelle. Um z. B. das vordefinierte Rechnungsmodell zu verwenden, geben Sie die Modell-ID "prebuilt-invoice" an, oder um das einfachere vordefinierte Layoutmodell zu verwenden, geben Sie die Modell-ID "prebuilt-layout" an.

Die in erzeugten AnalyzeResult Felder hängen vom Modell ab, das für die Analyse verwendet wird, und die Werte in den Feldern aller extrahierten Dokumente hängen von den Dokumenttypen im Modell (sofern vorhanden) und den entsprechenden Feldschemas ab.

Beispiele

Diese Methode unterstützt das Extrahieren von Daten aus einer Datei unter einer bestimmten URL. Der Formularerkennung-Dienst versucht, eine Datei mithilfe der übermittelten URL herunterzuladen, sodass die URL über das öffentliche Internet zugänglich sein muss. Beispielsweise kann ein SAS-Token verwendet werden, um Lesezugriff auf ein Blob in Azure Storage zu gewähren, und der Dienst verwendet die SAS-codierte URL, um die Datei anzufordern.

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

Extrahieren sie Daten aus einer Eingabe mithilfe eines Modells, das über ein bekanntes, stark typisiertes Dokumentschema ( documentModel) verfügt.

Die im erzeugten AnalyzeResult Felder hängen vom Modell ab, das für die Analyse verwendet wird. In TypeScript wird der Typ des Ergebnisses für diese Methodenüberladung vom Typ der Eingabe DocumentModelabgeleitet.

Beispiele

Diese Methode unterstützt das Extrahieren von Daten aus einer Datei unter einer bestimmten URL. Der Formularerkennung-Dienst versucht, eine Datei mithilfe der übermittelten URL herunterzuladen, sodass die URL über das öffentliche Internet zugänglich sein muss. Beispielsweise kann ein SAS-Token verwendet werden, um Lesezugriff auf ein Blob in Azure Storage zu gewähren, und der Dienst verwendet die SAS-codierte URL, um die Datei anzufordern.

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

Klassifizieren eines Dokuments mithilfe eines benutzerdefinierten Klassifizierers, der durch seine ID angegeben wird.

Diese Methode erzeugt einen zeitintensiven Vorgang (Poller), der schließlich einen AnalyzeResulterzeugt. Dies ist derselbe Typ wie beginAnalyzeDocument und beginAnalyzeDocumentFromUrl, aber das Ergebnis enthält nur eine kleine Teilmenge seiner Felder. Nur das Feld und pages das documents Feld werden aufgefüllt, und es werden nur minimale Seiteninformationen zurückgegeben. Das documents Feld enthält Informationen über alle identifizierten Dokumente und die docType , als die sie klassifiziert wurden.

Beispiel

Diese Methode unterstützt streambare Anforderungstexte (FormRecognizerRequestBody), z. B. Node.JS-Objekte ReadableStream , Browser Blobs und ArrayBuffers. Der Inhalt des Texts wird zur Analyse in den Dienst hochgeladen.

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)

Klassifizieren Sie ein Dokument aus einer URL mithilfe eines benutzerdefinierten Klassifizierers, der durch seine ID angegeben wird.

Diese Methode erzeugt einen zeitintensiven Vorgang (Poller), der schließlich einen AnalyzeResulterzeugt. Dies ist derselbe Typ wie beginAnalyzeDocument und beginAnalyzeDocumentFromUrl, aber das Ergebnis enthält nur eine kleine Teilmenge seiner Felder. Nur das Feld und pages das documents Feld werden aufgefüllt, und es werden nur minimale Seiteninformationen zurückgegeben. Das documents Feld enthält Informationen über alle identifizierten Dokumente und die docType , als die sie klassifiziert wurden.

Beispiel

Diese Methode unterstützt das Extrahieren von Daten aus einer Datei unter einer bestimmten URL. Der Formularerkennung-Dienst versucht, eine Datei mithilfe der übermittelten URL herunterzuladen, sodass die URL über das öffentliche Internet zugänglich sein muss. Beispielsweise kann ein SAS-Token verwendet werden, um Lesezugriff auf ein Blob in Azure Storage zu gewähren, und der Dienst verwendet die SAS-codierte URL, um die Datei anzufordern.

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

Details zum Konstruktor

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Erstellen eines DocumentAnalysisClient instance aus einem Ressourcenendpunkt und einem statischen API-Schlüssel (KeyCredential),

Beispiel:

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

Die Endpunkt-URL einer Azure Cognitive Services-instance

credential
KeyCredential

KeyCredential mit dem Cognitive Services-instance-Abonnementschlüssel

options
DocumentAnalysisClientOptions

optionale Einstellungen zum Konfigurieren aller Methoden im Client

DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

Erstellen Sie eine DocumentAnalysisClient instance aus einem Ressourcenendpunkt und eine Azure Identity TokenCredential.

Weitere Informationen zur Authentifizierung mit Azure Active Directory finden Sie im @azure/identity Paket.

Beispiel:

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

Die Endpunkt-URL einer Azure Cognitive Services-instance

credential
TokenCredential

ein tokenCredential-instance aus dem @azure/identity Paket

options
DocumentAnalysisClientOptions

optionale Einstellungen zum Konfigurieren aller Methoden im Client

Details zur Methode

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

Extrahieren Sie Daten aus einer Eingabe mithilfe eines Modells, das durch die eindeutige ID angegeben wird.

Dieser Vorgang unterstützt sowohl benutzerdefinierte als auch vordefinierte Modelle. Um z. B. das vordefinierte Rechnungsmodell zu verwenden, geben Sie die Modell-ID "prebuilt-invoice" an, oder um das einfachere vordefinierte Layoutmodell zu verwenden, geben Sie die Modell-ID "prebuilt-layout" an.

Die in erzeugten AnalyzeResult Felder hängen vom Modell ab, das für die Analyse verwendet wird, und die Werte in den Feldern aller extrahierten Dokumente hängen von den Dokumenttypen im Modell (sofern vorhanden) und den entsprechenden Feldschemas ab.

Beispiele

Diese Methode unterstützt streambare Anforderungstexte (FormRecognizerRequestBody), z. B. Node.JS-Objekte ReadableStream , Browser Blobs und ArrayBuffers. Der Inhalt des Texts wird zur Analyse in den Dienst hochgeladen.

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

die eindeutige ID (Name) des Modells innerhalb der Ressource dieses Clients

document
FormRecognizerRequestBody

ein FormRecognizerRequestBody , der mit der Anforderung hochgeladen wird

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

optionale Einstellungen für den Analysevorgang und den Poller

Gibt zurück

Ein lang andauernder Vorgang (Poller), der schließlich eine AnalyzeResult

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

Extrahieren sie Daten aus einer Eingabe mithilfe eines Modells, das über ein bekanntes, stark typisiertes Dokumentschema ( documentModel) verfügt.

Die im erzeugten AnalyzeResult Felder hängen vom Modell ab, das für die Analyse verwendet wird. In TypeScript wird der Typ des Ergebnisses für diese Methodenüberladung vom Typ der Eingabe DocumentModelabgeleitet.

Beispiele

Diese Methode unterstützt streambare Anforderungstexte (FormRecognizerRequestBody), z. B. Node.JS-Objekte ReadableStream , Browser Blobs und ArrayBuffers. Der Inhalt des Texts wird zur Analyse in den Dienst hochgeladen.

Wenn es sich bei der bereitgestellten Eingabe um eine Zeichenfolge handelt, wird sie als URL zum Speicherort eines zu analysierenden Dokuments behandelt. Weitere Informationen finden Sie unter der beginAnalyzeDocumentFromUrl-Methode . Die Verwendung dieser Methode wird bei verwendung von URLs bevorzugt, und DIE URL-Unterstützung wird nur in dieser Methode aus Gründen der Abwärtskompatibilität bereitgestellt.

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>

Ein DocumentModel , das das für die Analyse zu verwendende Modell und den erwarteten Ausgabetyp darstellt

document
FormRecognizerRequestBody

ein FormRecognizerRequestBody , der mit der Anforderung hochgeladen wird

options

AnalyzeDocumentOptions<Result>

optionale Einstellungen für den Analysevorgang und den Poller

Gibt zurück

Promise<AnalysisPoller<Result>>

ein Zeitintensiver Vorgang (Poller), der schließlich einen AnalyzeResult mit Dokumenten erzeugt, die den Ergebnistyp aufweisen, der dem Eingabemodell zugeordnet ist

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

Extrahieren Sie Daten aus einer Eingabe mithilfe eines Modells, das durch die eindeutige ID angegeben wird.

Dieser Vorgang unterstützt sowohl benutzerdefinierte als auch vordefinierte Modelle. Um z. B. das vordefinierte Rechnungsmodell zu verwenden, geben Sie die Modell-ID "prebuilt-invoice" an, oder um das einfachere vordefinierte Layoutmodell zu verwenden, geben Sie die Modell-ID "prebuilt-layout" an.

Die in erzeugten AnalyzeResult Felder hängen vom Modell ab, das für die Analyse verwendet wird, und die Werte in den Feldern aller extrahierten Dokumente hängen von den Dokumenttypen im Modell (sofern vorhanden) und den entsprechenden Feldschemas ab.

Beispiele

Diese Methode unterstützt das Extrahieren von Daten aus einer Datei unter einer bestimmten URL. Der Formularerkennung-Dienst versucht, eine Datei mithilfe der übermittelten URL herunterzuladen, sodass die URL über das öffentliche Internet zugänglich sein muss. Beispielsweise kann ein SAS-Token verwendet werden, um Lesezugriff auf ein Blob in Azure Storage zu gewähren, und der Dienst verwendet die SAS-codierte URL, um die Datei anzufordern.

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

die eindeutige ID (Name) des Modells innerhalb der Ressource dieses Clients

documentUrl

string

eine URL (Zeichenfolge) zu einem Eingabedokument, auf das über das öffentliche Internet zugegriffen werden kann

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

optionale Einstellungen für den Analysevorgang und den Poller

Gibt zurück

Ein lang andauernder Vorgang (Poller), der schließlich eine AnalyzeResult

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

Extrahieren sie Daten aus einer Eingabe mithilfe eines Modells, das über ein bekanntes, stark typisiertes Dokumentschema ( documentModel) verfügt.

Die im erzeugten AnalyzeResult Felder hängen vom Modell ab, das für die Analyse verwendet wird. In TypeScript wird der Typ des Ergebnisses für diese Methodenüberladung vom Typ der Eingabe DocumentModelabgeleitet.

Beispiele

Diese Methode unterstützt das Extrahieren von Daten aus einer Datei unter einer bestimmten URL. Der Formularerkennung-Dienst versucht, eine Datei mithilfe der übermittelten URL herunterzuladen, sodass die URL über das öffentliche Internet zugänglich sein muss. Beispielsweise kann ein SAS-Token verwendet werden, um Lesezugriff auf ein Blob in Azure Storage zu gewähren, und der Dienst verwendet die SAS-codierte URL, um die Datei anzufordern.

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

Ein DocumentModel , das das für die Analyse zu verwendende Modell und den erwarteten Ausgabetyp darstellt

documentUrl

string

eine URL (Zeichenfolge) zu einem Eingabedokument, auf das über das öffentliche Internet zugegriffen werden kann

options

AnalyzeDocumentOptions<Result>

optionale Einstellungen für den Analysevorgang und den Poller

Gibt zurück

Promise<AnalysisPoller<Result>>

Ein lang andauernder Vorgang (Poller), der schließlich eine AnalyzeResult

beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

Klassifizieren eines Dokuments mithilfe eines benutzerdefinierten Klassifizierers, der durch seine ID angegeben wird.

Diese Methode erzeugt einen zeitintensiven Vorgang (Poller), der schließlich einen AnalyzeResulterzeugt. Dies ist derselbe Typ wie beginAnalyzeDocument und beginAnalyzeDocumentFromUrl, aber das Ergebnis enthält nur eine kleine Teilmenge seiner Felder. Nur das Feld und pages das documents Feld werden aufgefüllt, und es werden nur minimale Seiteninformationen zurückgegeben. Das documents Feld enthält Informationen über alle identifizierten Dokumente und die docType , als die sie klassifiziert wurden.

Beispiel

Diese Methode unterstützt streambare Anforderungstexte (FormRecognizerRequestBody), z. B. Node.JS-Objekte ReadableStream , Browser Blobs und ArrayBuffers. Der Inhalt des Texts wird zur Analyse in den Dienst hochgeladen.

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

die ID des benutzerdefinierten Klassifizierers, der für die Analyse verwendet werden soll.

document
FormRecognizerRequestBody

das zu klassifizierende Dokument

options
ClassifyDocumentOptions

Optionen für den Klassifizierungsvorgang

Gibt zurück

Ein lang andauernder Vorgang (Poller), der schließlich eine AnalyzeResult

beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

Klassifizieren Sie ein Dokument aus einer URL mithilfe eines benutzerdefinierten Klassifizierers, der durch seine ID angegeben wird.

Diese Methode erzeugt einen zeitintensiven Vorgang (Poller), der schließlich einen AnalyzeResulterzeugt. Dies ist derselbe Typ wie beginAnalyzeDocument und beginAnalyzeDocumentFromUrl, aber das Ergebnis enthält nur eine kleine Teilmenge seiner Felder. Nur das Feld und pages das documents Feld werden aufgefüllt, und es werden nur minimale Seiteninformationen zurückgegeben. Das documents Feld enthält Informationen über alle identifizierten Dokumente und die docType , als die sie klassifiziert wurden.

Beispiel

Diese Methode unterstützt das Extrahieren von Daten aus einer Datei unter einer bestimmten URL. Der Formularerkennung-Dienst versucht, eine Datei mithilfe der übermittelten URL herunterzuladen, sodass die URL über das öffentliche Internet zugänglich sein muss. Beispielsweise kann ein SAS-Token verwendet werden, um Lesezugriff auf ein Blob in Azure Storage zu gewähren, und der Dienst verwendet die SAS-codierte URL, um die Datei anzufordern.

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

die ID des benutzerdefinierten Klassifizierers, der für die Analyse verwendet werden soll.

documentUrl

string

die URL des zu klassifizierenden Dokuments

Gibt zurück