Sdílet prostřednictvím


DocumentAnalysisClient class

Klient pro interakci s analytickými funkcemi služby Rozpoznávání formulářů.

Příklady:

Služba Rozpoznávání formulářů a klienti podporují dva způsoby ověřování:

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

Klíč rozhraní API (klíč předplatného)

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

Konstruktory

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Vytvoření instance DocumentAnalysisClient z koncového bodu prostředku a klíče statického rozhraní API (KeyCredential),

Příklad:

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)

Vytvořte instanci DocumentAnalysisClient z koncového bodu prostředku a TokenCredentialidentity Azure .

Další informace o ověřování pomocí Azure Active Directory najdete v balíčku @azure/identity.

Příklad:

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

Metody

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

Extrahujte data ze vstupu pomocí modelu poskytnutého jeho jedinečným ID.

Tato operace podporuje vlastní i předem připravené modely. Pokud například chcete použít předem připravený model faktury, zadejte ID modelu "předem připravená faktura" nebo pokud chcete použít jednodušší předem připravený model rozložení, zadejte ID modelu "předem připravené rozložení".

Pole vytvořená v AnalyzeResult závisí na modelu, který se používá k analýze, a hodnoty v polích extrahovaných dokumentů závisejí na typech dokumentů v modelu (pokud existuje) a jejich odpovídajících schématech polí.

Příklady

Tato metoda podporuje streamovatelné těla požadavků (FormRecognizerRequestBody), jako jsou Node.JS ReadableStream objekty, prohlížeče Blobs a ArrayBuffers. Obsah těla se nahraje do služby pro účely analýzy.

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

Extrahujte data ze vstupu pomocí modelu se známým schématem dokumentu se silnými typy (DocumentModel).

Pole vytvořená v AnalyzeResult závisí na modelu, který se používá k analýze. V TypeScriptu je typ výsledku pro toto přetížení metody odvozen z typu vstupního DocumentModel.

Příklady

Tato metoda podporuje streamovatelné těla požadavků (FormRecognizerRequestBody), jako jsou Node.JS ReadableStream objekty, prohlížeče Blobs a ArrayBuffers. Obsah těla se nahraje do služby pro účely analýzy.

Pokud je zadaným vstupem řetězec, bude považován za adresu URL umístění dokumentu, který se má analyzovat. Další informace najdete v beginAnalyzeDocumentFromUrl metoda. Použití této metody je upřednostňované při použití adres URL a podpora adres URL je k dispozici pouze v této metodě kvůli zpětné kompatibilitě.

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

Extrahujte data ze vstupu pomocí modelu poskytnutého jeho jedinečným ID.

Tato operace podporuje vlastní i předem připravené modely. Pokud například chcete použít předem připravený model faktury, zadejte ID modelu "předem připravená faktura" nebo pokud chcete použít jednodušší předem připravený model rozložení, zadejte ID modelu "předem připravené rozložení".

Pole vytvořená v AnalyzeResult závisí na modelu, který se používá k analýze, a hodnoty v polích extrahovaných dokumentů závisejí na typech dokumentů v modelu (pokud existuje) a jejich odpovídajících schématech polí.

Příklady

Tato metoda podporuje extrakci dat ze souboru na dané adrese URL. Služba Rozpoznávání formulářů se pokusí stáhnout soubor pomocí odeslané adresy URL, takže adresa URL musí být přístupná z veřejného internetu. Token SAS se dá například použít k udělení přístupu pro čtení k objektu blob ve službě Azure Storage a služba použije k vyžádání souboru zakódovanou adresu URL s kódováním SAS.

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

Extrahujte data ze vstupu pomocí modelu se známým schématem dokumentu se silnými typy (DocumentModel).

Pole vytvořená v AnalyzeResult závisí na modelu, který se používá k analýze. V TypeScriptu je typ výsledku pro toto přetížení metody odvozen z typu vstupního DocumentModel.

Příklady

Tato metoda podporuje extrakci dat ze souboru na dané adrese URL. Služba Rozpoznávání formulářů se pokusí stáhnout soubor pomocí odeslané adresy URL, takže adresa URL musí být přístupná z veřejného internetu. Token SAS se dá například použít k udělení přístupu pro čtení k objektu blob ve službě Azure Storage a služba použije k vyžádání souboru zakódovanou adresu URL s kódováním SAS.

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

Klasifikovat dokument pomocí vlastního klasifikátoru zadaného jeho ID

Tato metoda vytvoří dlouhotrvající operaci (poller), která nakonec vytvoří AnalyzeResult. Jedná se o stejný typ jako beginAnalyzeDocument a beginAnalyzeDocumentFromUrl, ale výsledek bude obsahovat pouze malou podmnožinu polí. Naplní se pouze pole documents a pole pages a vrátí se pouze minimální informace o stránce. Pole documents bude obsahovat informace o všech identifikovaných dokumentech a docType, které byly klasifikovány jako.

Příklad

