-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[text analytics] Updates to Healthcare design #16247
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
Changes from 2 commits
c00140c
e69151c
d005b70
ac9faf0
078e875
c2a09ff
fb37651
f827c6b
864b1b2
2649001
eed2d38
429c4ea
ef6c210
91ba6a1
a78decd
7da7797
0a14704
d952ded
82bc4e4
03d68a7
00c00a5
f2dedef
bae8200
4563059
f9e5776
3745666
0971671
7771a70
acc58ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| _get_deserialize | ||
| ) | ||
| from ._lro import TextAnalyticsOperationResourcePolling, TextAnalyticsLROPollingMethod | ||
| from ._models import AnalyzeHealthcareEntitiesOperation | ||
|
|
||
| if TYPE_CHECKING: | ||
| from azure.core.credentials import TokenCredential, AzureKeyCredential | ||
|
|
@@ -49,7 +50,6 @@ | |
| EntitiesRecognitionTask, | ||
| PiiEntitiesRecognitionTask, | ||
| KeyPhraseExtractionTask, | ||
| AnalyzeHealthcareResultItem, | ||
| TextAnalysisResult | ||
| ) | ||
|
|
||
|
|
@@ -406,11 +406,11 @@ def _healthcare_result_callback(self, doc_id_order, raw_response, _, headers, sh | |
| ) | ||
|
|
||
| @distributed_trace | ||
| def begin_analyze_healthcare( # type: ignore | ||
| def begin_analyze_healthcare_entities( # type: ignore | ||
| self, | ||
| documents, # type: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]] | ||
| **kwargs # type: Any | ||
| ): # type: (...) -> LROPoller[ItemPaged[AnalyzeHealthcareResultItem]] | ||
| ): # type: (...) -> AnalyzeHealthcareEntitiesOperation[ItemPaged[AnalyzeHealthcareResultItem]] | ||
| """Analyze healthcare entities and identify relationships between these entities in a batch of documents. | ||
|
|
||
| Entities are associated with references that can be found in existing knowledge bases, | ||
|
|
@@ -433,8 +433,8 @@ def begin_analyze_healthcare( # type: ignore | |
| :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. | ||
| :return: An instance of an LROPoller. Call `result()` on the poller | ||
| object to return a list[:class:`~azure.ai.textanalytics.AnalyzeHealthcareResultItem`]. | ||
| :return: An instance of an AnalyzeHealthcareEntitiesOperation. Call `get_result()` on the this | ||
| object to return a list[:class:`~azure.ai.textanalytics.AnalyzeHealthcareEntitiesResultItem`]. | ||
| :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError or NotImplementedError: | ||
|
|
||
| .. admonition:: Example: | ||
|
|
@@ -457,7 +457,7 @@ def begin_analyze_healthcare( # type: ignore | |
| doc_id_order = [doc.get("id") for doc in docs] | ||
|
|
||
| try: | ||
| return self._client.begin_health( | ||
| poller = self._client.begin_health( | ||
| docs, | ||
| model_version=model_version, | ||
| string_index_type=self._string_code_unit, | ||
|
|
@@ -471,28 +471,31 @@ def begin_analyze_healthcare( # type: ignore | |
| continuation_token=continuation_token, | ||
| **kwargs | ||
| ) | ||
| return AnalyzeHealthcareEntitiesOperation(poller=poller) | ||
|
|
||
| except ValueError as error: | ||
| if "API version v3.0 does not have operation 'begin_health'" in str(error): | ||
| raise ValueError( | ||
| "'begin_analyze_healthcare' endpoint is only available for API version v3.1-preview.3" | ||
| "'begin_analyze_healthcare_entities' method is only available for API version \ | ||
| v3.1-preview.3 and up." | ||
| ) | ||
| raise error | ||
|
|
||
| except HttpResponseError as error: | ||
| process_http_response_error(error) | ||
|
|
||
| def begin_cancel_analyze_healthcare( # type: ignore | ||
| def begin_cancel_analyze_healthcare_entities_operation( # type: ignore | ||
| self, | ||
| poller, # type: LROPoller[ItemPaged[AnalyzeHealthcareResultItem]] | ||
| healthcare_operation, # type: AnalyzeHealthcareEntitiesOperation[ItemPaged[AnalyzeHealthcareResultItem]] | ||
| **kwargs | ||
| ): | ||
| # type: (...) -> LROPoller[None] | ||
| # type: (...) -> Union[None, LROPoller[None]] | ||
| """Cancel an existing health operation. | ||
|
|
||
| :param poller: The LRO poller object associated with the health operation. | ||
| :return: An instance of an LROPoller that returns None. | ||
| :rtype: ~azure.core.polling.LROPoller[None] | ||
| :param healthcare_operation: The operation to cancel. | ||
| :return: If the operation is already in a terminal state returns None, otherwise returns an instance | ||
| of an LROPoller that returns None. | ||
| :rtype: Union[None, ~azure.core.polling.LROPoller[None]] | ||
| :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError or NotImplementedError: | ||
|
|
||
| .. admonition:: Example: | ||
|
|
@@ -505,20 +508,33 @@ def begin_cancel_analyze_healthcare( # type: ignore | |
| :caption: Cancel an existing health operation. | ||
| """ | ||
| polling_interval = kwargs.pop("polling_interval", 5) | ||
| initial_response = getattr(poller._polling_method, "_initial_response") # pylint: disable=protected-access | ||
| operation_location = initial_response.http_response.headers["Operation-Location"] | ||
|
|
||
| job_id = urlparse(operation_location).path.split("/")[-1] | ||
| terminal_states = ["cancelled", "cancelling", "failed", "succeeded", "partiallyCompleted", "rejected"] | ||
| healthcare_operation.update_status() | ||
|
|
||
| if healthcare_operation.status in terminal_states: | ||
| print("Operation with ID '%s' is already in a terminal state and cannot be cancelled." \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be raised as an error? or does Python knows how to mask this print statement into something the user can see
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe an error would be better. It's a little bit difficult to test every code path here since most of the time the jobs succeed quickly enough that this always happens. I could try adding larger documents to the request to see if i can get the job to run long enough to test actual cancellation.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to raise the exception type
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm idk what the behavior is in Python for this scenarios. @iscai-msft for context
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for python we can log warnings, usually they look like this, not Warning raises. I think if other languages are raising an error when trying to cancel a finished operation, we might as well just raise an error too though
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got the inspiration for this from here. If there is a better exception type to use, could you make a suggestion? |
||
| % healthcare_operation.id) | ||
| return | ||
|
|
||
| try: | ||
| return self._client.begin_cancel_health_job( | ||
| job_id, | ||
| healthcare_operation.id, | ||
| polling=TextAnalyticsLROPollingMethod(timeout=polling_interval) | ||
| ) | ||
|
|
||
| except ValueError as error: | ||
| if "API version v3.0 does not have operation 'begin_cancel_health_job'" in str(error): | ||
| raise ValueError( | ||
| "'begin_cancel_analyze_healthcare_entities' method is only available for API version \ | ||
| v3.1-preview.3 and up." | ||
| ) | ||
| raise error | ||
|
|
||
| except HttpResponseError as error: | ||
| process_http_response_error(error) | ||
|
|
||
|
|
||
| @distributed_trace | ||
| def extract_key_phrases( # type: ignore | ||
| self, | ||
|
|
@@ -616,6 +632,9 @@ def analyze_sentiment( # type: ignore | |
| :class:`~azure.ai.textanalytics.SentenceSentiment` objects | ||
| will have property `mined_opinions` containing the result of this analysis. Only available for | ||
| API version v3.1-preview and up. | ||
| :keyword str string_index_type: Specifies the method used to interpret string offsets. Possible values are | ||
|
mssfang marked this conversation as resolved.
|
||
| 'UnicodeCodePoint', 'TextElements_v8', or 'Utf16CodeUnit'. The default value is 'UnicodeCodePoint'. | ||
| Only available for API version v3.1-preview and up. | ||
| :keyword str language: The 2 letter ISO 639-1 representation of language for the | ||
| entire batch. For example, use "en" for English; "es" for Spanish etc. | ||
| If not set, uses "en" for English as default. Per-document language will | ||
|
|
@@ -649,9 +668,11 @@ def analyze_sentiment( # type: ignore | |
| docs = _validate_input(documents, "language", language) | ||
| model_version = kwargs.pop("model_version", None) | ||
| show_stats = kwargs.pop("show_stats", False) | ||
| show_opinion_mining = kwargs.pop("show_opinion_mining", None) | ||
| if self._string_code_unit: | ||
| kwargs.update({"string_index_type": self._string_code_unit}) | ||
| show_opinion_mining = kwargs.pop("show_opinion_mining", True) | ||
| string_index_type = kwargs.pop("string_index_type", self._string_code_unit) | ||
|
|
||
| if string_index_type is not None: | ||
| kwargs.update({"string_index_type": string_index_type}) | ||
|
|
||
| if show_opinion_mining is not None: | ||
| kwargs.update({"opinion_mining": show_opinion_mining}) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.