Dela via


DocumentAnalysisClient class

En klient för att interagera med Formigenkänning-tjänstens analysfunktioner.

Exempel:

Formigenkänning-tjänsten och klienterna stöder två autentiseringsmetoder:

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-nyckel (prenumerationsnyckel)

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

Konstruktorer

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Skapa en DocumentAnalysisClient instans från en resursslutpunkt och en statisk API-nyckel (KeyCredential),

Exempel:

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)

Skapa en DocumentAnalysisClient instans från en resursslutpunkt och en Azure-identitet TokenCredential.

Mer information om autentisering med Azure Active Directory finns i @azure/identity paketet.

Exempel:

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

Metoder

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

Extrahera data från indata med hjälp av en modell som anges av dess unika ID.

Den här åtgärden stöder anpassade och fördefinierade modeller. Om du till exempel vill använda den fördefinierade fakturamodellen anger du modell-ID:t "prebuilt-invoice" eller för att använda den enklare fördefinierade layoutmodellen genom att ange modell-ID:t "prebuilt-layout".

De fält som skapas i AnalyzeResult beror på vilken modell som används för analys, och värdena i alla extraherade dokumentfält beror på dokumenttyperna i modellen (om sådana finns) och deras motsvarande fältscheman.

Exempel

Den här metoden stöder strömmande begärandeorgan (FormRecognizerRequestBody) som Node.JS ReadableStream objekt, webbläsare Bloboch ArrayBuffers. Innehållet i brödtexten laddas upp till tjänsten för analys.

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

Extrahera data från indata med hjälp av en modell som har ett känt, starkt skrivet dokumentschema (en DocumentModel).

De fält som skapas i AnalyzeResult beror på vilken modell som används för analys. I TypeScript härleds typen av resultat för den här metodens överlagring från typen av indata DocumentModel.

Exempel

Den här metoden stöder strömmande begärandeorgan (FormRecognizerRequestBody) som Node.JS ReadableStream objekt, webbläsare Bloboch ArrayBuffers. Innehållet i brödtexten laddas upp till tjänsten för analys.

Om indata är en sträng behandlas den som en URL till platsen för ett dokument som ska analyseras. Mer information finns i metoden beginAnalyzeDocumentFromUrl . Du bör använda den metoden när du använder URL:er, och URL-stöd tillhandahålls endast i den här metoden för bakåtkompatibilitet.

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

Extrahera data från indata med hjälp av en modell som anges av dess unika ID.

Den här åtgärden stöder anpassade och fördefinierade modeller. Om du till exempel vill använda den fördefinierade fakturamodellen anger du modell-ID:t "prebuilt-invoice" eller för att använda den enklare fördefinierade layoutmodellen genom att ange modell-ID:t "prebuilt-layout".

De fält som skapas i AnalyzeResult beror på vilken modell som används för analys, och värdena i alla extraherade dokumentfält beror på dokumenttyperna i modellen (om sådana finns) och deras motsvarande fältscheman.

Exempel

Den här metoden stöder extrahering av data från en fil på en viss URL. Den Formigenkänning tjänsten försöker ladda ned en fil med hjälp av den skickade URL:en, så URL:en måste vara tillgänglig från det offentliga Internet. En SAS-token kan till exempel användas för att bevilja läsbehörighet till en blob i Azure Storage, och tjänsten använder den SAS-kodade URL:en för att begära filen.

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

Extrahera data från indata med hjälp av en modell som har ett känt, starkt skrivet dokumentschema (en DocumentModel).

De fält som skapas i AnalyzeResult beror på vilken modell som används för analys. I TypeScript härleds typen av resultat för den här metodens överlagring från typen av indata DocumentModel.

Exempel

Den här metoden stöder extrahering av data från en fil på en viss URL. Den Formigenkänning tjänsten försöker ladda ned en fil med hjälp av den skickade URL:en, så URL:en måste vara tillgänglig från det offentliga Internet. En SAS-token kan till exempel användas för att bevilja läsbehörighet till en blob i Azure Storage, och tjänsten använder den SAS-kodade URL:en för att begära filen.

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

Klassificera ett dokument med hjälp av en anpassad klassificerare som anges av dess ID.

Den här metoden skapar en tidskrävande åtgärd (poller) som så småningom skapar en AnalyzeResult. Det här är samma typ som beginAnalyzeDocument och beginAnalyzeDocumentFromUrl, men resultatet innehåller bara en liten delmängd av fälten. Endast fältet documents och pages fältet fylls i och endast minimal sidinformation returneras. Fältet documents innehåller information om alla identifierade dokument och docType att de har klassificerats som.

Exempel