Tato metoda podporuje streamovatelné těla požadavků (FormRecognizerRequestBody), jako jsou Node.JS ReadableStream objekty, prohlížeče Blobs a ArrayBuffers. Obsah těla se nahraje do služby pro účely analýzy.

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)

Klasifikovat dokument z adresy URL pomocí vlastního klasifikátoru poskytnutého jeho ID.

Tato metoda vytvoří dlouhotrvající operaci (poller), která nakonec vytvoří AnalyzeResult. Jedná se o stejný typ jako beginAnalyzeDocument a beginAnalyzeDocumentFromUrl, ale výsledek bude obsahovat pouze malou podmnožinu polí. Naplní se pouze pole documents a pole pages a vrátí se pouze minimální informace o stránce. Pole documents bude obsahovat informace o všech identifikovaných dokumentech a docType, které byly klasifikovány jako.

Příklad

Tato metoda podporuje extrakci dat ze souboru na dané adrese URL. Služba Rozpoznávání formulářů se pokusí stáhnout soubor pomocí odeslané adresy URL, takže adresa URL musí být přístupná z veřejného internetu. Token SAS se dá například použít k udělení přístupu pro čtení k objektu blob ve službě Azure Storage a služba použije k vyžádání souboru zakódovanou adresu URL s kódováním SAS.

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

Podrobnosti konstruktoru

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Vytvoření instance DocumentAnalysisClient z koncového bodu prostředku a klíče statického rozhraní API (KeyCredential),

Příklad:

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)

Parametry

endpoint

string

adresa URL koncového bodu instance služby Azure Cognitive Services

credential
KeyCredential

Klíč KeyCredential obsahující klíč předplatného instance služeb Cognitive Services

options
DocumentAnalysisClientOptions

volitelná nastavení pro konfiguraci všech metod v klientovi

DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

Vytvořte instanci DocumentAnalysisClient z koncového bodu prostředku a TokenCredentialidentity Azure .

Další informace o ověřování pomocí Azure Active Directory najdete v balíčku @azure/identity.

Příklad:

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)

Parametry

endpoint

string

adresa URL koncového bodu instance služby Azure Cognitive Services

credential
TokenCredential

Instance TokenCredential z balíčku @azure/identity

options
DocumentAnalysisClientOptions

volitelná nastavení pro konfiguraci všech metod v klientovi

Podrobnosti metody

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

Extrahujte data ze vstupu pomocí modelu poskytnutého jeho jedinečným ID.

Tato operace podporuje vlastní i předem připravené modely. Pokud například chcete použít předem připravený model faktury, zadejte ID modelu "předem připravená faktura" nebo pokud chcete použít jednodušší předem připravený model rozložení, zadejte ID modelu "předem připravené rozložení".

Pole vytvořená v AnalyzeResult závisí na modelu, který se používá k analýze, a hodnoty v polích extrahovaných dokumentů závisejí na typech dokumentů v modelu (pokud existuje) a jejich odpovídajících schématech polí.

Příklady

Tato metoda podporuje streamovatelné těla požadavků (FormRecognizerRequestBody), jako jsou Node.JS ReadableStream objekty, prohlížeče Blobs a ArrayBuffers. Obsah těla se nahraje do služby pro účely analýzy.

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

Parametry

modelId

string

jedinečné ID (název) modelu v rámci prostředku tohoto klienta

document
FormRecognizerRequestBody

FormRecognizerRequestBody, který se nahraje s žádostí

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

volitelná nastavení pro operaci analýzy a poller

Návraty

dlouhotrvající operace (poller), která nakonec vytvoří AnalyzeResult

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

Extrahujte data ze vstupu pomocí modelu se známým schématem dokumentu se silnými typy (DocumentModel).

Pole vytvořená v AnalyzeResult závisí na modelu, který se používá k analýze. V TypeScriptu je typ výsledku pro toto přetížení metody odvozen z typu vstupního DocumentModel.

Příklady

Tato metoda podporuje streamovatelné těla požadavků (FormRecognizerRequestBody), jako jsou Node.JS ReadableStream objekty, prohlížeče Blobs a ArrayBuffers. Obsah těla se nahraje do služby pro účely analýzy.

Pokud je zadaným vstupem řetězec, bude považován za adresu URL umístění dokumentu, který se má analyzovat. Další informace najdete v beginAnalyzeDocumentFromUrl metoda. Použití této metody je upřednostňované při použití adres URL a podpora adres URL je k dispozici pouze v této metodě kvůli zpětné kompatibilitě.

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

Parametry

model

DocumentModel<Result>

DocumentModel představující model, který se má použít k analýze, a očekávaný typ výstupu

document
FormRecognizerRequestBody

FormRecognizerRequestBody, který se nahraje s žádostí

options

AnalyzeDocumentOptions<Result>

volitelná nastavení pro operaci analýzy a poller

Návraty

Promise<AnalysisPoller<Result>>

Dlouhotrvající operace (poller), která nakonec vytvoří AnalyzeResult s dokumenty, které mají typ výsledku přidružený ke vstupnímu modelu.

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

