Skip to content

Commit

Permalink
[textanalytics] add support for custom text actions (#20721)
Browse files Browse the repository at this point in the history
* impl for custom actions sync/async + models

* remove project_name and deployment_name from result models

* update naming to classify documents

* add samples for arch board

* fix sample

* update naming to align with all langs

* update sample names

* arch board feedback

* rename samples and fix types

* regenerate on latest swagger

* add new tests and recordings

* make corrections to code based on renames

* remove samples from PR

* fix

* update changelog

* update missing docstrings

* bump azure-core for azure.core.rest
  • Loading branch information
kristapratico authored Oct 6, 2021
1 parent 971464e commit 9e882d7
Show file tree
Hide file tree
Showing 57 changed files with 11,963 additions and 4,982 deletions.
4 changes: 4 additions & 0 deletions sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
This version of the SDK defaults to the latest supported API version, which currently is `v3.2-preview.2`.

### Features Added
- Added support for Custom Entities Recognition through the `begin_analyze_actions` API with the `RecognizeCustomEntitiesAction` and `RecognizeCustomEntitiesResult` types.
- Added support for Custom Single Classification through the `begin_analyze_actions` API with the `SingleCategoryClassifyAction` and `SingleCategoryClassifyActionResult` types.
- Added support for Custom Multi Classification through the `begin_analyze_actions` API with the `MultiCategoryClassifyAction` and `MultiCategoryClassifyActionResult` types.

### Breaking Changes

### Bugs Fixed

### Other Changes
- Package requires [azure-core](https://pypi.org/project/azure-core/) version 1.16.0 or greater

## 5.2.0b1 (2021-08-09)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
ExtractSummaryAction,
ExtractSummaryResult,
SummarySentence,
RecognizeCustomEntitiesAction,
RecognizeCustomEntitiesResult,
SingleCategoryClassifyAction,
SingleCategoryClassifyResult,
MultiCategoryClassifyAction,
MultiCategoryClassifyResult,
ClassificationCategory,
)

from ._lro import AnalyzeHealthcareEntitiesLROPoller, AnalyzeActionsLROPoller
Expand Down Expand Up @@ -107,6 +114,13 @@
"ExtractSummaryAction",
"ExtractSummaryResult",
"SummarySentence",
"RecognizeCustomEntitiesAction",
"RecognizeCustomEntitiesResult",
"SingleCategoryClassifyAction",
"SingleCategoryClassifyResult",
"MultiCategoryClassifyAction",
"MultiCategoryClassifyResult",
"ClassificationCategory",
]

__version__ = VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def __init__(self, endpoint, credential, **kwargs):
credential=credential,
api_version=kwargs.pop("api_version", DEFAULT_API_VERSION),
sdk_moniker=USER_AGENT,
authentication_policy=_authentication_policy(credential),
custom_hook_policy=TextAnalyticsResponseHookPolicy(**kwargs),
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)),
custom_hook_policy=kwargs.pop("custom_hook_policy", TextAnalyticsResponseHookPolicy(**kwargs)),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@
# --------------------------------------------------------------------------
from msrest import Serializer, Deserializer
from typing import TYPE_CHECKING
import warnings

# FIXME: have to manually reconfigure import path for multiapi operation mixin
from .._lro import AnalyzeActionsLROPoller, AnalyzeActionsLROPollingMethod, AnalyzeHealthcareEntitiesLROPoller, AnalyzeHealthcareEntitiesLROPollingMethod
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import HttpRequest, HttpResponse
from azure.core.polling import LROPoller, NoPolling, PollingMethod
from azure.core.polling.base_polling import LROBasePolling

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union
from typing import Any, List, Optional, Union

# FIXME: have to manually reconfigure import path for multiapi operation mixin
from .._lro import AnalyzeActionsLROPoller, AnalyzeHealthcareEntitiesLROPoller
from azure.core.polling import LROPoller