Den här metoden stöder strömmande begärandeorgan (FormRecognizerRequestBody) som Node.JS ReadableStream objekt, webbläsare Bloboch ArrayBuffers. Innehållet i brödtexten laddas upp till tjänsten för analys.

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)

Klassificera ett dokument från en URL med hjälp av en anpassad klassificerare som anges av dess ID.

Den här metoden skapar en tidskrävande åtgärd (poller) som så småningom skapar en AnalyzeResult. Det här är samma typ som beginAnalyzeDocument och beginAnalyzeDocumentFromUrl, men resultatet innehåller bara en liten delmängd av fälten. Endast fältet documents och pages fältet fylls i och endast minimal sidinformation returneras. Fältet documents innehåller information om alla identifierade dokument och docType att de har klassificerats som.

Exempel

Den här metoden stöder extrahering av data från en fil på en viss URL. Den Formigenkänning tjänsten försöker ladda ned en fil med hjälp av den skickade URL:en, så URL:en måste vara tillgänglig från det offentliga Internet. En SAS-token kan till exempel användas för att bevilja läsbehörighet till en blob i Azure Storage, och tjänsten använder den SAS-kodade URL:en för att begära filen.

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

Konstruktorinformation

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

Skapa en DocumentAnalysisClient instans från en resursslutpunkt och en statisk API-nyckel (KeyCredential),

Exempel:

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)

Parametrar

endpoint

string

slutpunkts-URL:en för en Azure Cognitive Services-instans

credential
KeyCredential

en KeyCredential som innehåller prenumerationsnyckeln för Cognitive Services-instansen

options
DocumentAnalysisClientOptions

valfria inställningar för att konfigurera alla metoder i klienten

DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

Skapa en DocumentAnalysisClient instans från en resursslutpunkt och en Azure-identitet TokenCredential.

Mer information om autentisering med Azure Active Directory finns i @azure/identity paketet.

Exempel:

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)

Parametrar

endpoint

string

slutpunkts-URL:en för en Azure Cognitive Services-instans

credential
TokenCredential

en TokenCredential-instans från @azure/identity paketet

options
DocumentAnalysisClientOptions

valfria inställningar för att konfigurera alla metoder i klienten

Metodinformation

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

Extrahera data från indata med hjälp av en modell som anges av dess unika ID.

Den här åtgärden stöder anpassade och fördefinierade modeller. Om du till exempel vill använda den fördefinierade fakturamodellen anger du modell-ID:t "prebuilt-invoice" eller för att använda den enklare fördefinierade layoutmodellen genom att ange modell-ID:t "prebuilt-layout".

De fält som skapas i AnalyzeResult beror på vilken modell som används för analys, och värdena i alla extraherade dokumentfält beror på dokumenttyperna i modellen (om sådana finns) och deras motsvarande fältscheman.

Exempel

Den här metoden stöder strömmande begärandeorgan (FormRecognizerRequestBody) som Node.JS ReadableStream objekt, webbläsare Bloboch ArrayBuffers. Innehållet i brödtexten laddas upp till tjänsten för analys.

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

Parametrar

modelId

string

modellens unika ID (namn) i den här klientens resurs

document
FormRecognizerRequestBody

en FormRecognizerRequestBody som laddas upp med begäran

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

valfria inställningar för analysåtgärden och poller

Returer

en långvarig åtgärd (poller) som så småningom skapar en AnalyzeResult

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

Extrahera data från indata med hjälp av en modell som har ett känt, starkt skrivet dokumentschema (en DocumentModel).

De fält som skapas i AnalyzeResult beror på vilken modell som används för analys. I TypeScript härleds typen av resultat för den här metodens överlagring från typen av indata DocumentModel.

Exempel

Den här metoden stöder strömmande begärandeorgan (FormRecognizerRequestBody) som Node.JS ReadableStream objekt, webbläsare Bloboch ArrayBuffers. Innehållet i brödtexten laddas upp till tjänsten för analys.

Om indata är en sträng behandlas den som en URL till platsen för ett dokument som ska analyseras. Mer information finns i metoden beginAnalyzeDocumentFromUrl . Du bör använda den metoden när du använder URL:er, och URL-stöd tillhandahålls endast i den här metoden för bakåtkompatibilitet.

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

Parametrar

model

DocumentModel<Result>

en DocumentModel som representerar modellen som ska användas för analys och förväntad utdatatyp

document
FormRecognizerRequestBody

en FormRecognizerRequestBody som laddas upp med begäran

options

AnalyzeDocumentOptions<Result>

valfria inställningar för analysåtgärden och poller

Returer

Promise<AnalysisPoller<Result>>

en långvarig åtgärd (poller) som så småningom skapar en AnalyzeResult med dokument som har den resultattyp som är associerad med indatamodellen

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

Extrahera data från indata med hjälp av en modell som anges av dess unika ID.

