def test_polling_interval(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key), polling_interval=7) self.assertEqual(client._client._config.polling_interval, 7) poller = client.begin_recognize_business_cards_from_url(self.business_card_url_jpg, polling_interval=6) poller.wait() self.assertEqual(poller._polling_method._timeout, 6) poller2 = client.begin_recognize_business_cards_from_url(self.business_card_url_jpg) poller2.wait() self.assertEqual(poller2._polling_method._timeout, 7) # goes back to client default
def test_authentication_bad_key(self, formrecognizer_test_endpoint, formrecognizer_test_api_key): client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential("xxxx")) with self.assertRaises(ClientAuthenticationError): poller = client.begin_recognize_business_cards_from_url( self.business_card_url_jpg)
def test_authentication_bad_key(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential("xxxx")) with self.assertRaises(ClientAuthenticationError): poller = client.begin_recognize_business_cards_from_url( self.business_card_url_jpg)
def test_business_card_url_bad_endpoint(self, formrecognizer_test_endpoint, formrecognizer_test_api_key): with self.assertRaises(ServiceRequestError): client = FormRecognizerClient( "http://notreal.azure.com", AzureKeyCredential(formrecognizer_test_api_key)) poller = client.begin_recognize_business_cards_from_url( self.business_card_url_jpg)
if name == "Items": print("Receipt Items:") for idx, items in enumerate(field.value): print("...Item #{}".format(idx + 1)) for item_name, item in items.value.items(): print("......{}: {} has confidence {}".format( item_name, item.value, item.confidence)) else: print("{}: {} has confidence {}".format(name, field.value, field.confidence)) # </snippet_receipts> # <snippet_bc> bcUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/master/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/business_cards/business-card-english.jpg" poller = form_recognizer_client.begin_recognize_business_cards_from_url(bcUrl) 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: