Share via


DocumentAnalysisClient class

Ügyfél a Form Recognizer szolgáltatás elemzési funkcióinak használatához.

Példák:

A Form Recognizer szolgáltatás és az ügyfelek két hitelesítési módot támogatnak:

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-kulcs (előfizetési kulcs)

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

Konstruktorok

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Példány létrehozása DocumentAnalysisClient erőforrásvégpontból és statikus API-kulcsból (KeyCredential),

Példa:

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)

Hozzon létre egy példányt DocumentAnalysisClient egy erőforrásvégpontból és egy Azure Identityből TokenCredential.

Az Azure Active Directoryval történő hitelesítésről további információt a @azure/identity csomagban talál.

Példa:

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

Metódusok

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

Adatok kinyerése egy bemenetből az egyedi azonosítója által megadott modell használatával.

Ez a művelet támogatja az egyéni és az előre összeállított modelleket. Ha például az előre összeállított számlamodellt szeretné használni, adja meg az "előre összeállított számla" modellazonosítót, vagy az egyszerűbb előre összeállított elrendezési modell használatához adja meg az "előre összeállított elrendezés" modellazonosítót.

A modellben AnalyzeResult előállított mezők az elemzéshez használt modelltől függenek, és a kinyert dokumentumok mezőinek értékei a modell dokumentumtípusaitól (ha vannak) és a hozzájuk tartozó mezősémáktól függnek.

Példák

Ez a metódus támogatja a streamelhető kéréstörzseket (FormRecognizerRequestBody), például Node.JS ReadableStream objektumokat, böngésző Blobs-eket és ArrayBuffers-eket. A rendszer a törzs tartalmát elemzés céljából feltölti a szolgáltatásba.

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

Adatok kinyerése egy bemenetből egy ismert, erősen gépelt dokumentumsémával ( DocumentModel) rendelkező modell használatával.

A benne AnalyzeResult létrehozott mezők az elemzéshez használt modelltől függnek. A TypeScriptben a metódus eredményének típusa túlterhelt a bemenet DocumentModeltípusából származik.

Példák

Ez a metódus támogatja a streamelhető kéréstörzseket (FormRecognizerRequestBody), például Node.JS ReadableStream objektumokat, böngésző Blobs-eket és ArrayBuffers-eket. A rendszer a törzs tartalmát elemzés céljából feltölti a szolgáltatásba.

Ha a megadott bemenet egy sztring, akkor a rendszer az elemezni kívánt dokumentum helyére mutató URL-címként kezeli. További információt a beginAnalyzeDocumentFromUrl metódusban talál. A metódus használata url-címek használata esetén ajánlott, és az URL-támogatás csak ebben a metódusban érhető el a visszamenőleges kompatibilitás érdekében.

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

Adatok kinyerése egy bemenetből az egyedi azonosítója által megadott modell használatával.

Ez a művelet támogatja az egyéni és az előre összeállított modelleket. Ha például az előre összeállított számlamodellt szeretné használni, adja meg az "előre összeállított számla" modellazonosítót, vagy az egyszerűbb előre összeállított elrendezési modell használatához adja meg az "előre összeállított elrendezés" modellazonosítót.

A modellben AnalyzeResult előállított mezők az elemzéshez használt modelltől függenek, és a kinyert dokumentumok mezőinek értékei a modell dokumentumtípusaitól (ha vannak) és a hozzájuk tartozó mezősémáktól függnek.

Példák

Ez a módszer támogatja az adatok kinyerését egy adott URL-címen lévő fájlból. A Form Recognizer szolgáltatás megpróbál letölteni egy fájlt a beküldött URL-cím használatával, így az URL-címnek elérhetőnek kell lennie a nyilvános internetről. Például egy SAS-jogkivonattal olvasási hozzáférést biztosíthat egy blobhoz az Azure Storage-ban, és a szolgáltatás az SAS-kódolású URL-címmel kéri le a fájlt.

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

Adatok kinyerése egy bemenetből egy ismert, erősen gépelt dokumentumsémával ( DocumentModel) rendelkező modell használatával.