Den här åtgärden stöder anpassade och fördefinierade modeller. Om du till exempel vill använda den fördefinierade fakturamodellen anger du modell-ID:t "prebuilt-invoice" eller för att använda den enklare fördefinierade layoutmodellen genom att ange modell-ID:t "prebuilt-layout".

De fält som skapas i AnalyzeResult beror på vilken modell som används för analys, och värdena i alla extraherade dokumentfält beror på dokumenttyperna i modellen (om sådana finns) och deras motsvarande fältscheman.

Exempel

Den här metoden stöder extrahering av data från en fil på en viss URL. Den Formigenkänning tjänsten försöker ladda ned en fil med hjälp av den skickade URL:en, så URL:en måste vara tillgänglig från det offentliga Internet. En SAS-token kan till exempel användas för att bevilja läsbehörighet till en blob i Azure Storage, och tjänsten använder den SAS-kodade URL:en för att begära filen.

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

Parametrar

modelId

string

modellens unika ID (namn) i den här klientens resurs

documentUrl

string

en URL (sträng) till ett indatadokument som är tillgängligt från det offentliga Internet

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

valfria inställningar för analysåtgärden och poller

Returer

en långvarig åtgärd (poller) som så småningom skapar en AnalyzeResult

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

Extrahera data från indata med hjälp av en modell som har ett känt, starkt skrivet dokumentschema (en DocumentModel).

De fält som skapas i AnalyzeResult beror på vilken modell som används för analys. I TypeScript härleds typen av resultat för den här metodens överlagring från typen av indata DocumentModel.

Exempel

Den här metoden stöder extrahering av data från en fil på en viss URL. Den Formigenkänning tjänsten försöker ladda ned en fil med hjälp av den skickade URL:en, så URL:en måste vara tillgänglig från det offentliga Internet. En SAS-token kan till exempel användas för att bevilja läsbehörighet till en blob i Azure Storage, och tjänsten använder den SAS-kodade URL:en för att begära filen.

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

Parametrar

model

DocumentModel<Result>

en DocumentModel som representerar modellen som ska användas för analys och förväntad utdatatyp

documentUrl

string

en URL (sträng) till ett indatadokument som är tillgängligt från det offentliga Internet

options

AnalyzeDocumentOptions<Result>

valfria inställningar för analysåtgärden och poller

Returer

Promise<AnalysisPoller<Result>>

en långvarig åtgärd (poller) som så småningom skapar en AnalyzeResult

beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

Klassificera ett dokument med hjälp av en anpassad klassificerare som anges av dess ID.

Den här metoden skapar en tidskrävande åtgärd (poller) som så småningom skapar en AnalyzeResult. Det här är samma typ som beginAnalyzeDocument och beginAnalyzeDocumentFromUrl, men resultatet innehåller bara en liten delmängd av fälten. Endast fältet documents och pages fältet fylls i och endast minimal sidinformation returneras. Fältet documents innehåller information om alla identifierade dokument och docType att de har klassificerats som.

Exempel

Den här metoden stöder strömmande begärandeorgan (FormRecognizerRequestBody) som Node.JS ReadableStream objekt, webbläsare Bloboch ArrayBuffers. Innehållet i brödtexten laddas upp till tjänsten för analys.

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

Parametrar

classifierId

string

ID för den anpassade klassificeraren som ska användas för analys

document
FormRecognizerRequestBody

dokumentet som ska klassificeras

options
ClassifyDocumentOptions

alternativ för klassificeringsåtgärden

Returer

en långvarig åtgärd (poller) som så småningom skapar en AnalyzeResult

beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

Klassificera ett dokument från en URL med hjälp av en anpassad klassificerare som anges av dess ID.

Den här metoden skapar en tidskrävande åtgärd (poller) som så småningom skapar en AnalyzeResult. Det här är samma typ som beginAnalyzeDocument och beginAnalyzeDocumentFromUrl, men resultatet innehåller bara en liten delmängd av fälten. Endast fältet documents och pages fältet fylls i och endast minimal sidinformation returneras. Fältet documents innehåller information om alla identifierade dokument och docType att de har klassificerats som.

Exempel

Den här metoden stöder extrahering av data från en fil på en viss URL. Den Formigenkänning tjänsten försöker ladda ned en fil med hjälp av den skickade URL:en, så URL:en måste vara tillgänglig från det offentliga Internet. En SAS-token kan till exempel användas för att bevilja läsbehörighet till en blob i Azure Storage, och tjänsten använder den SAS-kodade URL:en för att begära filen.

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

Parametrar

classifierId

string

ID för den anpassade klassificeraren som ska användas för analys

documentUrl

string

URL:en för dokumentet som ska klassificeras

Returer