Share via


DocumentAnalysisClient class

Een client voor interactie met de analysefuncties van de Form Recognizer-service.

Voorbeelden:

De Form Recognizer-service en clients ondersteunen twee verificatiemethoden:

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-sleutel (abonnementssleutel)

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

Constructors

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

DocumentAnalysisClient Een exemplaar maken van een resource-eindpunt en een statische API-sleutel (KeyCredential),

Voorbeeld:

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)

Maak een DocumentAnalysisClient exemplaar van een resource-eindpunt en een Azure-identiteit TokenCredential.

Zie het @azure/identity pakket voor meer informatie over verificatie met Azure Active Directory.

Voorbeeld:

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

Gegevens extraheren uit een invoer met behulp van een model dat is opgegeven door de unieke id.

Deze bewerking ondersteunt zowel aangepaste als vooraf samengestelde modellen. Als u bijvoorbeeld het vooraf samengestelde factuurmodel wilt gebruiken, geeft u de model-id 'prebuilt-invoice' op of geeft u de model-id 'prebuilt-layout' op.

De velden die in de AnalyzeResult worden geproduceerd, zijn afhankelijk van het model dat wordt gebruikt voor analyse en de waarden in geëxtraheerde documentenvelden zijn afhankelijk van de documenttypen in het model (indien aanwezig) en de bijbehorende veldschema's.

Voorbeelden

Deze methode ondersteunt streambare aanvraagbody's (FormRecognizerRequestBody), zoals Node.JS ReadableStream objecten, browser Blobs en ArrayBuffers. De inhoud van de hoofdtekst wordt geüpload naar de service voor analyse.

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

Gegevens extraheren uit een invoer met behulp van een model met een bekend, sterk getypt documentschema (een DocumentModel).

De velden die in de AnalyzeResult worden geproduceerd, zijn afhankelijk van het model dat wordt gebruikt voor analyse. In TypeScript wordt het type resultaat voor deze methode-overbelasting afgeleid van het type van de invoer DocumentModel.

Voorbeelden

Deze methode ondersteunt streambare aanvraagbody's (FormRecognizerRequestBody), zoals Node.JS ReadableStream objecten, browser Blobs en ArrayBuffers. De inhoud van de hoofdtekst wordt geüpload naar de service voor analyse.

Als de opgegeven invoer een tekenreeks is, wordt deze behandeld als een URL naar de locatie van een document dat moet worden geanalyseerd. Zie de methode beginAnalyzeDocumentFromUrl voor meer informatie. Het gebruik van deze methode heeft de voorkeur wanneer u URL's gebruikt en URL-ondersteuning wordt alleen in deze methode geboden voor compatibiliteit met eerdere versies.

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

Gegevens extraheren uit een invoer met behulp van een model dat is opgegeven door de unieke id.

Deze bewerking ondersteunt zowel aangepaste als vooraf samengestelde modellen. Als u bijvoorbeeld het vooraf samengestelde factuurmodel wilt gebruiken, geeft u de model-id 'prebuilt-invoice' op of geeft u de model-id 'prebuilt-layout' op.

De velden die in de AnalyzeResult worden geproduceerd, zijn afhankelijk van het model dat wordt gebruikt voor analyse en de waarden in geëxtraheerde documentenvelden zijn afhankelijk van de documenttypen in het model (indien aanwezig) en de bijbehorende veldschema's.

Voorbeelden

Deze methode ondersteunt het extraheren van gegevens uit een bestand op een bepaalde URL. De Form Recognizer-service probeert een bestand te downloaden met behulp van de verzonden URL, dus de URL moet toegankelijk zijn vanaf het openbare internet. Een SAS-token kan bijvoorbeeld worden gebruikt om leestoegang te verlenen tot een blob in Azure Storage en de service gebruikt de MET SAS gecodeerde URL om het bestand aan te vragen.

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

Gegevens extraheren uit een invoer met behulp van een model met een bekend, sterk getypt documentschema (een DocumentModel).