A benne AnalyzeResult létrehozott mezők az elemzéshez használt modelltől függnek. A TypeScriptben a metódus eredményének típusa túlterhelt a bemenet DocumentModeltípusából származik.

Példák

Ez a módszer támogatja az adatok kinyerését egy adott URL-címen lévő fájlból. A Form Recognizer szolgáltatás megpróbál letölteni egy fájlt a beküldött URL-cím használatával, így az URL-címnek elérhetőnek kell lennie a nyilvános internetről. Például egy SAS-jogkivonattal olvasási hozzáférést biztosíthat egy blobhoz az Azure Storage-ban, és a szolgáltatás az SAS-kódolású URL-címmel kéri le a fájlt.

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

Osztályozhatja a dokumentumokat az azonosítója által megadott egyéni osztályozó használatával.

Ez a metódus létrehoz egy hosszú ideig futó műveletet (poller), amely végül létrehoz egy AnalyzeResult. Ez ugyanaz a típus, mint beginAnalyzeDocument a és beginAnalyzeDocumentFromUrl, de az eredmény csak a mezőinek egy kis részét tartalmazza. Csak a mező és pages a documents mező lesz kitöltve, és csak minimális oldalinformációk lesznek visszaadva. A documents mező az összes azonosított dokumentumra és a docType besorolásukra vonatkozó információkat tartalmazza.

Példa

Ez a metódus támogatja a streamelhető kéréstörzseket (FormRecognizerRequestBody), például Node.JS ReadableStream objektumokat, böngésző Blobs-eket és ArrayBuffers-eket. A rendszer a törzs tartalmát elemzés céljából feltölti a szolgáltatásba.

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)

Osztályozhatja a dokumentumokat egy URL-címről az azonosítója által megadott egyéni osztályozó használatával.

Ez a metódus létrehoz egy hosszú ideig futó műveletet (poller), amely végül létrehoz egy AnalyzeResult. Ez ugyanaz a típus, mint beginAnalyzeDocument a és beginAnalyzeDocumentFromUrl, de az eredmény csak a mezőinek egy kis részét tartalmazza. Csak a mező és pages a documents mező lesz kitöltve, és csak minimális oldalinformációk lesznek visszaadva. A documents mező az összes azonosított dokumentumra és a docType besorolásukra vonatkozó információkat tartalmazza.

Példa

Ez a módszer támogatja az adatok kinyerését egy adott URL-címen lévő fájlból. A Form Recognizer szolgáltatás megpróbál letölteni egy fájlt a beküldött URL-cím használatával, így az URL-címnek elérhetőnek kell lennie a nyilvános internetről. Például egy SAS-jogkivonattal olvasási hozzáférést biztosíthat egy blobhoz az Azure Storage-ban, és a szolgáltatás az SAS-kódolású URL-címmel kéri le a fájlt.

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

Konstruktor adatai

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Példány létrehozása DocumentAnalysisClient erőforrásvégpontból és statikus API-kulcsból (KeyCredential),

Példa:

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)

Paraméterek

endpoint

string

egy Azure Cognitive Services-példány végponti URL-címe

credential
KeyCredential

a Cognitive Services-példány előfizetési kulcsát tartalmazó KeyCredential

options
DocumentAnalysisClientOptions

választható beállítások az ügyfél összes metódusának konfigurálásához

DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

Hozzon létre egy példányt DocumentAnalysisClient egy erőforrásvégpontból és egy Azure Identityből TokenCredential.

Az Azure Active Directoryval történő hitelesítésről további információt a @azure/identity csomagban talál.

Példa:

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)

Paraméterek

endpoint

string

egy Azure Cognitive Services-példány végponti URL-címe

credential
TokenCredential

TokenCredential-példány a @azure/identity csomagból

options
DocumentAnalysisClientOptions

választható beállítások az ügyfél összes metódusának konfigurálásához

Metódus adatai

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

Adatok kinyerése egy bemenetből az egyedi azonosítója által megadott modell használatával.

Ez a művelet támogatja az egyéni és az előre összeállított modelleket. Ha például az előre összeállított számlamodellt szeretné használni, adja meg az "előre összeállított számla" modellazonosítót, vagy az egyszerűbb előre összeállított elrendezési modell használatához adja meg az "előre összeállított elrendezés" modellazonosítót.