class TextAnalyticsClientOperationsMixin(object):
Expand All @@ -35,6 +30,7 @@ def analyze_status(
skip=0, # type: Optional[int]
**kwargs # type: Any
):
# type: (...) -> "_models.AnalyzeJobState"
"""Get analysis status and results.
Get the status of an analysis job. A job may consist of one or more tasks. Once all tasks are
Expand Down Expand Up @@ -77,6 +73,7 @@ def begin_analyze(
body=None, # type: Optional["_models.AnalyzeBatchInput"]
**kwargs # type: Any
):
# type: (...) -> AnalyzeActionsLROPoller["_models.AnalyzeJobState"]
"""Submit analysis job.
Submit a collection of text documents for analysis. Specify one or more unique tasks to be
Expand All @@ -86,13 +83,17 @@ def begin_analyze(
:type body: ~azure.ai.textanalytics.v3_2_preview_2.models.AnalyzeBatchInput
: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: By default, your polling method will be AnalyzeActionsLROPollingMethod.
Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.
:keyword polling: By default, your polling method will be AnalyzeActionsLROPollingMethod. Pass
in False for this operation to not poll, or pass in your own initialized polling object for a
personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.PollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AnalyzeActionsLROPoller that returns either AnalyzeJobState or the result of cls(response)
:rtype: ~...._lro.AnalyzeActionsLROPoller[~azure.ai.textanalytics.v3_2_preview_2.models.AnalyzeJobState]
:raises ~azure.core.exceptions.HttpResponseError:
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
:return: An instance of AnalyzeActionsLROPoller that returns either AnalyzeJobState or the
result of cls(response)
:rtype:
~...._lro.AnalyzeActionsLROPoller[~azure.ai.textanalytics.v3_2_preview_2.models.AnalyzeJobState]
:raises: ~azure.core.exceptions.HttpResponseError
"""
api_version = self._get_api_version('begin_analyze')
if api_version == 'v3.1':
Expand All @@ -114,6 +115,7 @@ def begin_cancel_health_job(
job_id, # type: str
**kwargs # type: Any
):
# type: (...) -> LROPoller[None]
"""Cancel healthcare prediction job.
Cancel healthcare prediction job.
Expand All @@ -122,13 +124,15 @@ def begin_cancel_health_job(
:type job_id: str
: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: By default, your polling method will be LROBasePolling.
Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.
:keyword polling: By default, your polling method will be LROBasePolling. Pass in False for
this operation to not poll, or pass in your own initialized polling object for a personal
polling strategy.
:paramtype polling: bool or ~azure.core.polling.PollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
:return: An instance of LROPoller that returns either None or the result of cls(response)
:rtype: ~azure.core.polling.LROPoller[None]
:raises ~azure.core.exceptions.HttpResponseError:
:raises: ~azure.core.exceptions.HttpResponseError
"""
api_version = self._get_api_version('begin_cancel_health_job')
if api_version == 'v3.1':
Expand All @@ -153,6 +157,7 @@ def begin_health(
logging_opt_out=None, # type: Optional[bool]
**kwargs # type: Any
):
# type: (...) -> AnalyzeHealthcareEntitiesLROPoller["_models.HealthcareJobState"]
"""Submit healthcare analysis job.
Start a healthcare analysis job to recognize healthcare related entities (drugs, conditions,
Expand All @@ -177,13 +182,17 @@ def begin_health(
:type logging_opt_out: bool
: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: By default, your polling method will be AnalyzeHealthcareEntitiesLROPollingMethod.
Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.
:keyword polling: By default, your polling method will be
AnalyzeHealthcareEntitiesLROPollingMethod. Pass in False for this operation to not poll, or
pass in your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.PollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AnalyzeHealthcareEntitiesLROPoller that returns either HealthcareJobState or the result of cls(response)
:rtype: ~...._lro.AnalyzeHealthcareEntitiesLROPoller[~azure.ai.textanalytics.v3_2_preview_2.models.HealthcareJobState]
:raises ~azure.core.exceptions.HttpResponseError:
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
:return: An instance of AnalyzeHealthcareEntitiesLROPoller that returns either
HealthcareJobState or the result of cls(response)
:rtype:
~...._lro.AnalyzeHealthcareEntitiesLROPoller[~azure.ai.textanalytics.v3_2_preview_2.models.HealthcareJobState]
:raises: ~azure.core.exceptions.HttpResponseError
"""
api_version = self._get_api_version('begin_health')
if api_version == 'v3.1':
Expand All @@ -209,6 +218,7 @@ def entities_linking(
string_index_type=None, # type: Optional[Union[str, "_models.StringIndexType"]]
**kwargs # type: Any
):
# type: (...) -> "_models.EntityLinkingResult"
"""Linked entities from a well known knowledge base.
The API returns a list of recognized entities with links to a well known knowledge base. See
Expand Down Expand Up @@ -270,6 +280,7 @@ def entities_recognition_general(
string_index_type=None, # type: Optional[Union[str, "_models.StringIndexType"]]
**kwargs # type: Any
):
# type: (...) -> "_models.EntitiesResult"
"""Named Entity Recognition.
The API returns a list of general named entities in a given document. For the list of supported
Expand Down Expand Up @@ -334,6 +345,7 @@ def entities_recognition_pii(
pii_categories=None, # type: Optional[List[Union[str, "_models.PiiCategory"]]]
**kwargs # type: Any
):
# type: (...) -> "_models.PiiResult"
"""Entities containing personal information.
The API returns a list of entities with personal information (\"SSN\", \"Bank Account\" etc) in
Expand Down Expand Up @@ -395,6 +407,7 @@ def health_status(
show_stats=None, # type: Optional[bool]
**kwargs # type: Any
):
# type: (...) -> "_models.HealthcareJobState"
"""Get healthcare analysis job status and results.
Get details of the healthcare prediction job specified by the jobId.
Expand Down Expand Up @@ -438,6 +451,7 @@ def key_phrases(
logging_opt_out=None, # type: Optional[bool]
**kwargs # type: Any
):
# type: (...) -> "_models.KeyPhraseResult"
"""Key Phrases.
The API returns a list of strings denoting the key phrases in the input text. See the :code:`<a
Expand Down Expand Up @@ -494,6 +508,7 @@ def languages(
logging_opt_out=None, # type: Optional[bool]
**kwargs # type: Any
):
# type: (...) -> "_models.LanguageResult"
"""Detect Language.
The API returns the detected language and a numeric score between 0 and 1. Scores close to 1
Expand Down Expand Up @@ -553,6 +568,7 @@ def sentiment(
string_index_type=None, # type: Optional[Union[str, "_models.StringIndexType"]]
**kwargs # type: Any
):
# type: (...) -> "_models.SentimentResponse"
"""Sentiment.
The API returns a detailed sentiment analysis for the input text. The analysis is done in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from typing import Any, Optional

from azure.core.credentials import TokenCredential
from azure.core.pipeline.transport import HttpRequest, HttpResponse

class _SDKClient(object):
def __init__(self, *args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
# regenerated.
# --------------------------------------------------------------------------
from msrest import Serializer, Deserializer
from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union
import warnings
from typing import Any, List, Optional, Union

# FIXME: have to manually reconfigure import path for multiapi operation mixin
from ...aio._lro_async import AsyncAnalyzeHealthcareEntitiesLROPoller, AsyncAnalyzeHealthcareEntitiesLROPollingMethod, AsyncAnalyzeActionsLROPoller, AsyncAnalyzeActionsLROPollingMethod
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod
from azure.core.polling.async_base_polling import AsyncLROBasePolling
from azure.core.polling import AsyncLROPoller


class TextAnalyticsClientOperationsMixin(object):
Expand Down Expand Up @@ -83,12 +78,16 @@ async def begin_analyze(
: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: By default, your polling method will be AsyncAnalyzeActionsLROPollingMethod.
Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.
Pass in False for this operation to not poll, or pass in your own initialized polling object
for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncAnalyzeActionsLROPoller that returns either AnalyzeJobState or the result of cls(response)
:rtype: ~.....aio._lro_async.AsyncAnalyzeActionsLROPoller[~azure.ai.textanalytics.v3_2_preview_2.models.AnalyzeJobState]
:raises ~azure.core.exceptions.HttpResponseError:
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
:return: An instance of AsyncAnalyzeActionsLROPoller that returns either AnalyzeJobState or the
result of cls(response)
:rtype:
~.....aio._lro_async.AsyncAnalyzeActionsLROPoller[~azure.ai.textanalytics.v3_2_preview_2.models.AnalyzeJobState]
:raises: ~azure.core.exceptions.HttpResponseError
"""
api_version = self._get_api_version('begin_analyze')
if api_version == 'v3.1':
Expand Down Expand Up @@ -118,13 +117,15 @@ async def begin_cancel_health_job(
:type job_id: str
: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: By default, your polling method will be AsyncLROBasePolling.
Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.
:keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False
for this operation to not poll, or pass in your own initialized polling object for a personal
polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either None or the result of cls(response)
:rtype: ~azure.core.polling.AsyncLROPoller[None]
:raises ~azure.core.exceptions.HttpResponseError:
:raises: ~azure.core.exceptions.HttpResponseError
"""
api_version = self._get_api_version('begin_cancel_health_job')
if api_version == 'v3.1':
Expand Down Expand Up @@ -173,13 +174,17 @@ async def begin_health(
:type logging_opt_out: bool
: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: By default, your polling method will be AsyncAnalyzeHealthcareEntitiesLROPollingMethod.
Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.
:keyword polling: By default, your polling method will be
AsyncAnalyzeHealthcareEntitiesLROPollingMethod. Pass in False for this operation to not poll,
or pass in your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncAnalyzeHealthcareEntitiesLROPoller that returns either HealthcareJobState or the result of cls(response)
:rtype: ~.....aio._lro_async.AsyncAnalyzeHealthcareEntitiesLROPoller[~azure.ai.textanalytics.v3_2_preview_2.models.HealthcareJobState]
:raises ~azure.core.exceptions.HttpResponseError:
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
:return: An instance of AsyncAnalyzeHealthcareEntitiesLROPoller that returns either
HealthcareJobState or the result of cls(response)
:rtype:
~.....aio._lro_async.AsyncAnalyzeHealthcareEntitiesLROPoller[~azure.ai.textanalytics.v3_2_preview_2.models.HealthcareJobState]
:raises: ~azure.core.exceptions.HttpResponseError
"""
api_version = self._get_api_version('begin_health')
if api_version == 'v3.1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import Any, Optional, TYPE_CHECKING

from azure.core import AsyncPipelineClient
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
from azure.profiles import KnownProfiles, ProfileDefinition
from azure.profiles.multiapiclient import MultiApiClientMixin
from msrest import Deserializer, Serializer
Expand All @@ -22,6 +21,7 @@

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential
from azure.core.credentials_async import AsyncTokenCredential

class _SDKClient(object):
Expand Down
Loading

0 comments on commit 9e882d7

Please sign in to comment.