FormRecognizerClient Kelas

FormRecognizerClient mengekstrak informasi dari formulir dan gambar ke dalam data terstruktur. Ini adalah antarmuka yang digunakan untuk menganalisis dengan model bawaan (tanda terima, kartu nama, faktur, dokumen identitas), mengenali konten/tata letak dari formulir, dan menganalisis formulir kustom dari model terlatih. Ini menyediakan metode yang berbeda berdasarkan input dari URL dan input dari aliran.

Catatan

FormRecognizerClient harus digunakan dengan versi <API =v2.1.

Untuk menggunakan API versi 2022-08-31 dan yang lebih baru, buat instans DocumentAnalysisClient.

Warisan
azure.ai.formrecognizer._form_base_client.FormRecognizerClientBase
FormRecognizerClient

Konstruktor

FormRecognizerClient(endpoint: str, credential: AzureKeyCredential | TokenCredential, **kwargs: Any)

Parameter

endpoint
str
Diperlukan

Titik akhir Cognitive Services yang didukung (protokol dan nama host, misalnya: https://westus2.api.cognitive.microsoft.com).

credential
AzureKeyCredential atau TokenCredential
Diperlukan

Kredensial yang diperlukan agar klien terhubung ke Azure. Ini adalah instans AzureKeyCredential jika menggunakan kunci API atau kredensial token dari identity.

api_version
str atau FormRecognizerApiVersion

Versi API layanan yang digunakan untuk permintaan. Ini default ke API versi v2.1. Pengaturan ke versi yang lebih lama dapat mengakibatkan kompatibilitas fitur yang berkurang. Untuk menggunakan versi dan fitur API terbaru yang didukung, buat instans DocumentAnalysisClient sebagai gantinya.

Contoh

Membuat FormRecognizerClient dengan titik akhir dan kunci API.


   from azure.core.credentials import AzureKeyCredential
   from azure.ai.formrecognizer import FormRecognizerClient
   endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
   key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

   form_recognizer_client = FormRecognizerClient(endpoint, AzureKeyCredential(key))

Membuat FormRecognizerClient dengan kredensial token.


   """DefaultAzureCredential will use the values from these environment
   variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
   """
   from azure.ai.formrecognizer import FormRecognizerClient
   from azure.identity import DefaultAzureCredential

   endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
   credential = DefaultAzureCredential()

   form_recognizer_client = FormRecognizerClient(endpoint, credential)

Metode

begin_recognize_business_cards

Ekstrak teks bidang dan nilai semantik dari kartu nama tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Lihat bidang yang ditemukan di kartu nama di sini: https://aka.ms/formrecognizer/businesscardfields

Baru dalam versi v2.1: Metode klien begin_recognize_business_cards

begin_recognize_business_cards_from_url

Ekstrak teks bidang dan nilai semantik dari kartu nama tertentu. Dokumen input harus berupa lokasi (URL) kartu yang akan dianalisis.

Lihat bidang yang ditemukan di kartu nama di sini: https://aka.ms/formrecognizer/businesscardfields

Baru dalam versi v2.1: Metode klien begin_recognize_business_cards_from_url

begin_recognize_content

Ekstrak informasi teks dan konten/tata letak dari dokumen tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Baru dalam versi v2.1 : Halaman,bahasa , dan reading_order argumen kata kunci dan dukungan untuk konten gambar/bmp

begin_recognize_content_from_url

Ekstrak teks dan informasi tata letak dari dokumen tertentu. Dokumen input harus berupa lokasi (URL) dokumen yang akan dianalisis.

Baru dalam versi v2.1 : Halaman,bahasa , dan reading_order argumen kata kunci dan dukungan untuk konten gambar/bmp

begin_recognize_custom_forms

Menganalisis formulir kustom dengan model yang dilatih dengan atau tanpa label. Formulir untuk dianalisis harus berjenis sama dengan formulir yang digunakan untuk melatih model. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff', atau 'image/bmp'.

begin_recognize_custom_forms_from_url

Menganalisis formulir kustom dengan model yang dilatih dengan atau tanpa label. Formulir untuk dianalisis harus berjenis sama dengan formulir yang digunakan untuk melatih model. Dokumen input harus menjadi lokasi (URL) dokumen yang akan dianalisis.

begin_recognize_identity_documents

Ekstrak teks bidang dan nilai semantik dari dokumen identitas tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Lihat bidang yang ditemukan pada dokumen identitas di sini: https://aka.ms/formrecognizer/iddocumentfields

Baru dalam versi v2.1: Metode klien begin_recognize_identity_documents

begin_recognize_identity_documents_from_url

Ekstrak teks bidang dan nilai semantik dari dokumen identitas tertentu. Dokumen input harus menjadi lokasi (URL) dokumen identitas yang akan dianalisis.

Lihat bidang yang ditemukan pada dokumen identitas di sini: https://aka.ms/formrecognizer/iddocumentfields

Baru dalam versi v2.1: Metode klien begin_recognize_identity_documents_from_url

begin_recognize_invoices

Ekstrak teks bidang dan nilai semantik dari faktur tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Lihat bidang yang ditemukan pada faktur di sini: https://aka.ms/formrecognizer/invoicefields

Baru dalam versi v2.1: Metode klien begin_recognize_invoices

begin_recognize_invoices_from_url

Ekstrak teks bidang dan nilai semantik dari faktur tertentu. Dokumen input harus menjadi lokasi (URL) faktur yang akan dianalisis.

Lihat bidang yang ditemukan pada kartu faktur di sini: https://aka.ms/formrecognizer/invoicefields

Baru dalam versi v2.1: Metode klien begin_recognize_invoices_from_url

begin_recognize_receipts

Ekstrak teks bidang dan nilai semantik dari tanda terima penjualan tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Lihat bidang yang ditemukan pada tanda terima di sini: https://aka.ms/formrecognizer/receiptfields

Baru dalam versi v2.1: Argumen dan dukungan kata kunci lokal dan halaman untuk konten gambar/bmp

begin_recognize_receipts_from_url

Ekstrak teks bidang dan nilai semantik dari tanda terima penjualan tertentu. Dokumen input harus menjadi lokasi (URL) tanda terima yang akan dianalisis.

Lihat bidang yang ditemukan pada tanda terima di sini: https://aka.ms/formrecognizer/receiptfields

Baru dalam versi v2.1: Argumen dan dukungan kata kunci lokal dan halaman untuk konten gambar/bmp

close

FormRecognizerClient Tutup sesi.

send_request

Menjalankan permintaan jaringan menggunakan alur klien yang ada.

URL permintaan dapat relatif terhadap URL dasar. Versi API layanan yang digunakan untuk permintaan sama dengan klien kecuali ditentukan lain. Mengambil alih versi API klien yang dikonfigurasi di URL relatif didukung pada klien dengan API versi 2022-08-31 dan yang lebih baru. Mengambil alih URL absolut yang didukung pada klien dengan versi API apa pun. Metode ini tidak menaikkan jika responsnya adalah kesalahan; untuk menaikkan pengecualian, panggil raise_for_status() pada objek respons yang dikembalikan. Untuk informasi selengkapnya tentang cara mengirim permintaan kustom dengan metode ini, lihat https://aka.ms/azsdk/dpcodegen/python/send_request.

begin_recognize_business_cards

Ekstrak teks bidang dan nilai semantik dari kartu nama tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Lihat bidang yang ditemukan di kartu nama di sini: https://aka.ms/formrecognizer/businesscardfields

Baru dalam versi v2.1: Metode klien begin_recognize_business_cards

begin_recognize_business_cards(business_card: bytes | IO[bytes], **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

business_card
bytes atau IO[bytes]
Diperlukan

Aliran atau byte file jenis JPEG, PNG, PDF, TIFF, atau BMP.

locale
str

Lokal kartu nama. Lokal yang didukung meliputi: en-US, en-AU, en-CA, en-GB, dan en-IN.

include_field_elements
bool

Apakah menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

content_type
str atau FormContentType

Jenis konten isi yang dikirim ke API. Jenis konten terdeteksi secara otomatis, tetapi dapat ditimpa dengan meneruskan argumen kata kunci ini. Untuk opsi, lihat FormContentType.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

Contoh

Mengenali kartu nama dari file.


   from azure.core.credentials import AzureKeyCredential
   from azure.ai.formrecognizer import FormRecognizerClient

   endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
   key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

   form_recognizer_client = FormRecognizerClient(
       endpoint=endpoint, credential=AzureKeyCredential(key)
   )
   with open(path_to_sample_forms, "rb") as f:
       poller = form_recognizer_client.begin_recognize_business_cards(business_card=f, locale="en-US")
   business_cards = poller.result()

   for idx, business_card in enumerate(business_cards):
       print("--------Recognizing business card #{}--------".format(idx+1))
       contact_names = business_card.fields.get("ContactNames")
       if contact_names:
           for contact_name in contact_names.value:
               print("Contact First Name: {} has confidence: {}".format(
                   contact_name.value["FirstName"].value, contact_name.value["FirstName"].confidence
               ))
               print("Contact Last Name: {} has confidence: {}".format(
                   contact_name.value["LastName"].value, contact_name.value["LastName"].confidence
               ))
       company_names = business_card.fields.get("CompanyNames")
       if company_names:
           for company_name in company_names.value:
               print("Company Name: {} has confidence: {}".format(company_name.value, company_name.confidence))
       departments = business_card.fields.get("Departments")
       if departments:
           for department in departments.value:
               print("Department: {} has confidence: {}".format(department.value, department.confidence))
       job_titles = business_card.fields.get("JobTitles")
       if job_titles:
           for job_title in job_titles.value:
               print("Job Title: {} has confidence: {}".format(job_title.value, job_title.confidence))
       emails = business_card.fields.get("Emails")
       if emails:
           for email in emails.value:
               print("Email: {} has confidence: {}".format(email.value, email.confidence))
       websites = business_card.fields.get("Websites")
       if websites:
           for website in websites.value:
               print("Website: {} has confidence: {}".format(website.value, website.confidence))
       addresses = business_card.fields.get("Addresses")
       if addresses:
           for address in addresses.value:
               print("Address: {} has confidence: {}".format(address.value, address.confidence))
       mobile_phones = business_card.fields.get("MobilePhones")
       if mobile_phones:
           for phone in mobile_phones.value:
               print("Mobile phone number: {} has confidence: {}".format(phone.value, phone.confidence))
       faxes = business_card.fields.get("Faxes")
       if faxes:
           for fax in faxes.value:
               print("Fax number: {} has confidence: {}".format(fax.value, fax.confidence))
       work_phones = business_card.fields.get("WorkPhones")
       if work_phones:
           for work_phone in work_phones.value:
               print("Work phone number: {} has confidence: {}".format(work_phone.value, work_phone.confidence))
       other_phones = business_card.fields.get("OtherPhones")
       if other_phones:
           for other_phone in other_phones.value:
               print("Other phone number: {} has confidence: {}".format(other_phone.value, other_phone.confidence))

begin_recognize_business_cards_from_url

Ekstrak teks bidang dan nilai semantik dari kartu nama tertentu. Dokumen input harus berupa lokasi (URL) kartu yang akan dianalisis.

Lihat bidang yang ditemukan di kartu nama di sini: https://aka.ms/formrecognizer/businesscardfields

Baru dalam versi v2.1: Metode klien begin_recognize_business_cards_from_url

begin_recognize_business_cards_from_url(business_card_url: str, **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

business_card_url
str
Diperlukan

URL kartu nama yang akan dianalisis. Input harus berupa URL yang valid dan dikodekan dari salah satu format yang didukung: JPEG, PNG, PDF, TIFF, atau BMP.

locale
str

Lokal kartu nama. Lokal yang didukung meliputi: en-US, en-AU, en-CA, en-GB, dan en-IN.

include_field_elements
bool

Apakah menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

begin_recognize_content

Ekstrak informasi teks dan konten/tata letak dari dokumen tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Baru dalam versi v2.1 : Halaman,bahasa , dan reading_order argumen kata kunci dan dukungan untuk konten gambar/bmp

begin_recognize_content(form: bytes | IO[bytes], **kwargs: Any) -> LROPoller[List[FormPage]]

Parameter

form
bytes atau IO[bytes]
Diperlukan

Aliran atau byte file jenis JPEG, PNG, PDF, TIFF, atau BMP.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

language
str

Kode bahasa BCP-47 dari teks dalam dokumen. Lihat kode bahasa yang didukung di sini: https://docs.microsoft.com/azure/cognitive-services/form-recognizer/language-support. Konten mendukung identifikasi bahasa otomatis dan dokumen multibahasa, jadi hanya berikan kode bahasa jika Anda ingin memaksa dokumen diproses sebagai bahasa tertentu.

reading_order
str

Algoritma urutan baca untuk mengurutkan baris teks yang dikembalikan. Urutan bacaan yang didukung meliputi: dasar (default), alami. Atur 'dasar' untuk mengurutkan garis kiri ke kanan dan atas ke bawah, meskipun dalam beberapa kasus kedekatan diperlakukan dengan prioritas yang lebih tinggi. Atur 'natural' untuk mengurutkan garis dengan menggunakan informasi posisi untuk menyaingkan garis terdekat.

content_type
str atau FormContentType

Jenis konten isi yang dikirim ke API. Jenis konten terdeteksi secara otomatis, tetapi dapat ditimpa dengan meneruskan argumen kata kunci ini. Untuk opsi, lihat FormContentType.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[FormPage].

Tipe hasil

Pengecualian

Contoh

Mengenali informasi teks dan konten/tata letak dari formulir.


   from azure.core.credentials import AzureKeyCredential
   from azure.ai.formrecognizer import FormRecognizerClient

   endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
   key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

   form_recognizer_client = FormRecognizerClient(endpoint=endpoint, credential=AzureKeyCredential(key))
   with open(path_to_sample_forms, "rb") as f:
       poller = form_recognizer_client.begin_recognize_content(form=f)
   form_pages = poller.result()

   for idx, content in enumerate(form_pages):
       print("----Recognizing content from page #{}----".format(idx+1))
       print("Page has width: {} and height: {}, measured with unit: {}".format(
           content.width,
           content.height,
           content.unit
       ))
       for table_idx, table in enumerate(content.tables):
           print("Table # {} has {} rows and {} columns".format(table_idx, table.row_count, table.column_count))
           print("Table # {} location on page: {}".format(table_idx, format_bounding_box(table.bounding_box)))
           for cell in table.cells:
               print("...Cell[{}][{}] has text '{}' within bounding box '{}'".format(
                   cell.row_index,
                   cell.column_index,
                   cell.text,
                   format_bounding_box(cell.bounding_box)
               ))

       for line_idx, line in enumerate(content.lines):
           print("Line # {} has word count '{}' and text '{}' within bounding box '{}'".format(
               line_idx,
               len(line.words),
               line.text,
               format_bounding_box(line.bounding_box)
           ))
           if line.appearance:
               if line.appearance.style_name == "handwriting" and line.appearance.style_confidence > 0.8:
                   print("Text line '{}' is handwritten and might be a signature.".format(line.text))
           for word in line.words:
               print("...Word '{}' has a confidence of {}".format(word.text, word.confidence))

       for selection_mark in content.selection_marks:
           print("Selection mark is '{}' within bounding box '{}' and has a confidence of {}".format(
               selection_mark.state,
               format_bounding_box(selection_mark.bounding_box),
               selection_mark.confidence
           ))
       print("----------------------------------------")


begin_recognize_content_from_url

Ekstrak teks dan informasi tata letak dari dokumen tertentu. Dokumen input harus berupa lokasi (URL) dokumen yang akan dianalisis.

Baru dalam versi v2.1 : Halaman,bahasa , dan reading_order argumen kata kunci dan dukungan untuk konten gambar/bmp

begin_recognize_content_from_url(form_url: str, **kwargs: Any) -> LROPoller[List[FormPage]]

Parameter

form_url
str
Diperlukan

URL formulir yang akan dianalisis. Input harus berupa URL yang valid dan dikodekan dari salah satu format yang didukung: JPEG, PNG, PDF, TIFF, atau BMP.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

language
str

Kode bahasa BCP-47 dari teks dalam dokumen. Lihat kode bahasa yang didukung di sini: https://docs.microsoft.com/azure/cognitive-services/form-recognizer/language-support. Konten mendukung identifikasi bahasa otomatis dan dokumen multibahasa, jadi hanya berikan kode bahasa jika Anda ingin memaksa dokumen diproses sebagai bahasa tertentu.

reading_order
str

Algoritma urutan baca untuk mengurutkan baris teks yang dikembalikan. Urutan bacaan yang didukung meliputi: dasar (default), alami. Atur 'dasar' untuk mengurutkan garis kiri ke kanan dan atas ke bawah, meskipun dalam beberapa kasus kedekatan diperlakukan dengan prioritas yang lebih tinggi. Atur 'natural' untuk mengurutkan garis dengan menggunakan informasi posisi untuk menyaingkan garis terdekat.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[FormPage].

Tipe hasil

Pengecualian

begin_recognize_custom_forms

Menganalisis formulir kustom dengan model yang dilatih dengan atau tanpa label. Formulir untuk dianalisis harus berjenis sama dengan formulir yang digunakan untuk melatih model. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff', atau 'image/bmp'.

begin_recognize_custom_forms(model_id: str, form: bytes | IO[bytes], **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

model_id
str
Diperlukan

Pengidentifikasi model kustom.

form
bytes atau IO[bytes]
Diperlukan

JPEG, PNG, PDF, TIFF, atau BMP jenis aliran file atau byte.

include_field_elements
bool

Apakah akan menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

content_type
str atau FormContentType

Jenis konten isi yang dikirim ke API. Tipe konten terdeteksi otomatis, tetapi dapat ditimpa dengan meneruskan argumen kata kunci ini. Untuk opsi, lihat FormContentType.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

Contoh

Mengenali bidang dan nilai dari formulir kustom.


   from azure.core.credentials import AzureKeyCredential
   from azure.ai.formrecognizer import FormRecognizerClient

   endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
   key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]
   model_id = os.getenv("CUSTOM_TRAINED_MODEL_ID", custom_model_id)

   form_recognizer_client = FormRecognizerClient(
       endpoint=endpoint, credential=AzureKeyCredential(key)
   )

   # Make sure your form's type is included in the list of form types the custom model can recognize
   with open(path_to_sample_forms, "rb") as f:
       poller = form_recognizer_client.begin_recognize_custom_forms(
           model_id=model_id, form=f, include_field_elements=True
       )
   forms = poller.result()

   for idx, form in enumerate(forms):
       print("--------Recognizing Form #{}--------".format(idx+1))
       print("Form has type {}".format(form.form_type))
       print("Form has form type confidence {}".format(form.form_type_confidence))
       print("Form was analyzed with model with ID {}".format(form.model_id))
       for name, field in form.fields.items():
           # each field is of type FormField
           # label_data is populated if you are using a model trained without labels,
           # since the service needs to make predictions for labels if not explicitly given to it.
           if field.label_data:
               print("...Field '{}' has label '{}' with a confidence score of {}".format(
                   name,
                   field.label_data.text,
                   field.confidence
               ))

           print("...Label '{}' has value '{}' with a confidence score of {}".format(
               field.label_data.text if field.label_data else name, field.value, field.confidence
           ))

       # iterate over tables, lines, and selection marks on each page
       for page in form.pages:
           for i, table in enumerate(page.tables):
               print("\nTable {} on page {}".format(i+1, table.page_number))
               for cell in table.cells:
                   print("...Cell[{}][{}] has text '{}' with confidence {}".format(
                       cell.row_index, cell.column_index, cell.text, cell.confidence
                   ))
           print("\nLines found on page {}".format(page.page_number))
           for line in page.lines:
               print("...Line '{}' is made up of the following words: ".format(line.text))
               for word in line.words:
                   print("......Word '{}' has a confidence of {}".format(
                       word.text,
                       word.confidence
                   ))
           if page.selection_marks:
               print("\nSelection marks found on page {}".format(page.page_number))
               for selection_mark in page.selection_marks:
                   print("......Selection mark is '{}' and has a confidence of {}".format(
                       selection_mark.state,
                       selection_mark.confidence
                   ))

       print("-----------------------------------")

begin_recognize_custom_forms_from_url

Menganalisis formulir kustom dengan model yang dilatih dengan atau tanpa label. Formulir untuk dianalisis harus berjenis sama dengan formulir yang digunakan untuk melatih model. Dokumen input harus menjadi lokasi (URL) dokumen yang akan dianalisis.

begin_recognize_custom_forms_from_url(model_id: str, form_url: str, **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

model_id
str
Diperlukan

Pengidentifikasi model kustom.

form_url
str
Diperlukan

URL formulir yang akan dianalisis. Input harus berupa URL yang valid dan dikodekan dari salah satu format yang didukung: JPEG, PNG, PDF, TIFF, atau BMP.

include_field_elements
bool

Apakah akan menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

begin_recognize_identity_documents

Ekstrak teks bidang dan nilai semantik dari dokumen identitas tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Lihat bidang yang ditemukan pada dokumen identitas di sini: https://aka.ms/formrecognizer/iddocumentfields

Baru dalam versi v2.1: Metode klien begin_recognize_identity_documents

begin_recognize_identity_documents(identity_document: bytes | IO[bytes], **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

identity_document
bytes atau IO[bytes]
Diperlukan

JPEG, PNG, PDF, TIFF, atau BMP jenis aliran file atau byte.

include_field_elements
bool

Apakah akan menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

content_type
str atau FormContentType

Jenis konten isi yang dikirim ke API. Tipe konten terdeteksi otomatis, tetapi dapat ditimpa dengan meneruskan argumen kata kunci ini. Untuk opsi, lihat FormContentType.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

Contoh

Mengenali bidang dokumen identitas.


   from azure.core.credentials import AzureKeyCredential
   from azure.ai.formrecognizer import FormRecognizerClient

   endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
   key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

   form_recognizer_client = FormRecognizerClient(
       endpoint=endpoint, credential=AzureKeyCredential(key)
   )
   with open(path_to_sample_forms, "rb") as f:
       poller = form_recognizer_client.begin_recognize_identity_documents(identity_document=f)
   id_documents = poller.result()

   for idx, id_document in enumerate(id_documents):
       print("--------Recognizing ID document #{}--------".format(idx+1))
       first_name = id_document.fields.get("FirstName")
       if first_name:
           print("First Name: {} has confidence: {}".format(first_name.value, first_name.confidence))
       last_name = id_document.fields.get("LastName")
       if last_name:
           print("Last Name: {} has confidence: {}".format(last_name.value, last_name.confidence))
       document_number = id_document.fields.get("DocumentNumber")
       if document_number:
           print("Document Number: {} has confidence: {}".format(document_number.value, document_number.confidence))
       dob = id_document.fields.get("DateOfBirth")
       if dob:
           print("Date of Birth: {} has confidence: {}".format(dob.value, dob.confidence))
       doe = id_document.fields.get("DateOfExpiration")
       if doe:
           print("Date of Expiration: {} has confidence: {}".format(doe.value, doe.confidence))
       sex = id_document.fields.get("Sex")
       if sex:
           print("Sex: {} has confidence: {}".format(sex.value, sex.confidence))
       address = id_document.fields.get("Address")
       if address:
           print("Address: {} has confidence: {}".format(address.value, address.confidence))
       country_region = id_document.fields.get("CountryRegion")
       if country_region:
           print("Country/Region: {} has confidence: {}".format(country_region.value, country_region.confidence))
       region = id_document.fields.get("Region")
       if region:
           print("Region: {} has confidence: {}".format(region.value, region.confidence))

begin_recognize_identity_documents_from_url

Ekstrak teks bidang dan nilai semantik dari dokumen identitas tertentu. Dokumen input harus menjadi lokasi (URL) dokumen identitas yang akan dianalisis.

Lihat bidang yang ditemukan pada dokumen identitas di sini: https://aka.ms/formrecognizer/iddocumentfields

Baru dalam versi v2.1: Metode klien begin_recognize_identity_documents_from_url

begin_recognize_identity_documents_from_url(identity_document_url: str, **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

identity_document_url
str
Diperlukan

URL dokumen identitas yang akan dianalisis. Input harus berupa URL yang valid dan dikodekan dari salah satu format yang didukung: JPEG, PNG, PDF, TIFF, atau BMP.

include_field_elements
bool

Apakah akan menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

begin_recognize_invoices

Ekstrak teks bidang dan nilai semantik dari faktur tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Lihat bidang yang ditemukan pada faktur di sini: https://aka.ms/formrecognizer/invoicefields

Baru dalam versi v2.1: Metode klien begin_recognize_invoices

begin_recognize_invoices(invoice: bytes | IO[bytes], **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

invoice
bytes atau IO[bytes]
Diperlukan

JPEG, PNG, PDF, TIFF, atau BMP jenis aliran file atau byte.

locale
str

Lokal faktur. Lokal yang didukung meliputi: en-US

include_field_elements
bool

Apakah akan menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

content_type
str atau FormContentType

Jenis konten isi yang dikirim ke API. Tipe konten terdeteksi otomatis, tetapi dapat ditimpa dengan meneruskan argumen kata kunci ini. Untuk opsi, lihat FormContentType.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

Contoh

Mengenali faktur dari file.


   from azure.core.credentials import AzureKeyCredential
   from azure.ai.formrecognizer import FormRecognizerClient

   endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
   key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

   form_recognizer_client = FormRecognizerClient(
       endpoint=endpoint, credential=AzureKeyCredential(key)
   )
   with open(path_to_sample_forms, "rb") as f:
       poller = form_recognizer_client.begin_recognize_invoices(invoice=f, locale="en-US")
   invoices = poller.result()

   for idx, invoice in enumerate(invoices):
       print("--------Recognizing invoice #{}--------".format(idx+1))
       vendor_name = invoice.fields.get("VendorName")
       if vendor_name:
           print("Vendor Name: {} has confidence: {}".format(vendor_name.value, vendor_name.confidence))
       vendor_address = invoice.fields.get("VendorAddress")
       if vendor_address:
           print("Vendor Address: {} has confidence: {}".format(vendor_address.value, vendor_address.confidence))
       vendor_address_recipient = invoice.fields.get("VendorAddressRecipient")
       if vendor_address_recipient:
           print("Vendor Address Recipient: {} has confidence: {}".format(vendor_address_recipient.value, vendor_address_recipient.confidence))
       customer_name = invoice.fields.get("CustomerName")
       if customer_name:
           print("Customer Name: {} has confidence: {}".format(customer_name.value, customer_name.confidence))
       customer_id = invoice.fields.get("CustomerId")
       if customer_id:
           print("Customer Id: {} has confidence: {}".format(customer_id.value, customer_id.confidence))
       customer_address = invoice.fields.get("CustomerAddress")
       if customer_address:
           print("Customer Address: {} has confidence: {}".format(customer_address.value, customer_address.confidence))
       customer_address_recipient = invoice.fields.get("CustomerAddressRecipient")
       if customer_address_recipient:
           print("Customer Address Recipient: {} has confidence: {}".format(customer_address_recipient.value, customer_address_recipient.confidence))
       invoice_id = invoice.fields.get("InvoiceId")
       if invoice_id:
           print("Invoice Id: {} has confidence: {}".format(invoice_id.value, invoice_id.confidence))
       invoice_date = invoice.fields.get("InvoiceDate")
       if invoice_date:
           print("Invoice Date: {} has confidence: {}".format(invoice_date.value, invoice_date.confidence))
       invoice_total = invoice.fields.get("InvoiceTotal")
       if invoice_total:
           print("Invoice Total: {} has confidence: {}".format(invoice_total.value, invoice_total.confidence))
       due_date = invoice.fields.get("DueDate")
       if due_date:
           print("Due Date: {} has confidence: {}".format(due_date.value, due_date.confidence))
       purchase_order = invoice.fields.get("PurchaseOrder")
       if purchase_order:
           print("Purchase Order: {} has confidence: {}".format(purchase_order.value, purchase_order.confidence))
       billing_address = invoice.fields.get("BillingAddress")
       if billing_address:
           print("Billing Address: {} has confidence: {}".format(billing_address.value, billing_address.confidence))
       billing_address_recipient = invoice.fields.get("BillingAddressRecipient")
       if billing_address_recipient:
           print("Billing Address Recipient: {} has confidence: {}".format(billing_address_recipient.value, billing_address_recipient.confidence))
       shipping_address = invoice.fields.get("ShippingAddress")
       if shipping_address:
           print("Shipping Address: {} has confidence: {}".format(shipping_address.value, shipping_address.confidence))
       shipping_address_recipient = invoice.fields.get("ShippingAddressRecipient")
       if shipping_address_recipient:
           print("Shipping Address Recipient: {} has confidence: {}".format(shipping_address_recipient.value, shipping_address_recipient.confidence))
       print("Invoice items:")
       for idx, item in enumerate(invoice.fields.get("Items").value):
           print("...Item #{}".format(idx+1))
           item_description = item.value.get("Description")
           if item_description:
               print("......Description: {} has confidence: {}".format(item_description.value, item_description.confidence))
           item_quantity = item.value.get("Quantity")
           if item_quantity:
               print("......Quantity: {} has confidence: {}".format(item_quantity.value, item_quantity.confidence))
           unit = item.value.get("Unit")
           if unit:
               print("......Unit: {} has confidence: {}".format(unit.value, unit.confidence))
           unit_price = item.value.get("UnitPrice")
           if unit_price:
               print("......Unit Price: {} has confidence: {}".format(unit_price.value, unit_price.confidence))
           product_code = item.value.get("ProductCode")
           if product_code:
               print("......Product Code: {} has confidence: {}".format(product_code.value, product_code.confidence))
           item_date = item.value.get("Date")
           if item_date:
               print("......Date: {} has confidence: {}".format(item_date.value, item_date.confidence))
           tax = item.value.get("Tax")
           if tax:
               print("......Tax: {} has confidence: {}".format(tax.value, tax.confidence))
           amount = item.value.get("Amount")
           if amount:
               print("......Amount: {} has confidence: {}".format(amount.value, amount.confidence))
       subtotal = invoice.fields.get("SubTotal")
       if subtotal:
           print("Subtotal: {} has confidence: {}".format(subtotal.value, subtotal.confidence))
       total_tax = invoice.fields.get("TotalTax")
       if total_tax:
           print("Total Tax: {} has confidence: {}".format(total_tax.value, total_tax.confidence))
       previous_unpaid_balance = invoice.fields.get("PreviousUnpaidBalance")
       if previous_unpaid_balance:
           print("Previous Unpaid Balance: {} has confidence: {}".format(previous_unpaid_balance.value, previous_unpaid_balance.confidence))
       amount_due = invoice.fields.get("AmountDue")
       if amount_due:
           print("Amount Due: {} has confidence: {}".format(amount_due.value, amount_due.confidence))
       service_start_date = invoice.fields.get("ServiceStartDate")
       if service_start_date:
           print("Service Start Date: {} has confidence: {}".format(service_start_date.value, service_start_date.confidence))
       service_end_date = invoice.fields.get("ServiceEndDate")
       if service_end_date:
           print("Service End Date: {} has confidence: {}".format(service_end_date.value, service_end_date.confidence))
       service_address = invoice.fields.get("ServiceAddress")
       if service_address:
           print("Service Address: {} has confidence: {}".format(service_address.value, service_address.confidence))
       service_address_recipient = invoice.fields.get("ServiceAddressRecipient")
       if service_address_recipient:
           print("Service Address Recipient: {} has confidence: {}".format(service_address_recipient.value, service_address_recipient.confidence))
       remittance_address = invoice.fields.get("RemittanceAddress")
       if remittance_address:
           print("Remittance Address: {} has confidence: {}".format(remittance_address.value, remittance_address.confidence))
       remittance_address_recipient = invoice.fields.get("RemittanceAddressRecipient")
       if remittance_address_recipient:
           print("Remittance Address Recipient: {} has confidence: {}".format(remittance_address_recipient.value, remittance_address_recipient.confidence))

begin_recognize_invoices_from_url

Ekstrak teks bidang dan nilai semantik dari faktur tertentu. Dokumen input harus menjadi lokasi (URL) faktur yang akan dianalisis.

Lihat bidang yang ditemukan pada kartu faktur di sini: https://aka.ms/formrecognizer/invoicefields

Baru dalam versi v2.1: Metode klien begin_recognize_invoices_from_url

begin_recognize_invoices_from_url(invoice_url: str, **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

invoice_url
str
Diperlukan

URL faktur yang akan dianalisis. Input harus berupa URL yang valid dan dikodekan dari salah satu format yang didukung: JPEG, PNG, PDF, TIFF, atau BMP.

locale
str

Lokal faktur. Lokal yang didukung meliputi: en-US

include_field_elements
bool

Apakah akan menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

begin_recognize_receipts

Ekstrak teks bidang dan nilai semantik dari tanda terima penjualan tertentu. Dokumen input harus dari salah satu jenis konten yang didukung - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff' atau 'image/bmp'.

Lihat bidang yang ditemukan pada tanda terima di sini: https://aka.ms/formrecognizer/receiptfields

Baru dalam versi v2.1: Argumen dan dukungan kata kunci lokal dan halaman untuk konten gambar/bmp

begin_recognize_receipts(receipt: bytes | IO[bytes], **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

receipt
bytes atau IO[bytes]
Diperlukan

JPEG, PNG, PDF, TIFF, atau BMP jenis aliran file atau byte.

include_field_elements
bool

Apakah akan menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

content_type
str atau FormContentType

Jenis konten isi yang dikirim ke API. Tipe konten terdeteksi otomatis, tetapi dapat ditimpa dengan meneruskan argumen kata kunci ini. Untuk opsi, lihat FormContentType.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

locale
str

Lokal tanda terima. Lokal yang didukung meliputi: en-US, en-AU, en-CA, en-GB, dan en-IN.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

Contoh

Mengenali bidang tanda terima penjualan.


   from azure.core.credentials import AzureKeyCredential
   from azure.ai.formrecognizer import FormRecognizerClient

   endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
   key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

   form_recognizer_client = FormRecognizerClient(
       endpoint=endpoint, credential=AzureKeyCredential(key)
   )
   with open(path_to_sample_forms, "rb") as f:
       poller = form_recognizer_client.begin_recognize_receipts(receipt=f, locale="en-US")
   receipts = poller.result()

   for idx, receipt in enumerate(receipts):
       print("--------Recognizing receipt #{}--------".format(idx+1))
       receipt_type = receipt.fields.get("ReceiptType")
       if receipt_type:
           print("Receipt Type: {} has confidence: {}".format(receipt_type.value, receipt_type.confidence))
       merchant_name = receipt.fields.get("MerchantName")
       if merchant_name:
           print("Merchant Name: {} has confidence: {}".format(merchant_name.value, merchant_name.confidence))
       transaction_date = receipt.fields.get("TransactionDate")
       if transaction_date:
           print("Transaction Date: {} has confidence: {}".format(transaction_date.value, transaction_date.confidence))
       if receipt.fields.get("Items"):
           print("Receipt items:")
           for idx, item in enumerate(receipt.fields.get("Items").value):
               print("...Item #{}".format(idx+1))
               item_name = item.value.get("Name")
               if item_name:
                   print("......Item Name: {} has confidence: {}".format(item_name.value, item_name.confidence))
               item_quantity = item.value.get("Quantity")
               if item_quantity:
                   print("......Item Quantity: {} has confidence: {}".format(item_quantity.value, item_quantity.confidence))
               item_price = item.value.get("Price")
               if item_price:
                   print("......Individual Item Price: {} has confidence: {}".format(item_price.value, item_price.confidence))
               item_total_price = item.value.get("TotalPrice")
               if item_total_price:
                   print("......Total Item Price: {} has confidence: {}".format(item_total_price.value, item_total_price.confidence))
       subtotal = receipt.fields.get("Subtotal")
       if subtotal:
           print("Subtotal: {} has confidence: {}".format(subtotal.value, subtotal.confidence))
       tax = receipt.fields.get("Tax")
       if tax:
           print("Tax: {} has confidence: {}".format(tax.value, tax.confidence))
       tip = receipt.fields.get("Tip")
       if tip:
           print("Tip: {} has confidence: {}".format(tip.value, tip.confidence))
       total = receipt.fields.get("Total")
       if total:
           print("Total: {} has confidence: {}".format(total.value, total.confidence))
       print("--------------------------------------")

begin_recognize_receipts_from_url

Ekstrak teks bidang dan nilai semantik dari tanda terima penjualan tertentu. Dokumen input harus menjadi lokasi (URL) tanda terima yang akan dianalisis.

Lihat bidang yang ditemukan pada tanda terima di sini: https://aka.ms/formrecognizer/receiptfields

Baru dalam versi v2.1: Argumen dan dukungan kata kunci lokal dan halaman untuk konten gambar/bmp

begin_recognize_receipts_from_url(receipt_url: str, **kwargs: Any) -> LROPoller[List[RecognizedForm]]

Parameter

receipt_url
str
Diperlukan

URL tanda terima yang akan dianalisis. Input harus berupa URL yang valid dan dikodekan dari salah satu format yang didukung: JPEG, PNG, PDF, TIFF, atau BMP.

include_field_elements
bool

Apakah akan menyertakan semua baris per halaman dan elemen bidang seperti baris, kata, dan tanda pilihan untuk setiap bidang formulir atau tidak.

continuation_token
str

Token kelanjutan untuk memulai ulang poller dari status tersimpan.

locale
str

Lokal tanda terima. Lokal yang didukung meliputi: en-US, en-AU, en-CA, en-GB, dan en-IN.

pages
list[str]

Nomor halaman kustom untuk dokumen multi-halaman (PDF/TIFF). Masukkan nomor halaman dan/atau rentang halaman yang ingin Anda dapatkan dalam hasilnya. Untuk rentang halaman, gunakan tanda hubung, seperti pages=["1-3", "5-6"]. Pisahkan setiap nomor halaman atau rentang dengan koma.

Mengembalikan

Instans LROPoller. Panggil result() pada objek poller untuk mengembalikan daftar[RecognizedForm].

Tipe hasil

Pengecualian

Contoh

Mengenali bidang tanda terima penjualan dari URL.


   from azure.core.credentials import AzureKeyCredential
   from azure.ai.formrecognizer import FormRecognizerClient

   endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
   key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

   form_recognizer_client = FormRecognizerClient(
       endpoint=endpoint, credential=AzureKeyCredential(key)
   )
   url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-receipt.png"
   poller = form_recognizer_client.begin_recognize_receipts_from_url(receipt_url=url)
   receipts = poller.result()

   for idx, receipt in enumerate(receipts):
       print("--------Recognizing receipt #{}--------".format(idx+1))
       receipt_type = receipt.fields.get("ReceiptType")
       if receipt_type:
           print("Receipt Type: {} has confidence: {}".format(receipt_type.value, receipt_type.confidence))
       merchant_name = receipt.fields.get("MerchantName")
       if merchant_name:
           print("Merchant Name: {} has confidence: {}".format(merchant_name.value, merchant_name.confidence))
       transaction_date = receipt.fields.get("TransactionDate")
       if transaction_date:
           print("Transaction Date: {} has confidence: {}".format(transaction_date.value, transaction_date.confidence))
       if receipt.fields.get("Items"):
           print("Receipt items:")
           for idx, item in enumerate(receipt.fields.get("Items").value):
               print("...Item #{}".format(idx+1))
               item_name = item.value.get("Name")
               if item_name:
                   print("......Item Name: {} has confidence: {}".format(item_name.value, item_name.confidence))
               item_quantity = item.value.get("Quantity")
               if item_quantity:
                   print("......Item Quantity: {} has confidence: {}".format(item_quantity.value, item_quantity.confidence))
               item_price = item.value.get("Price")
               if item_price:
                   print("......Individual Item Price: {} has confidence: {}".format(item_price.value, item_price.confidence))
               item_total_price = item.value.get("TotalPrice")
               if item_total_price:
                   print("......Total Item Price: {} has confidence: {}".format(item_total_price.value, item_total_price.confidence))
       subtotal = receipt.fields.get("Subtotal")
       if subtotal:
           print("Subtotal: {} has confidence: {}".format(subtotal.value, subtotal.confidence))
       tax = receipt.fields.get("Tax")
       if tax:
           print("Tax: {} has confidence: {}".format(tax.value, tax.confidence))
       tip = receipt.fields.get("Tip")
       if tip:
           print("Tip: {} has confidence: {}".format(tip.value, tip.confidence))
       total = receipt.fields.get("Total")
       if total:
           print("Total: {} has confidence: {}".format(total.value, total.confidence))
       print("--------------------------------------")

close

FormRecognizerClient Tutup sesi.

close() -> None

Pengecualian

send_request

Menjalankan permintaan jaringan menggunakan alur klien yang ada.

URL permintaan dapat relatif terhadap URL dasar. Versi API layanan yang digunakan untuk permintaan sama dengan klien kecuali ditentukan lain. Mengambil alih versi API klien yang dikonfigurasi di URL relatif didukung pada klien dengan API versi 2022-08-31 dan yang lebih baru. Mengambil alih URL absolut yang didukung pada klien dengan versi API apa pun. Metode ini tidak menaikkan jika responsnya adalah kesalahan; untuk menaikkan pengecualian, panggil raise_for_status() pada objek respons yang dikembalikan. Untuk informasi selengkapnya tentang cara mengirim permintaan kustom dengan metode ini, lihat https://aka.ms/azsdk/dpcodegen/python/send_request.

send_request(request: HttpRequest, *, stream: bool = False, **kwargs) -> HttpResponse

Parameter

request
HttpRequest
Diperlukan

Permintaan jaringan yang ingin Anda buat.

stream
bool

Apakah payload respons akan dialirkan. Default ke False.

Mengembalikan

Respons panggilan jaringan Anda. Tidak melakukan penanganan kesalahan pada respons Anda.

Tipe hasil

Pengecualian