A modellben AnalyzeResult előállított mezők az elemzéshez használt modelltől függenek, és a kinyert dokumentumok mezőinek értékei a modell dokumentumtípusaitól (ha vannak) és a hozzájuk tartozó mezősémáktól függnek.

Példák

Ez a metódus támogatja a streamelhető kéréstörzseket (FormRecognizerRequestBody), például Node.JS ReadableStream objektumokat, böngésző Blobs-eket és ArrayBuffers-eket. A rendszer a törzs tartalmát elemzés céljából feltölti a szolgáltatásba.

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

Paraméterek

modelId

string

a modell egyedi azonosítója (neve) az ügyfél erőforrásán belül

document
FormRecognizerRequestBody

a FormRecognizerRequestBody , amelyet a kérelemmel együtt töltünk fel

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

nem kötelező beállítások az elemzési művelethez és a pollerhez

Válaszok

egy hosszú ideig futó művelet (poller), amely végül létrehoz egy AnalyzeResult

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

Adatok kinyerése egy bemenetből egy ismert, erősen gépelt dokumentumsémával ( DocumentModel) rendelkező modell használatával.

A benne AnalyzeResult létrehozott mezők az elemzéshez használt modelltől függnek. A TypeScriptben a metódus eredményének típusa túlterhelt a bemenet DocumentModeltípusából származik.

Példák

Ez a metódus támogatja a streamelhető kéréstörzseket (FormRecognizerRequestBody), például Node.JS ReadableStream objektumokat, böngésző Blobs-eket és ArrayBuffers-eket. A rendszer a törzs tartalmát elemzés céljából feltölti a szolgáltatásba.

Ha a megadott bemenet egy sztring, akkor a rendszer az elemezni kívánt dokumentum helyére mutató URL-címként kezeli. További információt a beginAnalyzeDocumentFromUrl metódusban talál. A metódus használata url-címek használata esetén ajánlott, és az URL-támogatás csak ebben a metódusban érhető el a visszamenőleges kompatibilitás érdekében.

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

Paraméterek

model

DocumentModel<Result>

az elemzéshez használni kívánt modellt és a várt kimeneti típust képviselő DocumentModel

document
FormRecognizerRequestBody

a FormRecognizerRequestBody , amelyet a kérelemmel együtt töltünk fel

options

AnalyzeDocumentOptions<Result>

nem kötelező beállítások az elemzési művelethez és a pollerhez

Válaszok

Promise<AnalysisPoller<Result>>

egy hosszú ideig futó művelet (poller), amely végül létrehoz egy AnalyzeResult olyan dokumentumot, amely a bemeneti modellhez társított eredménytípussal rendelkezik

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

Adatok kinyerése egy bemenetből az egyedi azonosítója által megadott modell használatával.

Ez a művelet támogatja az egyéni és az előre összeállított modelleket. Ha például az előre összeállított számlamodellt szeretné használni, adja meg az "előre összeállított számla" modellazonosítót, vagy az egyszerűbb előre összeállított elrendezési modell használatához adja meg az "előre összeállított elrendezés" modellazonosítót.

A modellben AnalyzeResult előállított mezők az elemzéshez használt modelltől függenek, és a kinyert dokumentumok mezőinek értékei a modell dokumentumtípusaitól (ha vannak) és a hozzájuk tartozó mezősémáktól függnek.

Példák

Ez a módszer támogatja az adatok kinyerését egy adott URL-címen lévő fájlból. A Form Recognizer szolgáltatás megpróbál letölteni egy fájlt a beküldött URL-cím használatával, így az URL-címnek elérhetőnek kell lennie a nyilvános internetről. Például egy SAS-jogkivonattal olvasási hozzáférést biztosíthat egy blobhoz az Azure Storage-ban, és a szolgáltatás az SAS-kódolású URL-címmel kéri le a fájlt.

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

Paraméterek

modelId

string

a modell egyedi azonosítója (neve) az ügyfél erőforrásán belül

documentUrl

string

a nyilvános internetről elérhető bemeneti dokumentum URL-címe (sztringje)

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

nem kötelező beállítások az elemzési művelethez és a pollerhez

