Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[formrecognizer] adds language param #14984

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ also be populated with any selection marks found on the page
- Added keyword argument `pages` to `begin_recognize_content` and `begin_recognize_content_from_url` to specify the page
numbers to analyze
- Added property `bounding_box` to `FormTable`
- Content-type `image/bmp` now supported by all recognize methods

- Content-type `image/bmp` now supported by recognize content and prebuilt models
- Added keyword argument `language` to `begin_recognize_content` and `begin_recognize_content_from_url` to specify
which language to process document in

**Dependency updates**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ def begin_recognize_content(self, form, **kwargs):
:keyword list[str] pages: Custom page numbers for multi-page documents(PDF/TIFF), input the number of the
pages you want to get OCR result. For a range of pages, use a hyphen. Separate each page or
range with a comma.
:keyword str language: The BCP-47 language code of the text in the document. Currently, only English
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this docstring more like locale with just the shorter list of the language codes?

:keyword str locale: Locale of the receipt. Supported locales include: en-US, en-AU, en-CA, en-GB,

('en'), Dutch ('nl'), French ('fr'), German ('de'), Italian ('it'), Portuguese ('pt'),
simplified Chinese ('zh-Hans') and Spanish ('es') are supported. For handwritten text,
only English is supported currently. Content supports auto language identification and multilanguage
documents, so only provide a language code if you would like to force the documented to be
processed as that specific language.
:keyword content_type: Content-type of the body sent to the API. Content-type is
auto-detected, but can be overridden by passing this keyword argument. For options,
see :class:`~azure.ai.formrecognizer.FormContentType`.
Expand All @@ -441,7 +447,7 @@ def begin_recognize_content(self, form, **kwargs):
:rtype: ~azure.core.polling.LROPoller[list[~azure.ai.formrecognizer.FormPage]]
:raises ~azure.core.exceptions.HttpResponseError:
.. versionadded:: v2.1-preview
The *pages* keyword argument
The *pages* and *language* keyword arguments

.. admonition:: Example:

Expand All @@ -453,6 +459,7 @@ def begin_recognize_content(self, form, **kwargs):
:caption: Recognize text and content/layout information from a form.
"""
pages = kwargs.pop("pages", None)
language = kwargs.pop("language", None)
content_type = kwargs.pop("content_type", None)
if content_type == "application/json":
raise TypeError("Call begin_recognize_content_from_url() to analyze a document from a URL.")
Expand All @@ -468,6 +475,12 @@ def begin_recognize_content(self, form, **kwargs):
else:
raise ValueError("'pages' is only available for API version V2_1_PREVIEW and up")

if language:
if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW:
kwargs.update({"language": language})
else:
raise ValueError("'language' is only available for API version V2_1_PREVIEW and up")

return self._client.begin_analyze_layout_async( # type: ignore
file_stream=form,
content_type=content_type,
Expand All @@ -487,6 +500,12 @@ def begin_recognize_content_from_url(self, form_url, **kwargs):
:keyword list[str] pages: Custom page numbers for multi-page documents(PDF/TIFF), input the number of the
pages you want to get OCR result. For a range of pages, use a hyphen. Separate each page or
range with a comma.
:keyword str language: The BCP-47 language code of the text in the document. Currently, only English
('en'), Dutch ('nl'), French ('fr'), German ('de'), Italian ('it'), Portuguese ('pt'),
simplified Chinese ('zh-Hans') and Spanish ('es') are supported. For handwritten text,
only English is supported currently. Content supports auto language identification and multilanguage
documents, so only provide a language code if you would like to force the documented to be
processed as that specific language.
:keyword int polling_interval: Waiting time between two polls for LRO operations
if no Retry-After header is present. Defaults to 5 seconds.
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
Expand All @@ -495,9 +514,10 @@ def begin_recognize_content_from_url(self, form_url, **kwargs):
:rtype: ~azure.core.polling.LROPoller[list[~azure.ai.formrecognizer.FormPage]]
:raises ~azure.core.exceptions.HttpResponseError:
.. versionadded:: v2.1-preview
The *pages* keyword argument
The *pages* and *language* keyword arguments
"""
pages = kwargs.pop("pages", None)
language = kwargs.pop("language", None)

# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
Expand All @@ -507,6 +527,12 @@ def begin_recognize_content_from_url(self, form_url, **kwargs):
else:
raise ValueError("'pages' is only available for API version V2_1_PREVIEW and up")