De velden die in de AnalyzeResult worden geproduceerd, zijn afhankelijk van het model dat wordt gebruikt voor analyse. In TypeScript wordt het type resultaat voor deze methode-overbelasting afgeleid van het type van de invoer DocumentModel.

Voorbeelden

Deze methode ondersteunt het extraheren van gegevens uit een bestand op een bepaalde URL. De Form Recognizer-service probeert een bestand te downloaden met behulp van de verzonden URL, dus de URL moet toegankelijk zijn vanaf het openbare internet. Een SAS-token kan bijvoorbeeld worden gebruikt om leestoegang te verlenen tot een blob in Azure Storage en de service gebruikt de MET SAS gecodeerde URL om het bestand aan te vragen.

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

Een document classificeren met behulp van een aangepaste classificatie die is opgegeven op basis van de id.

Deze methode produceert een langlopende bewerking (poller) die uiteindelijk een AnalyzeResultproduceert. Dit is hetzelfde type als beginAnalyzeDocument en beginAnalyzeDocumentFromUrl, maar het resultaat bevat slechts een kleine subset van de velden. Alleen het documents veld en pages het veld worden ingevuld en alleen minimale paginagegevens worden geretourneerd. Het documents veld bevat informatie over alle geïdentificeerde documenten en de docType documenten die zijn geclassificeerd als.

Voorbeeld

Deze methode ondersteunt streambare aanvraagbody's (FormRecognizerRequestBody), zoals Node.JS ReadableStream objecten, browser Blobs en ArrayBuffers. De inhoud van de hoofdtekst wordt geüpload naar de service voor analyse.

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)

Een document classificeren vanaf een URL met behulp van een aangepaste classificatie die is opgegeven op basis van de id.

Deze methode produceert een langlopende bewerking (poller) die uiteindelijk een AnalyzeResultproduceert. Dit is hetzelfde type als beginAnalyzeDocument en beginAnalyzeDocumentFromUrl, maar het resultaat bevat slechts een kleine subset van de velden. Alleen het documents veld en pages het veld worden ingevuld en alleen minimale paginagegevens worden geretourneerd. Het documents veld bevat informatie over alle geïdentificeerde documenten en de docType documenten die zijn geclassificeerd als.

Voorbeeld

Deze methode ondersteunt het extraheren van gegevens uit een bestand op een bepaalde URL. De Form Recognizer-service probeert een bestand te downloaden met behulp van de verzonden URL, dus de URL moet toegankelijk zijn vanaf het openbare internet. Een SAS-token kan bijvoorbeeld worden gebruikt om leestoegang te verlenen tot een blob in Azure Storage en de service gebruikt de MET SAS gecodeerde URL om het bestand aan te vragen.

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

Constructordetails

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

DocumentAnalysisClient Een exemplaar maken van een resource-eindpunt en een statische API-sleutel (KeyCredential),

Voorbeeld:

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)

Parameters

endpoint

string

de eindpunt-URL van een Azure Cognitive Services-exemplaar

credential
KeyCredential

een KeyCredential met de abonnementssleutel van het Cognitive Services-exemplaar

options
DocumentAnalysisClientOptions

optionele instellingen voor het configureren van alle methoden in de client

DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

Maak een DocumentAnalysisClient exemplaar van een resource-eindpunt en een Azure-identiteit TokenCredential.

Zie het @azure/identity pakket voor meer informatie over verificatie met Azure Active Directory.

Voorbeeld:

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)

Parameters

endpoint

string

de eindpunt-URL van een Azure Cognitive Services-exemplaar

credential
TokenCredential

een TokenCredential-exemplaar uit het @azure/identity pakket

options
DocumentAnalysisClientOptions

optionele instellingen voor het configureren van alle methoden in de client

Methodedetails

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

Gegevens extraheren uit een invoer met behulp van een model dat is opgegeven door de unieke id.

Deze bewerking ondersteunt zowel aangepaste als vooraf samengestelde modellen. Als u bijvoorbeeld het vooraf samengestelde factuurmodel wilt gebruiken, geeft u de model-id 'prebuilt-invoice' op of geeft u de model-id 'prebuilt-layout' op.