Válaszok

egy hosszú ideig futó művelet (poller), amely végül létrehoz egy AnalyzeResult

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

Adatok kinyerése egy bemenetből egy ismert, erősen gépelt dokumentumsémával ( DocumentModel) rendelkező modell használatával.

A benne AnalyzeResult létrehozott mezők az elemzéshez használt modelltől függnek. A TypeScriptben a metódus eredményének típusa túlterhelt a bemenet DocumentModeltípusából származik.

Példák

Ez a módszer támogatja az adatok kinyerését egy adott URL-címen lévő fájlból. A Form Recognizer szolgáltatás megpróbál letölteni egy fájlt a beküldött URL-cím használatával, így az URL-címnek elérhetőnek kell lennie a nyilvános internetről. Például egy SAS-jogkivonattal olvasási hozzáférést biztosíthat egy blobhoz az Azure Storage-ban, és a szolgáltatás az SAS-kódolású URL-címmel kéri le a fájlt.

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

Paraméterek

model

DocumentModel<Result>

az elemzéshez használni kívánt modellt és a várt kimeneti típust képviselő DocumentModel

documentUrl

string

a nyilvános internetről elérhető bemeneti dokumentum URL-címe (sztringje)

options

AnalyzeDocumentOptions<Result>

nem kötelező beállítások az elemzési művelethez és a pollerhez

Válaszok

Promise<AnalysisPoller<Result>>

egy hosszú ideig futó művelet (poller), amely végül létrehoz egy AnalyzeResult

beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

Osztályozhatja a dokumentumokat az azonosítója által megadott egyéni osztályozó használatával.

Ez a metódus létrehoz egy hosszú ideig futó műveletet (poller), amely végül létrehoz egy AnalyzeResult. Ez ugyanaz a típus, mint beginAnalyzeDocument a és beginAnalyzeDocumentFromUrl, de az eredmény csak a mezőinek egy kis részét tartalmazza. Csak a mező és pages a documents mező lesz kitöltve, és csak minimális oldalinformációk lesznek visszaadva. A documents mező az összes azonosított dokumentumra és a docType besorolásukra vonatkozó információkat tartalmazza.

Példa

Ez a metódus támogatja a streamelhető kéréstörzseket (FormRecognizerRequestBody), például Node.JS ReadableStream objektumokat, böngésző Blobs-eket és ArrayBuffers-eket. A rendszer a törzs tartalmát elemzés céljából feltölti a szolgáltatásba.

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

Paraméterek

classifierId

string

az elemzéshez használandó egyéni osztályozó azonosítója

document
FormRecognizerRequestBody

az osztályozandó dokumentum

options
ClassifyDocumentOptions

a besorolási művelet beállításai

Válaszok

egy hosszú ideig futó művelet (poller), amely végül létrehoz egy AnalyzeResult

beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

Osztályozhatja a dokumentumokat egy URL-címről az azonosítója által megadott egyéni osztályozó használatával.

Ez a metódus létrehoz egy hosszú ideig futó műveletet (poller), amely végül létrehoz egy AnalyzeResult. Ez ugyanaz a típus, mint beginAnalyzeDocument a és beginAnalyzeDocumentFromUrl, de az eredmény csak a mezőinek egy kis részét tartalmazza. Csak a mező és pages a documents mező lesz kitöltve, és csak minimális oldalinformációk lesznek visszaadva. A documents mező az összes azonosított dokumentumra és a docType besorolásukra vonatkozó információkat tartalmazza.

Példa

Ez a módszer támogatja az adatok kinyerését egy adott URL-címen lévő fájlból. A Form Recognizer szolgáltatás megpróbál letölteni egy fájlt a beküldött URL-cím használatával, így az URL-címnek elérhetőnek kell lennie a nyilvános internetről. Például egy SAS-jogkivonattal olvasási hozzáférést biztosíthat egy blobhoz az Azure Storage-ban, és a szolgáltatás az SAS-kódolású URL-címmel kéri le a fájlt.

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

Paraméterek

classifierId

string

az elemzéshez használandó egyéni osztályozó azonosítója

documentUrl

string

a besorolni kívánt dokumentum URL-címe

Válaszok