Extrahujte data ze vstupu pomocí modelu poskytnutého jeho jedinečným ID.

Tato operace podporuje vlastní i předem připravené modely. Pokud například chcete použít předem připravený model faktury, zadejte ID modelu "předem připravená faktura" nebo pokud chcete použít jednodušší předem připravený model rozložení, zadejte ID modelu "předem připravené rozložení".

Pole vytvořená v AnalyzeResult závisí na modelu, který se používá k analýze, a hodnoty v polích extrahovaných dokumentů závisejí na typech dokumentů v modelu (pokud existuje) a jejich odpovídajících schématech polí.

Příklady

Tato metoda podporuje extrakci dat ze souboru na dané adrese URL. Služba Rozpoznávání formulářů se pokusí stáhnout soubor pomocí odeslané adresy URL, takže adresa URL musí být přístupná z veřejného internetu. Token SAS se dá například použít k udělení přístupu pro čtení k objektu blob ve službě Azure Storage a služba použije k vyžádání souboru zakódovanou adresu URL s kódováním SAS.

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

Parametry

modelId

string

jedinečné ID (název) modelu v rámci prostředku tohoto klienta

documentUrl

string

adresa URL (řetězec) vstupního dokumentu přístupného z veřejného internetu

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

volitelná nastavení pro operaci analýzy a poller

Návraty

dlouhotrvající operace (poller), která nakonec vytvoří AnalyzeResult

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

Extrahujte data ze vstupu pomocí modelu se známým schématem dokumentu se silnými typy (DocumentModel).

Pole vytvořená v AnalyzeResult závisí na modelu, který se používá k analýze. V TypeScriptu je typ výsledku pro toto přetížení metody odvozen z typu vstupního DocumentModel.

Příklady

Tato metoda podporuje extrakci dat ze souboru na dané adrese URL. Služba Rozpoznávání formulářů se pokusí stáhnout soubor pomocí odeslané adresy URL, takže adresa URL musí být přístupná z veřejného internetu. Token SAS se dá například použít k udělení přístupu pro čtení k objektu blob ve službě Azure Storage a služba použije k vyžádání souboru zakódovanou adresu URL s kódováním SAS.

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

Parametry

model

DocumentModel<Result>

DocumentModel představující model, který se má použít k analýze, a očekávaný typ výstupu

documentUrl

string

adresa URL (řetězec) vstupního dokumentu přístupného z veřejného internetu

options

AnalyzeDocumentOptions<Result>

volitelná nastavení pro operaci analýzy a poller

Návraty

Promise<AnalysisPoller<Result>>

dlouhotrvající operace (poller), která nakonec vytvoří AnalyzeResult

beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

Klasifikovat dokument pomocí vlastního klasifikátoru zadaného jeho ID

Tato metoda vytvoří dlouhotrvající operaci (poller), která nakonec vytvoří AnalyzeResult. Jedná se o stejný typ jako beginAnalyzeDocument a beginAnalyzeDocumentFromUrl, ale výsledek bude obsahovat pouze malou podmnožinu polí. Naplní se pouze pole documents a pole pages a vrátí se pouze minimální informace o stránce. Pole documents bude obsahovat informace o všech identifikovaných dokumentech a docType, které byly klasifikovány jako.

Příklad

Tato metoda podporuje streamovatelné těla požadavků (FormRecognizerRequestBody), jako jsou Node.JS ReadableStream objekty, prohlížeče Blobs a ArrayBuffers. Obsah těla se nahraje do služby pro účely analýzy.

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

Parametry

classifierId

string

ID vlastního klasifikátoru, který se má použít k analýze

document
FormRecognizerRequestBody

dokument ke klasifikaci

options
ClassifyDocumentOptions

možnosti operace klasifikace

Návraty

dlouhotrvající operace (poller), která nakonec vytvoří AnalyzeResult

beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

Klasifikovat dokument z adresy URL pomocí vlastního klasifikátoru poskytnutého jeho ID.

Tato metoda vytvoří dlouhotrvající operaci (poller), která nakonec vytvoří AnalyzeResult. Jedná se o stejný typ jako beginAnalyzeDocument a beginAnalyzeDocumentFromUrl, ale výsledek bude obsahovat pouze malou podmnožinu polí. Naplní se pouze pole documents a pole pages a vrátí se pouze minimální informace o stránce. Pole documents bude obsahovat informace o všech identifikovaných dokumentech a docType, které byly klasifikovány jako.

Příklad

Tato metoda podporuje extrakci dat ze souboru na dané adrese URL. Služba Rozpoznávání formulářů se pokusí stáhnout soubor pomocí odeslané adresy URL, takže adresa URL musí být přístupná z veřejného internetu. Token SAS se dá například použít k udělení přístupu pro čtení k objektu blob ve službě Azure Storage a služba použije k vyžádání souboru zakódovanou adresu URL s kódováním SAS.

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

Parametry

classifierId

string

ID vlastního klasifikátoru, který se má použít k analýze

documentUrl

string

adresa URL dokumentu ke klasifikaci

Návraty