De velden die in de AnalyzeResult worden geproduceerd, zijn afhankelijk van het model dat wordt gebruikt voor analyse en de waarden in geëxtraheerde documentenvelden zijn afhankelijk van de documenttypen in het model (indien aanwezig) en de bijbehorende veldschema's.

Voorbeelden

Deze methode ondersteunt streambare aanvraagbody's (FormRecognizerRequestBody), zoals Node.JS ReadableStream objecten, browser Blobs en ArrayBuffers. De inhoud van de hoofdtekst wordt geüpload naar de service voor analyse.

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

Parameters

modelId

string

de unieke id (naam) van het model in de resource van deze client

document
FormRecognizerRequestBody

een FormRecognizerRequestBody die wordt geüpload met de aanvraag

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

optionele instellingen voor de analysebewerking en poller

Retouren

een langdurige bewerking (poller) die uiteindelijk een AnalyzeResult

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

Gegevens extraheren uit een invoer met behulp van een model met een bekend, sterk getypt documentschema (een DocumentModel).

De velden die in de AnalyzeResult worden geproduceerd, zijn afhankelijk van het model dat wordt gebruikt voor analyse. In TypeScript wordt het type resultaat voor deze methode-overbelasting afgeleid van het type van de invoer DocumentModel.

Voorbeelden

Deze methode ondersteunt streambare aanvraagbody's (FormRecognizerRequestBody), zoals Node.JS ReadableStream objecten, browser Blobs en ArrayBuffers. De inhoud van de hoofdtekst wordt geüpload naar de service voor analyse.

Als de opgegeven invoer een tekenreeks is, wordt deze behandeld als een URL naar de locatie van een document dat moet worden geanalyseerd. Zie de methode beginAnalyzeDocumentFromUrl voor meer informatie. Het gebruik van deze methode heeft de voorkeur wanneer u URL's gebruikt en URL-ondersteuning wordt alleen in deze methode geboden voor compatibiliteit met eerdere versies.

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

Parameters

model

DocumentModel<Result>

een DocumentModel dat het model vertegenwoordigt dat moet worden gebruikt voor analyse en het verwachte uitvoertype

document
FormRecognizerRequestBody

een FormRecognizerRequestBody die wordt geüpload met de aanvraag

options

AnalyzeDocumentOptions<Result>

optionele instellingen voor de analysebewerking en poller

Retouren

Promise<AnalysisPoller<Result>>

een langlopende bewerking (poller) die uiteindelijk een AnalyzeResult produceert met documenten met het resultaattype dat is gekoppeld aan het invoermodel

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

Gegevens extraheren uit een invoer met behulp van een model dat is opgegeven door de unieke id.

Deze bewerking ondersteunt zowel aangepaste als vooraf samengestelde modellen. Als u bijvoorbeeld het vooraf samengestelde factuurmodel wilt gebruiken, geeft u de model-id 'prebuilt-invoice' op of geeft u de model-id 'prebuilt-layout' op.

De velden die in de AnalyzeResult worden geproduceerd, zijn afhankelijk van het model dat wordt gebruikt voor analyse en de waarden in geëxtraheerde documentenvelden zijn afhankelijk van de documenttypen in het model (indien aanwezig) en de bijbehorende veldschema's.

Voorbeelden

Deze methode ondersteunt het extraheren van gegevens uit een bestand op een bepaalde URL. De Form Recognizer-service probeert een bestand te downloaden met behulp van de verzonden URL, dus de URL moet toegankelijk zijn vanaf het openbare internet. Een SAS-token kan bijvoorbeeld worden gebruikt om leestoegang te verlenen tot een blob in Azure Storage en de service gebruikt de MET SAS gecodeerde URL om het bestand aan te vragen.

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

Parameters

modelId

string

de unieke id (naam) van het model in de resource van deze client

documentUrl

string

een URL (tekenreeks) naar een invoerdocument dat toegankelijk is vanaf het openbare internet

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