if language:
if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW:
kwargs.update({"language": language})
else:
raise ValueError("'language' is only available for API version V2_1_PREVIEW and up")

return self._client.begin_analyze_layout_async( # type: ignore
file_stream={"source": form_url},
cls=kwargs.pop("cls", self._content_callback),
Expand All @@ -520,10 +546,10 @@ def begin_recognize_custom_forms(self, model_id, form, **kwargs):
"""Analyze a custom form with a model trained with or without labels. The form
to analyze should be of the same type as the forms that were used to train the model.
The input document must be of one of the supported content types - 'application/pdf',
'image/jpeg', 'image/png', 'image/tiff' or 'image/bmp'.
'image/jpeg', 'image/png', or 'image/tiff'.
maririos marked this conversation as resolved.
Show resolved Hide resolved

:param str model_id: Custom model identifier.
:param form: JPEG, PNG, PDF, TIFF, or BMP type file stream or bytes.
:param form: JPEG, PNG, PDF, or TIFF type file stream or bytes.
:type form: bytes or IO[bytes]
:keyword bool include_field_elements:
Whether or not to include field elements such as lines and words in addition to form fields.
Expand Down Expand Up @@ -586,7 +612,7 @@ def begin_recognize_custom_forms_from_url(self, model_id, form_url, **kwargs):

:param str model_id: Custom model identifier.
:param str form_url: The URL of the form to analyze. The input must be a valid, encoded URL
of one of the supported formats: JPEG, PNG, PDF, TIFF, or BMP.
of one of the supported formats: JPEG, PNG, PDF, or TIFF.
:keyword bool include_field_elements:
Whether or not to include field elements such as lines and words in addition to form fields.
:keyword int polling_interval: Waiting time between two polls for LRO operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FormRecognizerClientOperationsMixin(object):
def begin_analyze_business_card_async(
self,
include_text_details=False, # type: Optional[bool]
locale=None, # type: Optional[str]
locale=None, # type: Optional[Union[str, "models.Locale"]]
file_stream=None, # type: Optional[Union[IO, "models.SourcePath"]]
**kwargs # type: Any
):
Expand All @@ -42,9 +42,9 @@ def begin_analyze_business_card_async(

:param include_text_details: Include text lines and element references in the result.
:type include_text_details: bool
:param locale: Locale of the business card. Supported locales include: en-AU, en-CA, en-GB, en-
IN, en-US(default).
:type locale: str
:param locale: Locale of the input document. Supported locales include: en-AU, en-CA, en-GB,
en-IN, en-US(default).
maririos marked this conversation as resolved.
Show resolved Hide resolved
:type locale: str or ~azure.ai.formrecognizer.models.Locale
:param file_stream: .json, .pdf, .jpg, .png or .tiff type file stream.
:type file_stream: IO or ~azure.ai.formrecognizer.models.SourcePath
:keyword str content_type: Media type of the body sent to the API. Default value is "application/json".
Expand Down Expand Up @@ -75,7 +75,7 @@ def begin_analyze_business_card_async(
def begin_analyze_invoice_async(
self,
include_text_details=False, # type: Optional[bool]
locale=None, # type: Optional[str]
locale=None, # type: Optional[Union[str, "models.Locale"]]
file_stream=None, # type: Optional[Union[IO, "models.SourcePath"]]
**kwargs # type: Any
):
Expand All @@ -88,9 +88,9 @@ def begin_analyze_invoice_async(

:param include_text_details: Include text lines and element references in the result.
:type include_text_details: bool
:param locale: Locale of the invoice. Supported locales include: en-AU, en-CA, en-GB, en-IN,
en-US(default).
:type locale: str
:param locale: Locale of the input document. Supported locales include: en-AU, en-CA, en-GB,
en-IN, en-US(default).
:type locale: str or ~azure.ai.formrecognizer.models.Locale
:param file_stream: .json, .pdf, .jpg, .png or .tiff type file stream.
:type file_stream: IO or ~azure.ai.formrecognizer.models.SourcePath
:keyword str content_type: Media type of the body sent to the API. Default value is "application/json".
Expand Down Expand Up @@ -120,6 +120,7 @@ def begin_analyze_invoice_async(

def begin_analyze_layout_async(
self,
language=None, # type: Optional[Union[str, "models.Language"]]
pages=None, # type: Optional[List[str]]
file_stream=None, # type: Optional[Union[IO, "models.SourcePath"]]
**kwargs # type: Any
Expand All @@ -131,6 +132,13 @@ def begin_analyze_layout_async(
'image/bmp'. Alternatively, use 'application/json' type to specify the location (Uri or local
path) of the document to be analyzed.

:param language: The BCP-47 language code of the text in the document. Currently, only English
('en'), Dutch (‘nl’), French (‘fr’), German (‘de’), Italian (‘it’), Portuguese (‘pt'),
simplified Chinese ('zh-Hans') and Spanish ('es') are supported (print – nine languages and
handwritten – English only). Layout supports auto language identification and multi language
documents, so only provide a language code if you would like to force the documented to be
processed as that specific language.
:type language: str or ~azure.ai.formrecognizer.models.Language
:param pages: Custom page numbers for multi-page documents(PDF/TIFF), input the number of the
pages you want to get OCR result. For a range of pages, use a hyphen. Separate each page or
range with a comma or space.
Expand Down Expand Up @@ -166,12 +174,12 @@ def begin_analyze_layout_async(
if api_version == '2.0':
return mixin_instance.begin_analyze_layout_async(file_stream, **kwargs)
elif api_version == '2.1-preview.2':
return mixin_instance.begin_analyze_layout_async(pages, file_stream, **kwargs)
return mixin_instance.begin_analyze_layout_async(language, pages, file_stream, **kwargs)

def begin_analyze_receipt_async(
self,
include_text_details=False, # type: Optional[bool]
locale=None, # type: Optional[str]
locale=None, # type: Optional[Union[str, "models.Locale"]]
file_stream=None, # type: Optional[Union[IO, "models.SourcePath"]]
**kwargs # type: Any
):
Expand All @@ -184,9 +192,9 @@ def begin_analyze_receipt_async(

:param include_text_details: Include text lines and element references in the result.
:type include_text_details: bool
:param locale: Locale of the receipt. Supported locales include: en-AU, en-CA, en-GB, en-IN,
en-US(default).
:type locale: str
:param locale: Locale of the input document. Supported locales include: en-AU, en-CA, en-GB,
en-IN, en-US(default).
:type locale: str or ~azure.ai.formrecognizer.models.Locale
:param file_stream: .json, .pdf, .jpg, .png or .tiff type file stream.
:type file_stream: IO or ~azure.ai.formrecognizer.models.SourcePath
:keyword str content_type: Media type of the body sent to the API. Default value is "application/json".
Expand Down Expand Up @@ -241,7 +249,7 @@ def begin_analyze_with_custom_model(
:param file_stream: .json, .pdf, .jpg, .png or .tiff type file stream.
:type file_stream: IO or ~azure.ai.formrecognizer.models.SourcePath
:keyword str content_type: Media type of the body sent to the API. Default value is "application/json".
Allowed values are: "application/pdf", "image/bmp", "image/jpeg", "image/png", "image/tiff", "application/json".
Allowed values are: "application/pdf", "image/jpeg", "image/png", "image/tiff", "application/json".
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FormRecognizerClientOperationsMixin(object):
async def begin_analyze_business_card_async(
self,
include_text_details: Optional[bool] = False,
locale: Optional[str] = None,
locale: Optional[Union[str, "models.Locale"]] = None,
file_stream: Optional[Union[IO, "models.SourcePath"]] = None,
**kwargs
) -> AsyncLROPoller[None]:
Expand All @@ -38,9 +38,9 @@ async def begin_analyze_business_card_async(

:param include_text_details: Include text lines and element references in the result.
:type include_text_details: bool
:param locale: Locale of the business card. Supported locales include: en-AU, en-CA, en-GB, en-
IN, en-US(default).
:type locale: str
:param locale: Locale of the input document. Supported locales include: en-AU, en-CA, en-GB,
en-IN, en-US(default).
:type locale: str or ~azure.ai.formrecognizer.models.Locale
:param file_stream: .json, .pdf, .jpg, .png or .tiff type file stream.
:type file_stream: IO or ~azure.ai.formrecognizer.models.SourcePath
:keyword str content_type: Media type of the body sent to the API. Default value is "application/json".
Expand Down Expand Up @@ -71,7 +71,7 @@ async def begin_analyze_business_card_async(
async def begin_analyze_invoice_async(
self,
include_text_details: Optional[bool] = False,
locale: Optional[str] = None,
locale: Optional[Union[str, "models.Locale"]] = None,
file_stream: Optional[Union[IO, "models.SourcePath"]] = None,
**kwargs
) -> AsyncLROPoller[None]:
Expand All @@ -84,9 +84,9 @@ async def begin_analyze_invoice_async(

:param include_text_details: Include text lines and element references in the result.
:type include_text_details: bool
:param locale: Locale of the invoice. Supported locales include: en-AU, en-CA, en-GB, en-IN,
en-US(default).
:type locale: str
:param locale: Locale of the input document. Supported locales include: en-AU, en-CA, en-GB,
en-IN, en-US(default).
:type locale: str or ~azure.ai.formrecognizer.models.Locale
:param file_stream: .json, .pdf, .jpg, .png or .tiff type file stream.
:type file_stream: IO or ~azure.ai.formrecognizer.models.SourcePath
:keyword str content_type: Media type of the body sent to the API. Default value is "application/json".
Expand Down Expand Up @@ -116,6 +116,7 @@ async def begin_analyze_invoice_async(

async def begin_analyze_layout_async(
self,
language: Optional[Union[str, "models.Language"]] = None,
pages: Optional[List[str]] = None,
file_stream: Optional[Union[IO, "models.SourcePath"]] = None,
**kwargs
Expand All @@ -127,6 +128,13 @@ async def begin_analyze_layout_async(
'image/bmp'. Alternatively, use 'application/json' type to specify the location (Uri or local
path) of the document to be analyzed.

:param language: The BCP-47 language code of the text in the document. Currently, only English
('en'), Dutch (‘nl’), French (‘fr’), German (‘de’), Italian (‘it’), Portuguese (‘pt'),
simplified Chinese ('zh-Hans') and Spanish ('es') are supported (print – nine languages and
handwritten – English only). Layout supports auto language identification and multi language
documents, so only provide a language code if you would like to force the documented to be
processed as that specific language.
:type language: str or ~azure.ai.formrecognizer.models.Language
:param pages: Custom page numbers for multi-page documents(PDF/TIFF), input the number of the
pages you want to get OCR result. For a range of pages, use a hyphen. Separate each page or
range with a comma or space.
Expand Down Expand Up @@ -162,12 +170,12 @@ async def begin_analyze_layout_async(
if api_version == '2.0':
return await mixin_instance.begin_analyze_layout_async(file_stream, **kwargs)
elif api_version == '2.1-preview.2':
return await mixin_instance.begin_analyze_layout_async(pages, file_stream, **kwargs)
return await mixin_instance.begin_analyze_layout_async(language, pages, file_stream, **kwargs)

async def begin_analyze_receipt_async(
self,
include_text_details: Optional[bool] = False,
locale: Optional[str] = None,
locale: Optional[Union[str, "models.Locale"]] = None,
file_stream: Optional[Union[IO, "models.SourcePath"]] = None,
**kwargs
) -> AsyncLROPoller[None]:
Expand All @@ -180,9 +188,9 @@ async def begin_analyze_receipt_async(

:param include_text_details: Include text lines and element references in the result.
:type include_text_details: bool
:param locale: Locale of the receipt. Supported locales include: en-AU, en-CA, en-GB, en-IN,
en-US(default).
:type locale: str
:param locale: Locale of the input document. Supported locales include: en-AU, en-CA, en-GB,
en-IN, en-US(default).
:type locale: str or ~azure.ai.formrecognizer.models.Locale
:param file_stream: .json, .pdf, .jpg, .png or .tiff type file stream.
:type file_stream: IO or ~azure.ai.formrecognizer.models.SourcePath
:keyword str content_type: Media type of the body sent to the API. Default value is "application/json".
Expand Down Expand Up @@ -237,7 +245,7 @@ async def begin_analyze_with_custom_model(
:param file_stream: .json, .pdf, .jpg, .png or .tiff type file stream.
:type file_stream: IO or ~azure.ai.formrecognizer.models.SourcePath
:keyword str content_type: Media type of the body sent to the API. Default value is "application/json".
Allowed values are: "application/pdf", "image/bmp", "image/jpeg", "image/png", "image/tiff", "application/json".
Allowed values are: "application/pdf", "image/jpeg", "image/png", "image/tiff", "application/json".
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
Expand Down
Loading