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

[text analytics] merge feature into master #15450

Merged
merged 18 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@
RecognizePiiEntitiesResult,
PiiEntity,
PiiEntityDomainType,
AnalyzeHealthcareResultItem,
HealthcareEntity,
HealthcareRelation,
HealthcareEntityLink,
EntitiesRecognitionTask,
PiiEntitiesRecognitionTask,
KeyPhraseExtractionTask,
TextAnalysisResult,
RequestStatistics
)
from._paging import AnalyzeHealthcareResult

__all__ = [
'TextAnalyticsApiVersion',
Expand Down Expand Up @@ -61,6 +71,16 @@
'RecognizePiiEntitiesResult',
'PiiEntity',
'PiiEntityDomainType',
'AnalyzeHealthcareResultItem',
'AnalyzeHealthcareResult',
'HealthcareEntity',
'HealthcareRelation',
'HealthcareEntityLink',
'EntitiesRecognitionTask',
'PiiEntitiesRecognitionTask',
'KeyPhraseExtractionTask',
'TextAnalysisResult',
'RequestStatistics'
]

__version__ = VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

from azure.core.polling.base_polling import OperationFailed, BadStatus
from azure.core.polling.async_base_polling import AsyncLROBasePolling


_FINISHED = frozenset(["succeeded", "cancelled", "failed", "partiallysucceeded"])
_FAILED = frozenset(["failed"])
_SUCCEEDED = frozenset(["succeeded", "partiallysucceeded"])


class TextAnalyticsAsyncLROPollingMethod(AsyncLROBasePolling):

def finished(self):
"""Is this polling finished?
:rtype: bool
"""
return TextAnalyticsAsyncLROPollingMethod._finished(self.status())

@staticmethod
def _finished(status):
if hasattr(status, "value"):
status = status.value
return str(status).lower() in _FINISHED

@staticmethod
def _failed(status):
if hasattr(status, "value"):
status = status.value
return str(status).lower() in _FAILED

@staticmethod
def _raise_if_bad_http_status_and_method(response):
"""Check response status code is valid.

Must be 200, 201, 202, or 204.

:raises: BadStatus if invalid status.
"""
code = response.status_code
if code in {200, 201, 202, 204}:
return
raise BadStatus(
"Invalid return status {!r} for {!r} operation".format(
code, response.request.method
)
)

async def _poll(self): # pylint:disable=invalid-overridden-method
"""Poll status of operation so long as operation is incomplete and
we have an endpoint to query.

:param callable update_cmd: The function to call to retrieve the
latest status of the long running operation.
:raises: OperationFailed if operation status 'Failed' or 'Canceled'.
:raises: BadStatus if response status invalid.
:raises: BadResponse if response invalid.
"""
while not self.finished():
await self._delay()
await self.update_status()

if TextAnalyticsAsyncLROPollingMethod._failed(self.status()):
raise OperationFailed("Operation failed or canceled")

final_get_url = self._operation.get_final_get_url(self._pipeline_response)
if final_get_url:
self._pipeline_response = await self.request_status(final_get_url)
TextAnalyticsAsyncLROPollingMethod._raise_if_bad_http_status_and_method(
self._pipeline_response.http_response
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

from azure.core.async_paging import AsyncItemPaged


class AnalyzeHealthcareResultAsync(AsyncItemPaged):
def __init__(self, *args, **kwargs):
self.model_version = kwargs.pop('model_version')
self.statistics = kwargs.pop('statistics')
super(AnalyzeHealthcareResultAsync, self).__init__(*args, **kwargs)


class AnalyzeResultAsync(AsyncItemPaged):
def __init__(self, *args, **kwargs):
self.statistics = kwargs.pop('statistics')
super(AnalyzeResultAsync, self).__init__(*args, **kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class TextAnalyticsApiVersion(str, Enum):
"""Text Analytics API versions supported by this package"""

V3_1_PREVIEW_3 = "v3.1-preview.3"

#: this is the default version
V3_1_PREVIEW = "v3.1-preview.2"
V3_0 = "v3.0"
Expand Down
Loading