optionele instellingen voor de analysebewerking en poller

Retouren

een langdurige bewerking (poller) die uiteindelijk een AnalyzeResult

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

Gegevens extraheren uit een invoer met behulp van een model met een bekend, sterk getypt documentschema (een DocumentModel).

De velden die in de AnalyzeResult worden geproduceerd, zijn afhankelijk van het model dat wordt gebruikt voor analyse. In TypeScript wordt het type resultaat voor deze methode-overbelasting afgeleid van het type van de invoer DocumentModel.

Voorbeelden

Deze methode ondersteunt het extraheren van gegevens uit een bestand op een bepaalde URL. De Form Recognizer-service probeert een bestand te downloaden met behulp van de verzonden URL, dus de URL moet toegankelijk zijn vanaf het openbare internet. Een SAS-token kan bijvoorbeeld worden gebruikt om leestoegang te verlenen tot een blob in Azure Storage en de service gebruikt de MET SAS gecodeerde URL om het bestand aan te vragen.

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

Parameters

model

DocumentModel<Result>

een DocumentModel dat het model vertegenwoordigt dat moet worden gebruikt voor analyse en het verwachte uitvoertype

documentUrl

string

een URL (tekenreeks) naar een invoerdocument dat toegankelijk is vanaf het openbare internet

options

AnalyzeDocumentOptions<Result>

optionele instellingen voor de analysebewerking en poller

Retouren

Promise<AnalysisPoller<Result>>

een langdurige bewerking (poller) die uiteindelijk een AnalyzeResult

beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

Een document classificeren met behulp van een aangepaste classificatie die is opgegeven op basis van de id.

Deze methode produceert een langlopende bewerking (poller) die uiteindelijk een AnalyzeResultproduceert. Dit is hetzelfde type als beginAnalyzeDocument en beginAnalyzeDocumentFromUrl, maar het resultaat bevat slechts een kleine subset van de velden. Alleen het documents veld en pages het veld worden ingevuld en alleen minimale paginagegevens worden geretourneerd. Het documents veld bevat informatie over alle geïdentificeerde documenten en de docType documenten die zijn geclassificeerd als.

Voorbeeld

Deze methode ondersteunt streambare aanvraagbody's (FormRecognizerRequestBody), zoals Node.JS ReadableStream objecten, browser Blobs en ArrayBuffers. De inhoud van de hoofdtekst wordt geüpload naar de service voor analyse.

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

Parameters

classifierId

string

de id van de aangepaste classificatie die moet worden gebruikt voor analyse

document
FormRecognizerRequestBody

het te classificeren document

options
ClassifyDocumentOptions

opties voor de classificatiebewerking

Retouren

een langdurige bewerking (poller) die uiteindelijk een AnalyzeResult

beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

Een document classificeren vanaf een URL met behulp van een aangepaste classificatie die is opgegeven op basis van de id.

Deze methode produceert een langlopende bewerking (poller) die uiteindelijk een AnalyzeResultproduceert. Dit is hetzelfde type als beginAnalyzeDocument en beginAnalyzeDocumentFromUrl, maar het resultaat bevat slechts een kleine subset van de velden. Alleen het documents veld en pages het veld worden ingevuld en alleen minimale paginagegevens worden geretourneerd. Het documents veld bevat informatie over alle geïdentificeerde documenten en de docType documenten die zijn geclassificeerd als.

Voorbeeld

Deze methode ondersteunt het extraheren van gegevens uit een bestand op een bepaalde URL. De Form Recognizer-service probeert een bestand te downloaden met behulp van de verzonden URL, dus de URL moet toegankelijk zijn vanaf het openbare internet. Een SAS-token kan bijvoorbeeld worden gebruikt om leestoegang te verlenen tot een blob in Azure Storage en de service gebruikt de MET SAS gecodeerde URL om het bestand aan te vragen.

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

Parameters

classifierId

string

de id van de aangepaste classificatie die moet worden gebruikt voor analyse

documentUrl

string

de URL van het document dat moet worden geclassificeerd

Retouren