azure-ai-textanalytics 5.3.0b2__py3-none-any.whl → 6.0.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of azure-ai-textanalytics might be problematic. Click here for more details.

Files changed (128) hide show
  1. azure/ai/textanalytics/__init__.py +26 -193
  2. azure/ai/textanalytics/_client.py +111 -0
  3. azure/ai/textanalytics/_configuration.py +73 -0
  4. azure/ai/textanalytics/{_generated/v2022_05_01/operations → _operations}/__init__.py +13 -8
  5. azure/ai/textanalytics/_operations/_operations.py +716 -0
  6. azure/ai/textanalytics/{_generated/v2022_05_01/models → _operations}/_patch.py +8 -6
  7. azure/ai/textanalytics/_patch.py +350 -0
  8. azure/ai/textanalytics/{_generated/aio → _utils}/__init__.py +1 -5
  9. azure/ai/textanalytics/_utils/model_base.py +1237 -0
  10. azure/ai/textanalytics/{_generated/_serialization.py → _utils/serialization.py} +640 -616
  11. azure/ai/textanalytics/{_generated/v2022_05_01/aio/_vendor.py → _utils/utils.py} +10 -12
  12. azure/ai/textanalytics/_version.py +8 -7
  13. azure/ai/textanalytics/aio/__init__.py +25 -14
  14. azure/ai/textanalytics/aio/_client.py +115 -0
  15. azure/ai/textanalytics/aio/_configuration.py +75 -0
  16. azure/ai/textanalytics/{_generated/v2022_10_01_preview/aio/operations → aio/_operations}/__init__.py +13 -8
  17. azure/ai/textanalytics/aio/_operations/_operations.py +623 -0
  18. azure/ai/textanalytics/{_generated/v2022_05_01 → aio/_operations}/_patch.py +8 -6
  19. azure/ai/textanalytics/aio/_patch.py +344 -0
  20. azure/ai/textanalytics/models/__init__.py +402 -0
  21. azure/ai/textanalytics/models/_enums.py +1979 -0
  22. azure/ai/textanalytics/models/_models.py +6641 -0
  23. azure/ai/textanalytics/{_generated/v2022_05_01/aio → models}/_patch.py +8 -6
  24. azure/ai/textanalytics/py.typed +1 -0
  25. {azure_ai_textanalytics-5.3.0b2.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info}/METADATA +668 -403
  26. azure_ai_textanalytics-6.0.0b1.dist-info/RECORD +29 -0
  27. {azure_ai_textanalytics-5.3.0b2.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info}/WHEEL +1 -1
  28. azure/ai/textanalytics/_base_client.py +0 -113
  29. azure/ai/textanalytics/_check.py +0 -22
  30. azure/ai/textanalytics/_dict_mixin.py +0 -57
  31. azure/ai/textanalytics/_generated/__init__.py +0 -16
  32. azure/ai/textanalytics/_generated/_configuration.py +0 -70
  33. azure/ai/textanalytics/_generated/_operations_mixin.py +0 -795
  34. azure/ai/textanalytics/_generated/_text_analytics_client.py +0 -126
  35. azure/ai/textanalytics/_generated/_version.py +0 -8
  36. azure/ai/textanalytics/_generated/aio/_configuration.py +0 -66
  37. azure/ai/textanalytics/_generated/aio/_operations_mixin.py +0 -776
  38. azure/ai/textanalytics/_generated/aio/_text_analytics_client.py +0 -124
  39. azure/ai/textanalytics/_generated/models.py +0 -8
  40. azure/ai/textanalytics/_generated/v2022_05_01/__init__.py +0 -20
  41. azure/ai/textanalytics/_generated/v2022_05_01/_configuration.py +0 -72
  42. azure/ai/textanalytics/_generated/v2022_05_01/_text_analytics_client.py +0 -100
  43. azure/ai/textanalytics/_generated/v2022_05_01/_vendor.py +0 -45
  44. azure/ai/textanalytics/_generated/v2022_05_01/aio/__init__.py +0 -20
  45. azure/ai/textanalytics/_generated/v2022_05_01/aio/_configuration.py +0 -71
  46. azure/ai/textanalytics/_generated/v2022_05_01/aio/_text_analytics_client.py +0 -97
  47. azure/ai/textanalytics/_generated/v2022_05_01/aio/operations/__init__.py +0 -18
  48. azure/ai/textanalytics/_generated/v2022_05_01/aio/operations/_patch.py +0 -121
  49. azure/ai/textanalytics/_generated/v2022_05_01/aio/operations/_text_analytics_client_operations.py +0 -603
  50. azure/ai/textanalytics/_generated/v2022_05_01/models/__init__.py +0 -281
  51. azure/ai/textanalytics/_generated/v2022_05_01/models/_models_py3.py +0 -5722
  52. azure/ai/textanalytics/_generated/v2022_05_01/models/_text_analytics_client_enums.py +0 -439
  53. azure/ai/textanalytics/_generated/v2022_05_01/operations/_patch.py +0 -120
  54. azure/ai/textanalytics/_generated/v2022_05_01/operations/_text_analytics_client_operations.py +0 -744
  55. azure/ai/textanalytics/_generated/v2022_10_01_preview/__init__.py +0 -20
  56. azure/ai/textanalytics/_generated/v2022_10_01_preview/_configuration.py +0 -72
  57. azure/ai/textanalytics/_generated/v2022_10_01_preview/_patch.py +0 -19
  58. azure/ai/textanalytics/_generated/v2022_10_01_preview/_text_analytics_client.py +0 -100
  59. azure/ai/textanalytics/_generated/v2022_10_01_preview/_vendor.py +0 -45
  60. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/__init__.py +0 -20
  61. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_configuration.py +0 -71
  62. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_patch.py +0 -19
  63. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_text_analytics_client.py +0 -97
  64. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_vendor.py +0 -27
  65. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/operations/_patch.py +0 -121
  66. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/operations/_text_analytics_client_operations.py +0 -603
  67. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/__init__.py +0 -405
  68. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/_models_py3.py +0 -8420
  69. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/_patch.py +0 -486
  70. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/_text_analytics_client_enums.py +0 -729
  71. azure/ai/textanalytics/_generated/v2022_10_01_preview/operations/__init__.py +0 -18
  72. azure/ai/textanalytics/_generated/v2022_10_01_preview/operations/_patch.py +0 -120
  73. azure/ai/textanalytics/_generated/v2022_10_01_preview/operations/_text_analytics_client_operations.py +0 -744
  74. azure/ai/textanalytics/_generated/v3_0/__init__.py +0 -20
  75. azure/ai/textanalytics/_generated/v3_0/_configuration.py +0 -66
  76. azure/ai/textanalytics/_generated/v3_0/_patch.py +0 -31
  77. azure/ai/textanalytics/_generated/v3_0/_text_analytics_client.py +0 -96
  78. azure/ai/textanalytics/_generated/v3_0/_vendor.py +0 -33
  79. azure/ai/textanalytics/_generated/v3_0/aio/__init__.py +0 -20
  80. azure/ai/textanalytics/_generated/v3_0/aio/_configuration.py +0 -65
  81. azure/ai/textanalytics/_generated/v3_0/aio/_patch.py +0 -31
  82. azure/ai/textanalytics/_generated/v3_0/aio/_text_analytics_client.py +0 -93
  83. azure/ai/textanalytics/_generated/v3_0/aio/_vendor.py +0 -27
  84. azure/ai/textanalytics/_generated/v3_0/aio/operations/__init__.py +0 -18
  85. azure/ai/textanalytics/_generated/v3_0/aio/operations/_patch.py +0 -19
  86. azure/ai/textanalytics/_generated/v3_0/aio/operations/_text_analytics_client_operations.py +0 -428
  87. azure/ai/textanalytics/_generated/v3_0/models/__init__.py +0 -81
  88. azure/ai/textanalytics/_generated/v3_0/models/_models_py3.py +0 -1467
  89. azure/ai/textanalytics/_generated/v3_0/models/_patch.py +0 -19
  90. azure/ai/textanalytics/_generated/v3_0/models/_text_analytics_client_enums.py +0 -58
  91. azure/ai/textanalytics/_generated/v3_0/operations/__init__.py +0 -18
  92. azure/ai/textanalytics/_generated/v3_0/operations/_patch.py +0 -19
  93. azure/ai/textanalytics/_generated/v3_0/operations/_text_analytics_client_operations.py +0 -604
  94. azure/ai/textanalytics/_generated/v3_1/__init__.py +0 -20
  95. azure/ai/textanalytics/_generated/v3_1/_configuration.py +0 -66
  96. azure/ai/textanalytics/_generated/v3_1/_patch.py +0 -31
  97. azure/ai/textanalytics/_generated/v3_1/_text_analytics_client.py +0 -98
  98. azure/ai/textanalytics/_generated/v3_1/_vendor.py +0 -45
  99. azure/ai/textanalytics/_generated/v3_1/aio/__init__.py +0 -20
  100. azure/ai/textanalytics/_generated/v3_1/aio/_configuration.py +0 -65
  101. azure/ai/textanalytics/_generated/v3_1/aio/_patch.py +0 -31
  102. azure/ai/textanalytics/_generated/v3_1/aio/_text_analytics_client.py +0 -95
  103. azure/ai/textanalytics/_generated/v3_1/aio/_vendor.py +0 -27
  104. azure/ai/textanalytics/_generated/v3_1/aio/operations/__init__.py +0 -18
  105. azure/ai/textanalytics/_generated/v3_1/aio/operations/_patch.py +0 -19
  106. azure/ai/textanalytics/_generated/v3_1/aio/operations/_text_analytics_client_operations.py +0 -1291
  107. azure/ai/textanalytics/_generated/v3_1/models/__init__.py +0 -205
  108. azure/ai/textanalytics/_generated/v3_1/models/_models_py3.py +0 -3976
  109. azure/ai/textanalytics/_generated/v3_1/models/_patch.py +0 -19
  110. azure/ai/textanalytics/_generated/v3_1/models/_text_analytics_client_enums.py +0 -367
  111. azure/ai/textanalytics/_generated/v3_1/operations/__init__.py +0 -18
  112. azure/ai/textanalytics/_generated/v3_1/operations/_patch.py +0 -19
  113. azure/ai/textanalytics/_generated/v3_1/operations/_text_analytics_client_operations.py +0 -1709
  114. azure/ai/textanalytics/_lro.py +0 -553
  115. azure/ai/textanalytics/_models.py +0 -3158
  116. azure/ai/textanalytics/_policies.py +0 -66
  117. azure/ai/textanalytics/_request_handlers.py +0 -104
  118. azure/ai/textanalytics/_response_handlers.py +0 -583
  119. azure/ai/textanalytics/_text_analytics_client.py +0 -2081
  120. azure/ai/textanalytics/_user_agent.py +0 -8
  121. azure/ai/textanalytics/_validate.py +0 -113
  122. azure/ai/textanalytics/aio/_base_client_async.py +0 -98
  123. azure/ai/textanalytics/aio/_lro_async.py +0 -503
  124. azure/ai/textanalytics/aio/_response_handlers_async.py +0 -94
  125. azure/ai/textanalytics/aio/_text_analytics_client_async.py +0 -2077
  126. azure_ai_textanalytics-5.3.0b2.dist-info/RECORD +0 -115
  127. {azure_ai_textanalytics-5.3.0b2.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info/licenses}/LICENSE +0 -0
  128. {azure_ai_textanalytics-5.3.0b2.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info}/top_level.txt +0 -0
@@ -1,2081 +0,0 @@
1
- # ------------------------------------
2
- # Copyright (c) Microsoft Corporation.
3
- # Licensed under the MIT License.
4
- # ------------------------------------
5
- # pylint: disable=too-many-lines
6
-
7
- from typing import (
8
- Union,
9
- Any,
10
- List,
11
- Dict,
12
- cast,
13
- Optional,
14
- )
15
- from azure.core.paging import ItemPaged
16
- from azure.core.tracing.decorator import distributed_trace
17
- from azure.core.exceptions import HttpResponseError
18
- from azure.core.credentials import AzureKeyCredential
19
- from azure.core.credentials import TokenCredential
20
- from ._base_client import TextAnalyticsClientBase, TextAnalyticsApiVersion
21
- from ._lro import AnalyzeActionsLROPoller, AnalyzeHealthcareEntitiesLROPoller, TextAnalysisLROPoller
22
- from ._request_handlers import (
23
- _validate_input,
24
- _determine_action_type,
25
- )
26
- from ._validate import validate_multiapi_args, check_for_unsupported_actions_types
27
- from ._response_handlers import (
28
- process_http_response_error,
29
- entities_result,
30
- linked_entities_result,
31
- key_phrases_result,
32
- sentiment_result,
33
- language_result,
34
- pii_entities_result,
35
- healthcare_paged_result,
36
- analyze_paged_result,
37
- _get_result_from_continuation_token,
38
- dynamic_classification_result,
39
- )
40
-
41
- from ._lro import (
42
- TextAnalyticsOperationResourcePolling,
43
- AnalyzeActionsLROPollingMethod,
44
- AnalyzeHealthcareEntitiesLROPollingMethod,
45
- )
46
- from ._generated.models import HealthcareDocumentType, ClassificationType
47
- from ._models import (
48
- DetectLanguageInput,
49
- TextDocumentInput,
50
- DetectLanguageResult,
51
- RecognizeEntitiesResult,
52
- RecognizeLinkedEntitiesResult,
53
- ExtractKeyPhrasesResult,
54
- AnalyzeSentimentResult,
55
- DocumentError,
56
- RecognizePiiEntitiesResult,
57
- RecognizeEntitiesAction,
58
- RecognizePiiEntitiesAction,
59
- RecognizeLinkedEntitiesAction,
60
- ExtractKeyPhrasesAction,
61
- AnalyzeSentimentAction,
62
- AnalyzeHealthcareEntitiesResult,
63
- RecognizeCustomEntitiesAction,
64
- RecognizeCustomEntitiesResult,
65
- SingleLabelClassifyAction,
66
- MultiLabelClassifyAction,
67
- ClassifyDocumentResult,
68
- AnalyzeHealthcareEntitiesAction,
69
- _AnalyzeActionsType,
70
- ExtractSummaryAction,
71
- ExtractSummaryResult,
72
- AbstractiveSummaryAction,
73
- AbstractiveSummaryResult,
74
- DynamicClassificationResult,
75
- PiiEntityDomain,
76
- PiiEntityCategory,
77
- )
78
- from ._check import is_language_api, string_index_type_compatibility
79
-
80
-
81
- AnalyzeActionsResponse = TextAnalysisLROPoller[
82
- ItemPaged[
83
- List[
84
- Union[
85
- RecognizeEntitiesResult,
86
- RecognizeLinkedEntitiesResult,
87
- RecognizePiiEntitiesResult,
88
- ExtractKeyPhrasesResult,
89
- AnalyzeSentimentResult,
90
- RecognizeCustomEntitiesResult,
91
- ClassifyDocumentResult,
92
- AnalyzeHealthcareEntitiesResult,
93
- ExtractSummaryResult,
94
- AbstractiveSummaryResult,
95
- DocumentError,
96
- ]
97
- ]
98
- ]
99
- ]
100
-
101
-
102
- class TextAnalyticsClient(TextAnalyticsClientBase):
103
- """The Language service API is a suite of natural language processing (NLP) skills built with the best-in-class
104
- Microsoft machine learning algorithms. The API can be used to analyze unstructured text for
105
- tasks such as sentiment analysis, key phrase extraction, entities recognition,
106
- and language detection, and more.
107
-
108
- Further documentation can be found in
109
- https://docs.microsoft.com/azure/cognitive-services/language-service/overview
110
-
111
- :param str endpoint: Supported Cognitive Services or Language resource
112
- endpoints (protocol and hostname, for example: 'https://<resource-name>.cognitiveservices.azure.com').
113
- :param credential: Credentials needed for the client to connect to Azure.
114
- This can be the an instance of AzureKeyCredential if using a Cognitive Services/Language API key
115
- or a token credential from :mod:`azure.identity`.
116
- :type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
117
- :keyword str default_country_hint: Sets the default country_hint to use for all operations.
118
- Defaults to "US". If you don't want to use a country hint, pass the string "none".
119
- :keyword str default_language: Sets the default language to use for all operations.
120
- Defaults to "en".
121
- :keyword api_version: The API version of the service to use for requests. It defaults to the
122
- latest service version. Setting to an older version may result in reduced feature compatibility.
123
- :paramtype api_version: str or ~azure.ai.textanalytics.TextAnalyticsApiVersion
124
-
125
- .. admonition:: Example:
126
-
127
- .. literalinclude:: ../samples/sample_authentication.py
128
- :start-after: [START create_ta_client_with_key]
129
- :end-before: [END create_ta_client_with_key]
130
- :language: python
131
- :dedent: 4
132
- :caption: Creating the TextAnalyticsClient with endpoint and API key.
133
-
134
- .. literalinclude:: ../samples/sample_authentication.py
135
- :start-after: [START create_ta_client_with_aad]
136
- :end-before: [END create_ta_client_with_aad]
137
- :language: python
138
- :dedent: 4
139
- :caption: Creating the TextAnalyticsClient with endpoint and token credential from Azure Active Directory.
140
- """
141
-
142
- def __init__(
143
- self,
144
- endpoint: str,
145
- credential: Union[AzureKeyCredential, TokenCredential],
146
- *,
147
- default_language: Optional[str] = None,
148
- default_country_hint: Optional[str] = None,
149
- api_version: Optional[Union[str, TextAnalyticsApiVersion]] = None,
150
- **kwargs: Any,
151
- ) -> None:
152
- super().__init__(
153
- endpoint=endpoint, credential=credential, api_version=api_version, **kwargs
154
- )
155
- self._default_language = default_language if default_language is not None else "en"
156
- self._default_country_hint = default_country_hint if default_country_hint is not None else "US"
157
- self._string_index_type_default = (
158
- None if api_version == "v3.0" else "UnicodeCodePoint"
159
- )
160
-
161
- @distributed_trace
162
- @validate_multiapi_args(
163
- version_method_added="v3.0",
164
- args_mapping={"v3.1": ["disable_service_logs"]}
165
- )
166
- def detect_language(
167
- self,
168
- documents: Union[List[str], List[DetectLanguageInput], List[Dict[str, str]]],
169
- *,
170
- country_hint: Optional[str] = None,
171
- disable_service_logs: Optional[bool] = None,
172
- model_version: Optional[str] = None,
173
- show_stats: Optional[bool] = None,
174
- **kwargs: Any,
175
- ) -> List[Union[DetectLanguageResult, DocumentError]]:
176
- """Detect language for a batch of documents.
177
-
178
- Returns the detected language and a numeric score between zero and
179
- one. Scores close to one indicate 100% certainty that the identified
180
- language is true. See https://aka.ms/talangs for the list of enabled languages.
181
-
182
- See https://aka.ms/azsdk/textanalytics/data-limits for service data limits.
183
-
184
- :param documents: The set of documents to process as part of this batch.
185
- If you wish to specify the ID and country_hint on a per-item basis you must
186
- use as input a list[:class:`~azure.ai.textanalytics.DetectLanguageInput`] or a list of
187
- dict representations of :class:`~azure.ai.textanalytics.DetectLanguageInput`, like
188
- `{"id": "1", "country_hint": "us", "text": "hello world"}`.
189
- :type documents:
190
- list[str] or list[~azure.ai.textanalytics.DetectLanguageInput] or list[dict[str, str]]
191
- :keyword str country_hint: Country of origin hint for the entire batch. Accepts two
192
- letter country codes specified by ISO 3166-1 alpha-2. Per-document
193
- country hints will take precedence over whole batch hints. Defaults to
194
- "US". If you don't want to use a country hint, pass the string "none".
195
- :keyword str model_version: Version of the model used on the service side for scoring,
196
- e.g. "latest", "2019-10-01". If a model version
197
- is not specified, the API will default to the latest, non-preview version.
198
- See here for more info: https://aka.ms/text-analytics-model-versioning
199
- :keyword bool show_stats: If set to true, response will contain document
200
- level statistics in the `statistics` field of the document-level response.
201
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
202
- logged on the service side for troubleshooting. By default, the Language service logs your
203
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
204
- the service's natural language processing functions. Setting this parameter to true,
205
- disables input logging and may limit our ability to remediate issues that occur. Please see
206
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
207
- additional details, and Microsoft Responsible AI principles at
208
- https://www.microsoft.com/ai/responsible-ai.
209
- :return: The combined list of :class:`~azure.ai.textanalytics.DetectLanguageResult` and
210
- :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents were
211
- passed in.
212
- :rtype: list[~azure.ai.textanalytics.DetectLanguageResult or ~azure.ai.textanalytics.DocumentError]
213
- :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError:
214
-
215
- .. versionadded:: v3.1
216
- The *disable_service_logs* keyword argument.
217
-
218
- .. admonition:: Example:
219
-
220
- .. literalinclude:: ../samples/sample_detect_language.py
221
- :start-after: [START detect_language]
222
- :end-before: [END detect_language]
223
- :language: python
224
- :dedent: 4
225
- :caption: Detecting language in a batch of documents.
226
- """
227
-
228
- country_hint_arg = (
229
- country_hint
230
- if country_hint is not None
231
- else self._default_country_hint
232
- )
233
- docs = _validate_input(documents, "country_hint", country_hint_arg)
234
-
235
- try:
236
- if is_language_api(self._api_version):
237
- models = self._client.models(api_version=self._api_version)
238
- return cast(
239
- List[Union[DetectLanguageResult, DocumentError]],
240
- self._client.analyze_text(
241
- body=models.AnalyzeTextLanguageDetectionInput(
242
- analysis_input={"documents": docs},
243
- parameters=models.LanguageDetectionTaskParameters(
244
- logging_opt_out=disable_service_logs,
245
- model_version=model_version
246
- )
247
- ),
248
- show_stats=show_stats,
249
- cls=kwargs.pop("cls", language_result),
250
- **kwargs
251
- )
252
- )
253
-
254
- # api_versions 3.0, 3.1
255
- return cast(
256
- List[Union[DetectLanguageResult, DocumentError]],
257
- self._client.languages(
258
- documents=docs,
259
- model_version=model_version,
260
- show_stats=show_stats,
261
- logging_opt_out=disable_service_logs,
262
- cls=kwargs.pop("cls", language_result),
263
- **kwargs
264
- )
265
- )
266
- except HttpResponseError as error:
267
- return process_http_response_error(error)
268
-
269
- @distributed_trace
270
- @validate_multiapi_args(
271
- version_method_added="v3.0",
272
- args_mapping={"v3.1": ["string_index_type", "disable_service_logs"]}
273
- )
274
- def recognize_entities(
275
- self,
276
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
277
- *,
278
- disable_service_logs: Optional[bool] = None,
279
- language: Optional[str] = None,
280
- model_version: Optional[str] = None,
281
- show_stats: Optional[bool] = None,
282
- string_index_type: Optional[str] = None,
283
- **kwargs: Any,
284
- ) -> List[Union[RecognizeEntitiesResult, DocumentError]]:
285
- """Recognize entities for a batch of documents.
286
-
287
- Identifies and categorizes entities in your text as people, places,
288
- organizations, date/time, quantities, percentages, currencies, and more.
289
- For the list of supported entity types, check: https://aka.ms/taner
290
-
291
- See https://aka.ms/azsdk/textanalytics/data-limits for service data limits.
292
-
293
- :param documents: The set of documents to process as part of this batch.
294
- If you wish to specify the ID and language on a per-item basis you must
295
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list
296
- of dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`,
297
- like `{"id": "1", "language": "en", "text": "hello world"}`.
298
- :type documents:
299
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
300
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
301
- entire batch. For example, use "en" for English; "es" for Spanish etc.
302
- If not set, uses "en" for English as default. Per-document language will
303
- take precedence over whole batch language. See https://aka.ms/talangs for
304
- supported languages in Language API.
305
- :keyword str model_version: This value indicates which model will
306
- be used for scoring, e.g. "latest", "2019-10-01". If a model-version
307
- is not specified, the API will default to the latest, non-preview version.
308
- See here for more info: https://aka.ms/text-analytics-model-versioning
309
- :keyword bool show_stats: If set to true, response will contain document
310
- level statistics in the `statistics` field of the document-level response.
311
- :keyword str string_index_type: Specifies the method used to interpret string offsets.
312
- `UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
313
- you can also pass in `Utf16CodeUnit` or `TextElement_v8`. For additional information
314
- see https://aka.ms/text-analytics-offsets
315
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
316
- logged on the service side for troubleshooting. By default, the Language service logs your
317
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
318
- the service's natural language processing functions. Setting this parameter to true,
319
- disables input logging and may limit our ability to remediate issues that occur. Please see
320
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
321
- additional details, and Microsoft Responsible AI principles at
322
- https://www.microsoft.com/ai/responsible-ai.
323
- :return: The combined list of :class:`~azure.ai.textanalytics.RecognizeEntitiesResult` and
324
- :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents
325
- were passed in.
326
- :rtype: list[~azure.ai.textanalytics.RecognizeEntitiesResult or ~azure.ai.textanalytics.DocumentError]
327
- :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError:
328
-
329
- .. versionadded:: v3.1
330
- The *disable_service_logs* and *string_index_type* keyword arguments.
331
-
332
- .. admonition:: Example:
333
-
334
- .. literalinclude:: ../samples/sample_recognize_entities.py
335
- :start-after: [START recognize_entities]
336
- :end-before: [END recognize_entities]
337
- :language: python
338
- :dedent: 4
339
- :caption: Recognize entities in a batch of documents.
340
- """
341
-
342
- language_arg = language if language is not None else self._default_language
343
- docs = _validate_input(documents, "language", language_arg)
344
- string_index_type_arg = string_index_type if string_index_type is not None else self._string_index_type_default
345
-
346
- try:
347
- if is_language_api(self._api_version):
348
- models = self._client.models(api_version=self._api_version)
349
- return cast(
350
- List[Union[RecognizeEntitiesResult, DocumentError]],
351
- self._client.analyze_text(
352
- body=models.AnalyzeTextEntityRecognitionInput(
353
- analysis_input={"documents": docs},
354
- parameters=models.EntitiesTaskParameters(
355
- logging_opt_out=disable_service_logs,
356
- model_version=model_version,
357
- string_index_type=string_index_type_compatibility(string_index_type_arg)
358
- )
359
- ),
360
- show_stats=show_stats,
361
- cls=kwargs.pop("cls", entities_result),
362
- **kwargs
363
- )
364
- )
365
-
366
- # api_versions 3.0, 3.1
367
- return cast(
368
- List[Union[RecognizeEntitiesResult, DocumentError]],
369
- self._client.entities_recognition_general(
370
- documents=docs,
371
- model_version=model_version,
372
- show_stats=show_stats,
373
- string_index_type=string_index_type_arg,
374
- logging_opt_out=disable_service_logs,
375
- cls=kwargs.pop("cls", entities_result),
376
- **kwargs,
377
- )
378
- )
379
- except HttpResponseError as error:
380
- return process_http_response_error(error)
381
-
382
- @distributed_trace
383
- @validate_multiapi_args(
384
- version_method_added="v3.1"
385
- )
386
- def recognize_pii_entities(
387
- self,
388
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
389
- *,
390
- categories_filter: Optional[List[Union[str, PiiEntityCategory]]] = None,
391
- disable_service_logs: Optional[bool] = None,
392
- domain_filter: Optional[Union[str, PiiEntityDomain]] = None,
393
- language: Optional[str] = None,
394
- model_version: Optional[str] = None,
395
- show_stats: Optional[bool] = None,
396
- string_index_type: Optional[str] = None,
397
- **kwargs: Any,
398
- ) -> List[Union[RecognizePiiEntitiesResult, DocumentError]]:
399
- """Recognize entities containing personal information for a batch of documents.
400
-
401
- Returns a list of personal information entities ("SSN",
402
- "Bank Account", etc) in the document. For the list of supported entity types,
403
- check https://aka.ms/azsdk/language/pii
404
-
405
- See https://aka.ms/azsdk/textanalytics/data-limits for service data limits.
406
-
407
- :param documents: The set of documents to process as part of this batch.
408
- If you wish to specify the ID and language on a per-item basis you must
409
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
410
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
411
- `{"id": "1", "language": "en", "text": "hello world"}`.
412
- :type documents:
413
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
414
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
415
- entire batch. For example, use "en" for English; "es" for Spanish etc.
416
- If not set, uses "en" for English as default. Per-document language will
417
- take precedence over whole batch language. See https://aka.ms/talangs for
418
- supported languages in Language API.
419
- :keyword str model_version: This value indicates which model will
420
- be used for scoring, e.g. "latest", "2019-10-01". If a model-version
421
- is not specified, the API will default to the latest, non-preview version.
422
- See here for more info: https://aka.ms/text-analytics-model-versioning
423
- :keyword bool show_stats: If set to true, response will contain document
424
- level statistics in the `statistics` field of the document-level response.
425
- :keyword domain_filter: Filters the response entities to ones only included in the specified domain.
426
- I.e., if set to 'phi', will only return entities in the Protected Healthcare Information domain.
427
- See https://aka.ms/azsdk/language/pii for more information.
428
- :paramtype domain_filter: str or ~azure.ai.textanalytics.PiiEntityDomain
429
- :keyword categories_filter: Instead of filtering over all PII entity categories, you can pass in a list of
430
- the specific PII entity categories you want to filter out. For example, if you only want to filter out
431
- U.S. social security numbers in a document, you can pass in
432
- `[PiiEntityCategory.US_SOCIAL_SECURITY_NUMBER]` for this kwarg.
433
- :paramtype categories_filter: list[str or ~azure.ai.textanalytics.PiiEntityCategory]
434
- :keyword str string_index_type: Specifies the method used to interpret string offsets.
435
- `UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
436
- you can also pass in `Utf16CodeUnit` or `TextElement_v8`. For additional information
437
- see https://aka.ms/text-analytics-offsets
438
- :keyword bool disable_service_logs: Defaults to true, meaning that the Language service will not log your
439
- input text on the service side for troubleshooting. If set to False, the Language service logs your
440
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
441
- the service's natural language processing functions. Please see
442
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
443
- additional details, and Microsoft Responsible AI principles at
444
- https://www.microsoft.com/ai/responsible-ai.
445
- :return: The combined list of :class:`~azure.ai.textanalytics.RecognizePiiEntitiesResult`
446
- and :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents
447
- were passed in.
448
- :rtype: list[~azure.ai.textanalytics.RecognizePiiEntitiesResult or ~azure.ai.textanalytics.DocumentError]
449
- :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError:
450
-
451
- .. versionadded:: v3.1
452
- The *recognize_pii_entities* client method.
453
-
454
- .. admonition:: Example:
455
-
456
- .. literalinclude:: ../samples/sample_recognize_pii_entities.py
457
- :start-after: [START recognize_pii_entities]
458
- :end-before: [END recognize_pii_entities]
459
- :language: python
460
- :dedent: 4
461
- :caption: Recognize personally identifiable information entities in a batch of documents.
462
- """
463
- language_arg = language if language is not None else self._default_language
464
- docs = _validate_input(documents, "language", language_arg)
465
- string_index_type_arg = string_index_type if string_index_type is not None else self._string_index_type_default
466
-
467
- try:
468
- if is_language_api(self._api_version):
469
- models = self._client.models(api_version=self._api_version)
470
- return cast(
471
- List[Union[RecognizePiiEntitiesResult, DocumentError]],
472
- self._client.analyze_text(
473
- body=models.AnalyzeTextPiiEntitiesRecognitionInput(
474
- analysis_input={"documents": docs},
475
- parameters=models.PiiTaskParameters(
476
- logging_opt_out=disable_service_logs,
477
- model_version=model_version,
478
- domain=domain_filter,
479
- pii_categories=categories_filter,
480
- string_index_type=string_index_type_compatibility(string_index_type_arg)
481
- )
482
- ),
483
- show_stats=show_stats,
484
- cls=kwargs.pop("cls", pii_entities_result),
485
- **kwargs
486
- )
487
- )
488
-
489
- # api_versions 3.0, 3.1
490
- return cast(
491
- List[Union[RecognizePiiEntitiesResult, DocumentError]],
492
- self._client.entities_recognition_pii(
493
- documents=docs,
494
- model_version=model_version,
495
- show_stats=show_stats,
496
- domain=domain_filter,
497
- pii_categories=categories_filter,
498
- logging_opt_out=disable_service_logs,
499
- string_index_type=string_index_type_arg,
500
- cls=kwargs.pop("cls", pii_entities_result),
501
- **kwargs
502
- )
503
- )
504
- except HttpResponseError as error:
505
- return process_http_response_error(error)
506
-
507
- @distributed_trace
508
- @validate_multiapi_args(
509
- version_method_added="v3.0",
510
- args_mapping={"v3.1": ["string_index_type", "disable_service_logs"]}
511
- )
512
- def recognize_linked_entities(
513
- self,
514
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
515
- *,
516
- disable_service_logs: Optional[bool] = None,
517
- language: Optional[str] = None,
518
- model_version: Optional[str] = None,
519
- show_stats: Optional[bool] = None,
520
- string_index_type: Optional[str] = None,
521
- **kwargs: Any,
522
- ) -> List[Union[RecognizeLinkedEntitiesResult, DocumentError]]:
523
- """Recognize linked entities from a well-known knowledge base for a batch of documents.
524
-
525
- Identifies and disambiguates the identity of each entity found in text (for example,
526
- determining whether an occurrence of the word Mars refers to the planet, or to the
527
- Roman god of war). Recognized entities are associated with URLs to a well-known
528
- knowledge base, like Wikipedia.
529
-
530
- See https://aka.ms/azsdk/textanalytics/data-limits for service data limits.
531
-
532
- :param documents: The set of documents to process as part of this batch.
533
- If you wish to specify the ID and language on a per-item basis you must
534
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
535
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
536
- `{"id": "1", "language": "en", "text": "hello world"}`.
537
- :type documents:
538
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
539
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
540
- entire batch. For example, use "en" for English; "es" for Spanish etc.
541
- If not set, uses "en" for English as default. Per-document language will
542
- take precedence over whole batch language. See https://aka.ms/talangs for
543
- supported languages in Language API.
544
- :keyword str model_version: This value indicates which model will
545
- be used for scoring, e.g. "latest", "2019-10-01". If a model-version
546
- is not specified, the API will default to the latest, non-preview version.
547
- See here for more info: https://aka.ms/text-analytics-model-versioning
548
- :keyword bool show_stats: If set to true, response will contain document
549
- level statistics in the `statistics` field of the document-level response.
550
- :keyword str string_index_type: Specifies the method used to interpret string offsets.
551
- `UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
552
- you can also pass in `Utf16CodeUnit` or `TextElement_v8`. For additional information
553
- see https://aka.ms/text-analytics-offsets
554
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
555
- logged on the service side for troubleshooting. By default, the Language service logs your
556
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
557
- the service's natural language processing functions. Setting this parameter to true,
558
- disables input logging and may limit our ability to remediate issues that occur. Please see
559
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
560
- additional details, and Microsoft Responsible AI principles at
561
- https://www.microsoft.com/ai/responsible-ai.
562
- :return: The combined list of :class:`~azure.ai.textanalytics.RecognizeLinkedEntitiesResult`
563
- and :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents
564
- were passed in.
565
- :rtype: list[~azure.ai.textanalytics.RecognizeLinkedEntitiesResult or ~azure.ai.textanalytics.DocumentError]
566
- :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError:
567
-
568
- .. versionadded:: v3.1
569
- The *disable_service_logs* and *string_index_type* keyword arguments.
570
-
571
- .. admonition:: Example:
572
-
573
- .. literalinclude:: ../samples/sample_recognize_linked_entities.py
574
- :start-after: [START recognize_linked_entities]
575
- :end-before: [END recognize_linked_entities]
576
- :language: python
577
- :dedent: 4
578
- :caption: Recognize linked entities in a batch of documents.
579
- """
580
-
581
- language_arg = language if language is not None else self._default_language
582
- docs = _validate_input(documents, "language", language_arg)
583
- string_index_type_arg = string_index_type if string_index_type is not None else self._string_index_type_default
584
-
585
- try:
586
- if is_language_api(self._api_version):
587
- models = self._client.models(api_version=self._api_version)
588
- return cast(
589
- List[Union[RecognizeLinkedEntitiesResult, DocumentError]],
590
- self._client.analyze_text(
591
- body=models.AnalyzeTextEntityLinkingInput(
592
- analysis_input={"documents": docs},
593
- parameters=models.EntityLinkingTaskParameters(
594
- logging_opt_out=disable_service_logs,
595
- model_version=model_version,
596
- string_index_type=string_index_type_compatibility(string_index_type_arg)
597
- )
598
- ),
599
- show_stats=show_stats,
600
- cls=kwargs.pop("cls", linked_entities_result),
601
- **kwargs
602
- )
603
- )
604
-
605
- # api_versions 3.0, 3.1
606
- return cast(
607
- List[Union[RecognizeLinkedEntitiesResult, DocumentError]],
608
- self._client.entities_linking(
609
- documents=docs,
610
- logging_opt_out=disable_service_logs,
611
- model_version=model_version,
612
- string_index_type=string_index_type_arg,
613
- show_stats=show_stats,
614
- cls=kwargs.pop("cls", linked_entities_result),
615
- **kwargs
616
- )
617
- )
618
- except HttpResponseError as error:
619
- return process_http_response_error(error)
620
-
621
- # pylint: disable=unused-argument
622
- def _healthcare_result_callback(
623
- self, raw_response, deserialized, doc_id_order, task_id_order=None, show_stats=False, bespoke=False
624
- ):
625
- if deserialized is None:
626
- models = self._client.models(api_version=self._api_version)
627
- response_cls = \
628
- models.AnalyzeTextJobState if is_language_api(self._api_version) else models.HealthcareJobState
629
- deserialized = response_cls.deserialize(raw_response)
630
- return healthcare_paged_result(
631
- doc_id_order,
632
- self._client.analyze_text_job_status if is_language_api(self._api_version) else self._client.health_status,
633
- raw_response,
634
- deserialized,
635
- show_stats=show_stats,
636
- )
637
-
638
- @distributed_trace
639
- @validate_multiapi_args(
640
- version_method_added="v3.1",
641
- args_mapping={
642
- "2022-10-01-preview": ["fhir_version", "document_type"],
643
- "2022-05-01": ["display_name"]
644
- }
645
- )
646
- def begin_analyze_healthcare_entities(
647
- self,
648
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
649
- *,
650
- continuation_token: Optional[str] = None,
651
- disable_service_logs: Optional[bool] = None,
652
- display_name: Optional[str] = None,
653
- document_type: Optional[Union[str, HealthcareDocumentType]] = None,
654
- fhir_version: Optional[str] = None,
655
- language: Optional[str] = None,
656
- model_version: Optional[str] = None,
657
- polling_interval: Optional[int] = None,
658
- show_stats: Optional[bool] = None,
659
- string_index_type: Optional[str] = None,
660
- **kwargs: Any,
661
- ) -> AnalyzeHealthcareEntitiesLROPoller[ItemPaged[Union[AnalyzeHealthcareEntitiesResult, DocumentError]]]:
662
- """Analyze healthcare entities and identify relationships between these entities in a batch of documents.
663
-
664
- Entities are associated with references that can be found in existing knowledge bases,
665
- such as UMLS, CHV, MSH, etc.
666
-
667
- We also extract the relations found between entities, for example in "The subject took 100 mg of ibuprofen",
668
- we would extract the relationship between the "100 mg" dosage and the "ibuprofen" medication.
669
-
670
- :param documents: The set of documents to process as part of this batch.
671
- If you wish to specify the ID and language on a per-item basis you must
672
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
673
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
674
- `{"id": "1", "language": "en", "text": "hello world"}`.
675
- :type documents:
676
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
677
- :keyword str model_version: This value indicates which model will
678
- be used for scoring, e.g. "latest", "2019-10-01". If a model-version
679
- is not specified, the API will default to the latest, non-preview version.
680
- See here for more info: https://aka.ms/text-analytics-model-versioning
681
- :keyword bool show_stats: If set to true, response will contain document level statistics.
682
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
683
- entire batch. For example, use "en" for English; "es" for Spanish etc.
684
- For automatic language detection, use "auto" (Only supported by API version
685
- 2022-10-01-preview and newer). If not set, uses "en" for English as default.
686
- Per-document language will take precedence over whole batch language.
687
- See https://aka.ms/talangs for supported languages in Language API.
688
- :keyword str display_name: An optional display name to set for the requested analysis.
689
- :keyword str string_index_type: Specifies the method used to interpret string offsets.
690
- `UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
691
- you can also pass in `Utf16CodeUnit` or `TextElement_v8`. For additional information
692
- see https://aka.ms/text-analytics-offsets
693
- :keyword int polling_interval: Waiting time between two polls for LRO operations
694
- if no Retry-After header is present. Defaults to 5 seconds.
695
- :keyword str continuation_token:
696
- Call `continuation_token()` on the poller object to save the long-running operation (LRO)
697
- state into an opaque token. Pass the value as the `continuation_token` keyword argument
698
- to restart the LRO from a saved state.
699
- :keyword bool disable_service_logs: Defaults to true, meaning that the Language service will not log your
700
- input text on the service side for troubleshooting. If set to False, the Language service logs your
701
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
702
- the service's natural language processing functions. Please see
703
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
704
- additional details, and Microsoft Responsible AI principles at
705
- https://www.microsoft.com/ai/responsible-ai.
706
- :keyword str fhir_version: The FHIR Spec version that the result will use to format the fhir_bundle
707
- on the result object. For additional information see https://www.hl7.org/fhir/overview.html.
708
- The only acceptable values to pass in are None and "4.0.1". The default value is None.
709
- :keyword document_type: Document type that can be provided as input for Fhir Documents. Expect to
710
- have fhir_version provided when used. Behavior of using None enum is the same as not using the
711
- document_type parameter. Known values are: "None", "ClinicalTrial", "DischargeSummary",
712
- "ProgressNote", "HistoryAndPhysical", "Consult", "Imaging", "Pathology", and "ProcedureNote".
713
- :paramtype document_type: str or ~azure.ai.textanalytics.HealthcareDocumentType
714
- :return: An instance of an AnalyzeHealthcareEntitiesLROPoller. Call `result()` on the this
715
- object to return a heterogeneous pageable of
716
- :class:`~azure.ai.textanalytics.AnalyzeHealthcareEntitiesResult` and
717
- :class:`~azure.ai.textanalytics.DocumentError`.
718
- :rtype:
719
- ~azure.ai.textanalytics.AnalyzeHealthcareEntitiesLROPoller[~azure.core.paging.ItemPaged[
720
- ~azure.ai.textanalytics.AnalyzeHealthcareEntitiesResult or ~azure.ai.textanalytics.DocumentError]]
721
- :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError:
722
-
723
- .. versionadded:: v3.1
724
- The *begin_analyze_healthcare_entities* client method.
725
- .. versionadded:: 2022-05-01
726
- The *display_name* keyword argument.
727
- .. versionadded:: 2022-10-01-preview
728
- The *fhir_version* and *document_type* keyword arguments.
729
-
730
- .. admonition:: Example:
731
-
732
- .. literalinclude:: ../samples/sample_analyze_healthcare_entities.py
733
- :start-after: [START analyze_healthcare_entities]
734
- :end-before: [END analyze_healthcare_entities]
735
- :language: python
736
- :dedent: 4
737
- :caption: Recognize healthcare entities in a batch of documents.
738
- """
739
-
740
- language_arg = language if language is not None else self._default_language
741
- polling_interval_arg = polling_interval if polling_interval is not None else 5
742
- string_index_type_arg = string_index_type if string_index_type is not None else self._string_index_type_default
743
-
744
- if continuation_token:
745
- return cast(
746
- AnalyzeHealthcareEntitiesLROPoller[
747
- ItemPaged[Union[AnalyzeHealthcareEntitiesResult, DocumentError]]
748
- ],
749
- _get_result_from_continuation_token(
750
- self._client._client, # pylint: disable=protected-access
751
- continuation_token,
752
- AnalyzeHealthcareEntitiesLROPoller,
753
- AnalyzeHealthcareEntitiesLROPollingMethod(
754
- text_analytics_client=self._client,
755
- timeout=polling_interval_arg,
756
- **kwargs
757
- ),
758
- self._healthcare_result_callback
759
- )
760
- )
761
-
762
- docs = _validate_input(documents, "language", language_arg)
763
- doc_id_order = [doc.get("id") for doc in docs]
764
- my_cls = kwargs.pop(
765
- "cls",
766
- lambda pipeline_response, deserialized, _: self._healthcare_result_callback(
767
- pipeline_response, deserialized, doc_id_order, show_stats=show_stats
768
- ),
769
- )
770
- models = self._client.models(api_version=self._api_version)
771
-
772
- try:
773
- if is_language_api(self._api_version):
774
- input_docs = models.MultiLanguageAnalysisInput(
775
- documents=docs
776
- )
777
- return cast(
778
- AnalyzeHealthcareEntitiesLROPoller[
779
- ItemPaged[Union[AnalyzeHealthcareEntitiesResult, DocumentError]]
780
- ],
781
- self._client.begin_analyze_text_submit_job( # type: ignore
782
- body=models.AnalyzeTextJobsInput(
783
- analysis_input=input_docs,
784
- display_name=display_name,
785
- tasks=[
786
- models.HealthcareLROTask(
787
- task_name="0",
788
- parameters=models.HealthcareTaskParameters(
789
- model_version=model_version,
790
- logging_opt_out=disable_service_logs,
791
- string_index_type=string_index_type_compatibility(string_index_type_arg),
792
- fhir_version=fhir_version,
793
- document_type=document_type,
794
- )
795
- )
796
- ]
797
- ),
798
- cls=my_cls,
799
- polling=AnalyzeHealthcareEntitiesLROPollingMethod(
800
- text_analytics_client=self._client,
801
- timeout=polling_interval_arg,
802
- show_stats=show_stats,
803
- doc_id_order=doc_id_order,
804
- lro_algorithms=[
805
- TextAnalyticsOperationResourcePolling(
806
- show_stats=show_stats,
807
- )
808
- ],
809
- **kwargs
810
- ),
811
- continuation_token=continuation_token,
812
- poller_cls=AnalyzeHealthcareEntitiesLROPoller,
813
- **kwargs
814
- )
815
- )
816
-
817
- # v3.1
818
- return cast(
819
- AnalyzeHealthcareEntitiesLROPoller[
820
- ItemPaged[Union[AnalyzeHealthcareEntitiesResult, DocumentError]]
821
- ],
822
- self._client.begin_health(
823
- docs,
824
- model_version=model_version,
825
- string_index_type=string_index_type_arg,
826
- logging_opt_out=disable_service_logs,
827
- cls=my_cls,
828
- polling=AnalyzeHealthcareEntitiesLROPollingMethod(
829
- text_analytics_client=self._client,
830
- timeout=polling_interval_arg,
831
- doc_id_order=doc_id_order,
832
- show_stats=show_stats,
833
- lro_algorithms=[
834
- TextAnalyticsOperationResourcePolling(
835
- show_stats=show_stats,
836
- )
837
- ],
838
- **kwargs
839
- ),
840
- continuation_token=continuation_token,
841
- **kwargs
842
- )
843
- )
844
- except HttpResponseError as error:
845
- return process_http_response_error(error)
846
-
847
- @distributed_trace
848
- @validate_multiapi_args(
849
- version_method_added="v3.0",
850
- args_mapping={"v3.1": ["disable_service_logs"]}
851
- )
852
- def extract_key_phrases(
853
- self,
854
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
855
- *,
856
- disable_service_logs: Optional[bool] = None,
857
- language: Optional[str] = None,
858
- model_version: Optional[str] = None,
859
- show_stats: Optional[bool] = None,
860
- **kwargs: Any
861
- ) -> List[Union[ExtractKeyPhrasesResult, DocumentError]]:
862
- """Extract key phrases from a batch of documents.
863
-
864
- Returns a list of strings denoting the key phrases in the input
865
- text. For example, for the input text "The food was delicious and there
866
- were wonderful staff", the API returns the main talking points: "food"
867
- and "wonderful staff"
868
-
869
- See https://aka.ms/azsdk/textanalytics/data-limits for service data limits.
870
-
871
- :param documents: The set of documents to process as part of this batch.
872
- If you wish to specify the ID and language on a per-item basis you must
873
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
874
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
875
- `{"id": "1", "language": "en", "text": "hello world"}`.
876
- :type documents:
877
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
878
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
879
- entire batch. For example, use "en" for English; "es" for Spanish etc.
880
- If not set, uses "en" for English as default. Per-document language will
881
- take precedence over whole batch language. See https://aka.ms/talangs for
882
- supported languages in Language API.
883
- :keyword str model_version: This value indicates which model will
884
- be used for scoring, e.g. "latest", "2019-10-01". If a model-version
885
- is not specified, the API will default to the latest, non-preview version.
886
- See here for more info: https://aka.ms/text-analytics-model-versioning
887
- :keyword bool show_stats: If set to true, response will contain document
888
- level statistics in the `statistics` field of the document-level response.
889
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
890
- logged on the service side for troubleshooting. By default, the Language service logs your
891
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
892
- the service's natural language processing functions. Setting this parameter to true,
893
- disables input logging and may limit our ability to remediate issues that occur. Please see
894
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
895
- additional details, and Microsoft Responsible AI principles at
896
- https://www.microsoft.com/ai/responsible-ai.
897
- :return: The combined list of :class:`~azure.ai.textanalytics.ExtractKeyPhrasesResult` and
898
- :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents were
899
- passed in.
900
- :rtype: list[~azure.ai.textanalytics.ExtractKeyPhrasesResult or ~azure.ai.textanalytics.DocumentError]
901
- :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError:
902
-
903
- .. versionadded:: v3.1
904
- The *disable_service_logs* keyword argument.
905
-
906
- .. admonition:: Example:
907
-
908
- .. literalinclude:: ../samples/sample_extract_key_phrases.py
909
- :start-after: [START extract_key_phrases]
910
- :end-before: [END extract_key_phrases]
911
- :language: python
912
- :dedent: 4
913
- :caption: Extract the key phrases in a batch of documents.
914
- """
915
-
916
- language_arg = language if language is not None else self._default_language
917
- docs = _validate_input(documents, "language", language_arg)
918
-
919
- try:
920
- if is_language_api(self._api_version):
921
- models = self._client.models(api_version=self._api_version)
922
- return cast(
923
- List[Union[ExtractKeyPhrasesResult, DocumentError]],
924
- self._client.analyze_text(
925
- body=models.AnalyzeTextKeyPhraseExtractionInput(
926
- analysis_input={"documents": docs},
927
- parameters=models.KeyPhraseTaskParameters(
928
- logging_opt_out=disable_service_logs,
929
- model_version=model_version,
930
- )
931
- ),
932
- show_stats=show_stats,
933
- cls=kwargs.pop("cls", key_phrases_result),
934
- **kwargs
935
- )
936
- )
937
-
938
- # api_versions 3.0, 3.1
939
- return cast(
940
- List[Union[ExtractKeyPhrasesResult, DocumentError]],
941
- self._client.key_phrases(
942
- documents=docs,
943
- model_version=model_version,
944
- show_stats=show_stats,
945
- logging_opt_out=disable_service_logs,
946
- cls=kwargs.pop("cls", key_phrases_result),
947
- **kwargs
948
- )
949
- )
950
- except HttpResponseError as error:
951
- return process_http_response_error(error)
952
-
953
- @distributed_trace
954
- @validate_multiapi_args(
955
- version_method_added="v3.0",
956
- args_mapping={"v3.1": ["show_opinion_mining", "disable_service_logs", "string_index_type"]}
957
- )
958
- def analyze_sentiment(
959
- self,
960
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
961
- *,
962
- disable_service_logs: Optional[bool] = None,
963
- language: Optional[str] = None,
964
- model_version: Optional[str] = None,
965
- show_opinion_mining: Optional[bool] = None,
966
- show_stats: Optional[bool] = None,
967
- string_index_type: Optional[str] = None,
968
- **kwargs: Any,
969
- ) -> List[Union[AnalyzeSentimentResult, DocumentError]]:
970
- """Analyze sentiment for a batch of documents. Turn on opinion mining with `show_opinion_mining`.
971
-
972
- Returns a sentiment prediction, as well as sentiment scores for
973
- each sentiment class (Positive, Negative, and Neutral) for the document
974
- and each sentence within it.
975
-
976
- See https://aka.ms/azsdk/textanalytics/data-limits for service data limits.
977
-
978
- :param documents: The set of documents to process as part of this batch.
979
- If you wish to specify the ID and language on a per-item basis you must
980
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
981
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
982
- `{"id": "1", "language": "en", "text": "hello world"}`.
983
- :type documents:
984
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
985
- :keyword bool show_opinion_mining: Whether to mine the opinions of a sentence and conduct more
986
- granular analysis around the aspects of a product or service (also known as
987
- aspect-based sentiment analysis). If set to true, the returned
988
- :class:`~azure.ai.textanalytics.SentenceSentiment` objects
989
- will have property `mined_opinions` containing the result of this analysis. Only available for
990
- API version v3.1 and up.
991
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
992
- entire batch. For example, use "en" for English; "es" for Spanish etc.
993
- If not set, uses "en" for English as default. Per-document language will
994
- take precedence over whole batch language. See https://aka.ms/talangs for
995
- supported languages in Language API.
996
- :keyword str model_version: This value indicates which model will
997
- be used for scoring, e.g. "latest", "2019-10-01". If a model-version
998
- is not specified, the API will default to the latest, non-preview version.
999
- See here for more info: https://aka.ms/text-analytics-model-versioning
1000
- :keyword bool show_stats: If set to true, response will contain document
1001
- level statistics in the `statistics` field of the document-level response.
1002
- :keyword str string_index_type: Specifies the method used to interpret string offsets.
1003
- `UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
1004
- you can also pass in `Utf16CodeUnit` or `TextElement_v8`. For additional information
1005
- see https://aka.ms/text-analytics-offsets
1006
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
1007
- logged on the service side for troubleshooting. By default, the Language service logs your
1008
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
1009
- the service's natural language processing functions. Setting this parameter to true,
1010
- disables input logging and may limit our ability to remediate issues that occur. Please see
1011
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
1012
- additional details, and Microsoft Responsible AI principles at
1013
- https://www.microsoft.com/ai/responsible-ai.
1014
- :return: The combined list of :class:`~azure.ai.textanalytics.AnalyzeSentimentResult` and
1015
- :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents were
1016
- passed in.
1017
- :rtype: list[~azure.ai.textanalytics.AnalyzeSentimentResult or ~azure.ai.textanalytics.DocumentError]
1018
- :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError:
1019
-
1020
- .. versionadded:: v3.1
1021
- The *show_opinion_mining*, *disable_service_logs*, and *string_index_type* keyword arguments.
1022
-
1023
- .. admonition:: Example:
1024
-
1025
- .. literalinclude:: ../samples/sample_analyze_sentiment.py
1026
- :start-after: [START analyze_sentiment]
1027
- :end-before: [END analyze_sentiment]
1028
- :language: python
1029
- :dedent: 4
1030
- :caption: Analyze sentiment in a batch of documents.
1031
- """
1032
-
1033
- language_arg = language if language is not None else self._default_language
1034
- docs = _validate_input(documents, "language", language_arg)
1035
- string_index_type_arg = string_index_type if string_index_type is not None else self._string_index_type_default
1036
-
1037
- try:
1038
- if is_language_api(self._api_version):
1039
- models = self._client.models(api_version=self._api_version)
1040
- return cast(
1041
- List[Union[AnalyzeSentimentResult, DocumentError]],
1042
- self._client.analyze_text(
1043
- body=models.AnalyzeTextSentimentAnalysisInput(
1044
- analysis_input={"documents": docs},
1045
- parameters=models.SentimentAnalysisTaskParameters(
1046
- logging_opt_out=disable_service_logs,
1047
- model_version=model_version,
1048
- string_index_type=string_index_type_compatibility(string_index_type_arg),
1049
- opinion_mining=show_opinion_mining,
1050
- )
1051
- ),
1052
- show_stats=show_stats,
1053
- cls=kwargs.pop("cls", sentiment_result),
1054
- **kwargs
1055
- )
1056
- )
1057
-
1058
- # api_versions 3.0, 3.1
1059
- return cast(
1060
- List[Union[AnalyzeSentimentResult, DocumentError]],
1061
- self._client.sentiment(
1062
- documents=docs,
1063
- logging_opt_out=disable_service_logs,
1064
- model_version=model_version,
1065
- string_index_type=string_index_type_arg,
1066
- opinion_mining=show_opinion_mining,
1067
- show_stats=show_stats,
1068
- cls=kwargs.pop("cls", sentiment_result),
1069
- **kwargs
1070
- )
1071
- )
1072
- except HttpResponseError as error:
1073
- return process_http_response_error(error)
1074
-
1075
- def _analyze_result_callback(
1076
- self, raw_response, deserialized, doc_id_order, task_id_order=None, show_stats=False, bespoke=False
1077
- ):
1078
-
1079
- if deserialized is None:
1080
- models = self._client.models(api_version=self._api_version)
1081
- response_cls = models.AnalyzeTextJobState if is_language_api(self._api_version) else models.AnalyzeJobState
1082
- deserialized = response_cls.deserialize(raw_response)
1083
- return analyze_paged_result(
1084
- doc_id_order,
1085
- task_id_order,
1086
- self._client.analyze_text_job_status if is_language_api(self._api_version) else self._client.analyze_status,
1087
- raw_response,
1088
- deserialized,
1089
- show_stats=show_stats,
1090
- bespoke=bespoke
1091
- )
1092
-
1093
- @distributed_trace
1094
- @validate_multiapi_args(
1095
- version_method_added="v3.1",
1096
- custom_wrapper=check_for_unsupported_actions_types,
1097
- )
1098
- def begin_analyze_actions(
1099
- self,
1100
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
1101
- actions: List[
1102
- Union[
1103
- RecognizeEntitiesAction,
1104
- RecognizeLinkedEntitiesAction,
1105
- RecognizePiiEntitiesAction,
1106
- ExtractKeyPhrasesAction,
1107
- AnalyzeSentimentAction,
1108
- RecognizeCustomEntitiesAction,
1109
- SingleLabelClassifyAction,
1110
- MultiLabelClassifyAction,
1111
- AnalyzeHealthcareEntitiesAction,
1112
- ExtractSummaryAction,
1113
- AbstractiveSummaryAction,
1114
- ]
1115
- ],
1116
- *,
1117
- continuation_token: Optional[str] = None,
1118
- display_name: Optional[str] = None,
1119
- language: Optional[str] = None,
1120
- polling_interval: Optional[int] = None,
1121
- show_stats: Optional[bool] = None,
1122
- **kwargs: Any,
1123
- ) -> TextAnalysisLROPoller[
1124
- ItemPaged[
1125
- List[
1126
- Union[
1127
- RecognizeEntitiesResult,
1128
- RecognizeLinkedEntitiesResult,
1129
- RecognizePiiEntitiesResult,
1130
- ExtractKeyPhrasesResult,
1131
- AnalyzeSentimentResult,
1132
- RecognizeCustomEntitiesResult,
1133
- ClassifyDocumentResult,
1134
- AnalyzeHealthcareEntitiesResult,
1135
- ExtractSummaryResult,
1136
- AbstractiveSummaryResult,
1137
- DocumentError,
1138
- ]
1139
- ]
1140
- ]
1141
- ]:
1142
- """Start a long-running operation to perform a variety of text analysis actions over a batch of documents.
1143
-
1144
- We recommend you use this function if you're looking to analyze larger documents, and / or
1145
- combine multiple text analysis actions into one call. Otherwise, we recommend you use
1146
- the action specific endpoints, for example :func:`analyze_sentiment`.
1147
-
1148
- .. note:: The abstractive summarization feature is part of a gated preview. Request access here:
1149
- https://aka.ms/applyforgatedsummarizationfeatures
1150
-
1151
- .. note:: See the service documentation for regional support of custom action features:
1152
- https://aka.ms/azsdk/textanalytics/customfunctionalities
1153
-
1154
- :param documents: The set of documents to process as part of this batch.
1155
- If you wish to specify the ID and language on a per-item basis you must
1156
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
1157
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
1158
- `{"id": "1", "language": "en", "text": "hello world"}`.
1159
- :type documents:
1160
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
1161
- :param actions: A heterogeneous list of actions to perform on the input documents.
1162
- Each action object encapsulates the parameters used for the particular action type.
1163
- The action results will be in the same order of the input actions.
1164
- :type actions:
1165
- list[RecognizeEntitiesAction or RecognizePiiEntitiesAction or ExtractKeyPhrasesAction or
1166
- RecognizeLinkedEntitiesAction or AnalyzeSentimentAction or
1167
- RecognizeCustomEntitiesAction or SingleLabelClassifyAction or
1168
- MultiLabelClassifyAction or AnalyzeHealthcareEntitiesAction or ExtractSummaryAction
1169
- or AbstractiveSummaryAction]
1170
- :keyword str display_name: An optional display name to set for the requested analysis.
1171
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
1172
- entire batch. For example, use "en" for English; "es" for Spanish etc.
1173
- For automatic language detection, use "auto" (Only supported by API version
1174
- 2022-10-01-preview and newer). If not set, uses "en" for English as default.
1175
- Per-document language will take precedence over whole batch language.
1176
- See https://aka.ms/talangs for supported languages in Language API.
1177
- :keyword bool show_stats: If set to true, response will contain document level statistics.
1178
- :keyword int polling_interval: Waiting time between two polls for LRO operations
1179
- if no Retry-After header is present. Defaults to 5 seconds.
1180
- :keyword str continuation_token:
1181
- Call `continuation_token()` on the poller object to save the long-running operation (LRO)
1182
- state into an opaque token. Pass the value as the `continuation_token` keyword argument
1183
- to restart the LRO from a saved state.
1184
- :return: An instance of an TextAnalysisLROPoller. Call `result()` on the poller
1185
- object to return a pageable heterogeneous list of lists. This list of lists is first ordered
1186
- by the documents you input, then ordered by the actions you input. For example,
1187
- if you have documents input ["Hello", "world"], and actions
1188
- :class:`~azure.ai.textanalytics.RecognizeEntitiesAction` and
1189
- :class:`~azure.ai.textanalytics.AnalyzeSentimentAction`, when iterating over the list of lists,
1190
- you will first iterate over the action results for the "Hello" document, getting the
1191
- :class:`~azure.ai.textanalytics.RecognizeEntitiesResult` of "Hello",
1192
- then the :class:`~azure.ai.textanalytics.AnalyzeSentimentResult` of "Hello".
1193
- Then, you will get the :class:`~azure.ai.textanalytics.RecognizeEntitiesResult` and
1194
- :class:`~azure.ai.textanalytics.AnalyzeSentimentResult` of "world".
1195
- :rtype:
1196
- ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[
1197
- list[RecognizeEntitiesResult or RecognizeLinkedEntitiesResult or RecognizePiiEntitiesResult or
1198
- ExtractKeyPhrasesResult or AnalyzeSentimentResult or RecognizeCustomEntitiesResult
1199
- or ClassifyDocumentResult or AnalyzeHealthcareEntitiesResult or ExtractSummaryResult
1200
- or AbstractiveSummaryResult or DocumentError]]]
1201
- :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError:
1202
-
1203
- .. versionadded:: v3.1
1204
- The *begin_analyze_actions* client method.
1205
- .. versionadded:: 2022-05-01
1206
- The *RecognizeCustomEntitiesAction*, *SingleLabelClassifyAction*,
1207
- *MultiLabelClassifyAction*, and *AnalyzeHealthcareEntitiesAction* input options and the
1208
- corresponding *RecognizeCustomEntitiesResult*, *ClassifyDocumentResult*,
1209
- and *AnalyzeHealthcareEntitiesResult* result objects
1210
- .. versionadded:: 2022-10-01-preview
1211
- The *ExtractSummaryAction* and *AbstractSummaryAction* input options and the corresponding
1212
- *ExtractSummaryResult* and *AbstractSummaryResult* result objects.
1213
-
1214
- .. admonition:: Example:
1215
-
1216
- .. literalinclude:: ../samples/sample_analyze_actions.py
1217
- :start-after: [START analyze]
1218
- :end-before: [END analyze]
1219
- :language: python
1220
- :dedent: 4
1221
- :caption: Start a long-running operation to perform a variety of text analysis
1222
- actions over a batch of documents.
1223
- """
1224
-
1225
- language_arg = language if language is not None else self._default_language
1226
- polling_interval_arg = polling_interval if polling_interval is not None else 5
1227
- bespoke = kwargs.pop("bespoke", False)
1228
-
1229
- if continuation_token:
1230
- return cast(
1231
- AnalyzeActionsResponse,
1232
- _get_result_from_continuation_token(
1233
- self._client._client, # pylint: disable=protected-access
1234
- continuation_token,
1235
- AnalyzeActionsLROPoller,
1236
- AnalyzeActionsLROPollingMethod(
1237
- text_analytics_client=self._client,
1238
- timeout=polling_interval_arg,
1239
- **kwargs
1240
- ),
1241
- self._analyze_result_callback,
1242
- bespoke
1243
- )
1244
- )
1245
-
1246
- models = self._client.models(api_version=self._api_version)
1247
-
1248
- input_model_cls = \
1249
- models.MultiLanguageAnalysisInput if is_language_api(self._api_version) else models.MultiLanguageBatchInput
1250
- docs = input_model_cls(
1251
- documents=_validate_input(documents, "language", language_arg)
1252
- )
1253
- doc_id_order = [doc.get("id") for doc in docs.documents]
1254
- try:
1255
- generated_tasks = [
1256
- action._to_generated(self._api_version, str(idx)) # pylint: disable=protected-access
1257
- for idx, action in enumerate(actions)
1258
- ]
1259
- except AttributeError as e:
1260
- raise TypeError("Unsupported action type in list.") from e
1261
- task_order = [(_determine_action_type(a), a.task_name) for a in generated_tasks]
1262
- response_cls = kwargs.pop(
1263
- "cls",
1264
- lambda pipeline_response, deserialized, _:
1265
- self._analyze_result_callback(
1266
- pipeline_response,
1267
- deserialized,
1268
- doc_id_order,
1269
- task_id_order=task_order,
1270
- show_stats=show_stats,
1271
- bespoke=bespoke
1272
- ),
1273
- )
1274
-
1275
- try:
1276
- if is_language_api(self._api_version):
1277
- return cast(
1278
- AnalyzeActionsResponse,
1279
- self._client.begin_analyze_text_submit_job(
1280
- body=models.AnalyzeTextJobsInput(
1281
- analysis_input=docs,
1282
- display_name=display_name,
1283
- tasks=generated_tasks
1284
- ),
1285
- cls=response_cls,
1286
- polling=AnalyzeActionsLROPollingMethod(
1287
- text_analytics_client=self._client,
1288
- timeout=polling_interval_arg,
1289
- show_stats=show_stats,
1290
- doc_id_order=doc_id_order,
1291
- task_id_order=task_order,
1292
- lro_algorithms=[
1293
- TextAnalyticsOperationResourcePolling(
1294
- show_stats=show_stats,
1295
- )
1296
- ],
1297
- **kwargs
1298
- ),
1299
- continuation_token=continuation_token,
1300
- **kwargs
1301
- )
1302
- )
1303
-
1304
- # v3.1
1305
- analyze_tasks = models.JobManifestTasks(
1306
- entity_recognition_tasks=[
1307
- a for a in generated_tasks
1308
- if _determine_action_type(a) == _AnalyzeActionsType.RECOGNIZE_ENTITIES
1309
- ],
1310
- entity_recognition_pii_tasks=[
1311
- a for a in generated_tasks
1312
- if _determine_action_type(a) == _AnalyzeActionsType.RECOGNIZE_PII_ENTITIES
1313
- ],
1314
- key_phrase_extraction_tasks=[
1315
- a for a in generated_tasks
1316
- if _determine_action_type(a) == _AnalyzeActionsType.EXTRACT_KEY_PHRASES
1317
- ],
1318
- entity_linking_tasks=[
1319
- a for a in generated_tasks
1320
- if _determine_action_type(a) == _AnalyzeActionsType.RECOGNIZE_LINKED_ENTITIES
1321
- ],
1322
- sentiment_analysis_tasks=[
1323
- a for a in generated_tasks
1324
- if _determine_action_type(a) == _AnalyzeActionsType.ANALYZE_SENTIMENT
1325
- ],
1326
- )
1327
- analyze_body = models.AnalyzeBatchInput(
1328
- display_name=display_name, tasks=analyze_tasks, analysis_input=docs
1329
- )
1330
- return cast(
1331
- AnalyzeActionsResponse,
1332
- self._client.begin_analyze(
1333
- body=analyze_body,
1334
- cls=response_cls,
1335
- polling=AnalyzeActionsLROPollingMethod(
1336
- text_analytics_client=self._client,
1337
- timeout=polling_interval_arg,
1338
- show_stats=show_stats,
1339
- doc_id_order=doc_id_order,
1340
- task_id_order=task_order,
1341
- lro_algorithms=[
1342
- TextAnalyticsOperationResourcePolling(
1343
- show_stats=show_stats,
1344
- )
1345
- ],
1346
- **kwargs
1347
- ),
1348
- continuation_token=continuation_token,
1349
- **kwargs
1350
- )
1351
- )
1352
- except HttpResponseError as error:
1353
- return process_http_response_error(error)
1354
-
1355
- @distributed_trace
1356
- @validate_multiapi_args(
1357
- version_method_added="2022-05-01",
1358
- )
1359
- def begin_recognize_custom_entities(
1360
- self,
1361
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
1362
- project_name: str,
1363
- deployment_name: str,
1364
- *,
1365
- continuation_token: Optional[str] = None,
1366
- disable_service_logs: Optional[bool] = None,
1367
- display_name: Optional[str] = None,
1368
- language: Optional[str] = None,
1369
- polling_interval: Optional[int] = None,
1370
- show_stats: Optional[bool] = None,
1371
- string_index_type: Optional[str] = None,
1372
- **kwargs: Any,
1373
- ) -> TextAnalysisLROPoller[ItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]]:
1374
- """Start a long-running custom named entity recognition operation.
1375
-
1376
- For information on regional support of custom features and how to train a model to
1377
- recognize custom entities, see https://aka.ms/azsdk/textanalytics/customentityrecognition
1378
-
1379
- :param documents: The set of documents to process as part of this batch.
1380
- If you wish to specify the ID and language on a per-item basis you must
1381
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
1382
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
1383
- `{"id": "1", "language": "en", "text": "hello world"}`.
1384
- :type documents:
1385
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
1386
- :param str project_name: Required. This field indicates the project name for the model.
1387
- :param str deployment_name: This field indicates the deployment name for the model.
1388
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
1389
- entire batch. For example, use "en" for English; "es" for Spanish etc.
1390
- For automatic language detection, use "auto" (Only supported by API version
1391
- 2022-10-01-preview and newer). If not set, uses "en" for English as default.
1392
- Per-document language will take precedence over whole batch language.
1393
- See https://aka.ms/talangs for supported languages in Language API.
1394
- :keyword bool show_stats: If set to true, response will contain document level statistics.
1395
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
1396
- logged on the service side for troubleshooting. By default, the Language service logs your
1397
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
1398
- the service's natural language processing functions. Setting this parameter to true,
1399
- disables input logging and may limit our ability to remediate issues that occur. Please see
1400
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
1401
- additional details, and Microsoft Responsible AI principles at
1402
- https://www.microsoft.com/ai/responsible-ai.
1403
- :keyword str string_index_type: Specifies the method used to interpret string offsets.
1404
- `UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
1405
- you can also pass in `Utf16CodeUnit` or `TextElement_v8`. For additional information
1406
- see https://aka.ms/text-analytics-offsets
1407
- :keyword int polling_interval: Waiting time between two polls for LRO operations
1408
- if no Retry-After header is present. Defaults to 5 seconds.
1409
- :keyword str continuation_token:
1410
- Call `continuation_token()` on the poller object to save the long-running operation (LRO)
1411
- state into an opaque token. Pass the value as the `continuation_token` keyword argument
1412
- to restart the LRO from a saved state.
1413
- :keyword str display_name: An optional display name to set for the requested analysis.
1414
- :return: An instance of an TextAnalysisLROPoller. Call `result()` on the this
1415
- object to return a heterogeneous pageable of
1416
- :class:`~azure.ai.textanalytics.RecognizeCustomEntitiesResult` and
1417
- :class:`~azure.ai.textanalytics.DocumentError`.
1418
- :rtype:
1419
- ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[
1420
- ~azure.ai.textanalytics.RecognizeCustomEntitiesResult or ~azure.ai.textanalytics.DocumentError]]
1421
- :raises ~azure.core.exceptions.HttpResponseError:
1422
-
1423
- .. versionadded:: 2022-05-01
1424
- The *begin_recognize_custom_entities* client method.
1425
-
1426
- .. admonition:: Example:
1427
-
1428
- .. literalinclude:: ../samples/sample_recognize_custom_entities.py
1429
- :start-after: [START recognize_custom_entities]
1430
- :end-before: [END recognize_custom_entities]
1431
- :language: python
1432
- :dedent: 4
1433
- :caption: Recognize custom entities in a batch of documents.
1434
- """
1435
-
1436
- polling_interval_arg = polling_interval if polling_interval is not None else 5
1437
- string_index_type_arg = string_index_type if string_index_type is not None else self._string_index_type_default
1438
-
1439
- if continuation_token:
1440
- return cast(
1441
- TextAnalysisLROPoller[ItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]],
1442
- _get_result_from_continuation_token(
1443
- self._client._client, # pylint: disable=protected-access
1444
- continuation_token,
1445
- AnalyzeActionsLROPoller,
1446
- AnalyzeActionsLROPollingMethod(
1447
- text_analytics_client=self._client,
1448
- timeout=polling_interval_arg,
1449
- **kwargs
1450
- ),
1451
- self._analyze_result_callback,
1452
- bespoke=True
1453
- )
1454
- )
1455
-
1456
- try:
1457
- return cast(
1458
- TextAnalysisLROPoller[
1459
- ItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]
1460
- ],
1461
- self.begin_analyze_actions(
1462
- documents,
1463
- actions=[
1464
- RecognizeCustomEntitiesAction(
1465
- project_name=project_name,
1466
- deployment_name=deployment_name,
1467
- string_index_type=string_index_type_arg,
1468
- disable_service_logs=disable_service_logs
1469
- )
1470
- ],
1471
- display_name=display_name,
1472
- show_stats=show_stats,
1473
- language=language,
1474
- polling_interval=polling_interval_arg,
1475
- bespoke=True,
1476
- **kwargs
1477
- )
1478
- )
1479
-
1480
- except HttpResponseError as error:
1481
- return process_http_response_error(error)
1482
-
1483
- @distributed_trace
1484
- @validate_multiapi_args(
1485
- version_method_added="2022-05-01",
1486
- )
1487
- def begin_single_label_classify(
1488
- self,
1489
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
1490
- project_name: str,
1491
- deployment_name: str,
1492
- *,
1493
- continuation_token: Optional[str] = None,
1494
- disable_service_logs: Optional[bool] = None,
1495
- display_name: Optional[str] = None,
1496
- language: Optional[str] = None,
1497
- polling_interval: Optional[int] = None,
1498
- show_stats: Optional[bool] = None,
1499
- **kwargs: Any,
1500
- ) -> TextAnalysisLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]]:
1501
- """Start a long-running custom single label classification operation.
1502
-
1503
- For information on regional support of custom features and how to train a model to
1504
- classify your documents, see https://aka.ms/azsdk/textanalytics/customfunctionalities
1505
-
1506
- :param documents: The set of documents to process as part of this batch.
1507
- If you wish to specify the ID and language on a per-item basis you must
1508
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
1509
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
1510
- `{"id": "1", "language": "en", "text": "hello world"}`.
1511
- :type documents:
1512
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
1513
- :param str project_name: Required. This field indicates the project name for the model.
1514
- :param str deployment_name: This field indicates the deployment name for the model.
1515
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
1516
- entire batch. For example, use "en" for English; "es" for Spanish etc.
1517
- For automatic language detection, use "auto" (Only supported by API version
1518
- 2022-10-01-preview and newer). If not set, uses "en" for English as default.
1519
- Per-document language will take precedence over whole batch language.
1520
- See https://aka.ms/talangs for supported languages in Language API.
1521
- :keyword bool show_stats: If set to true, response will contain document level statistics.
1522
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
1523
- logged on the service side for troubleshooting. By default, the Language service logs your
1524
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
1525
- the service's natural language processing functions. Setting this parameter to true,
1526
- disables input logging and may limit our ability to remediate issues that occur. Please see
1527
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
1528
- additional details, and Microsoft Responsible AI principles at
1529
- https://www.microsoft.com/ai/responsible-ai.
1530
- :keyword int polling_interval: Waiting time between two polls for LRO operations
1531
- if no Retry-After header is present. Defaults to 5 seconds.
1532
- :keyword str continuation_token:
1533
- Call `continuation_token()` on the poller object to save the long-running operation (LRO)
1534
- state into an opaque token. Pass the value as the `continuation_token` keyword argument
1535
- to restart the LRO from a saved state.
1536
- :keyword str display_name: An optional display name to set for the requested analysis.
1537
- :return: An instance of an TextAnalysisLROPoller. Call `result()` on the this
1538
- object to return a heterogeneous pageable of
1539
- :class:`~azure.ai.textanalytics.ClassifyDocumentResult` and
1540
- :class:`~azure.ai.textanalytics.DocumentError`.
1541
- :rtype:
1542
- ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[
1543
- ~azure.ai.textanalytics.ClassifyDocumentResult or ~azure.ai.textanalytics.DocumentError]]
1544
- :raises ~azure.core.exceptions.HttpResponseError:
1545
-
1546
- .. versionadded:: 2022-05-01
1547
- The *begin_single_label_classify* client method.
1548
-
1549
- .. admonition:: Example:
1550
-
1551
- .. literalinclude:: ../samples/sample_single_label_classify.py
1552
- :start-after: [START single_label_classify]
1553
- :end-before: [END single_label_classify]
1554
- :language: python
1555
- :dedent: 4
1556
- :caption: Perform single label classification on a batch of documents.
1557
- """
1558
-
1559
- polling_interval_arg = polling_interval if polling_interval is not None else 5
1560
-
1561
- if continuation_token:
1562
- return cast(
1563
- TextAnalysisLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]],
1564
- _get_result_from_continuation_token(
1565
- self._client._client, # pylint: disable=protected-access
1566
- continuation_token,
1567
- AnalyzeActionsLROPoller,
1568
- AnalyzeActionsLROPollingMethod(
1569
- text_analytics_client=self._client,
1570
- timeout=polling_interval_arg,
1571
- **kwargs
1572
- ),
1573
- self._analyze_result_callback,
1574
- bespoke=True
1575
- )
1576
- )
1577
-
1578
- try:
1579
- return cast(
1580
- TextAnalysisLROPoller[
1581
- ItemPaged[Union[ClassifyDocumentResult, DocumentError]]
1582
- ],
1583
- self.begin_analyze_actions(
1584
- documents,
1585
- actions=[
1586
- SingleLabelClassifyAction(
1587
- project_name=project_name,
1588
- deployment_name=deployment_name,
1589
- disable_service_logs=disable_service_logs
1590
- )
1591
- ],
1592
- polling_interval=polling_interval_arg,
1593
- display_name=display_name,
1594
- show_stats=show_stats,
1595
- language=language,
1596
- bespoke=True,
1597
- **kwargs
1598
- )
1599
- )
1600
-
1601
- except HttpResponseError as error:
1602
- return process_http_response_error(error)
1603
-
1604
- @distributed_trace
1605
- @validate_multiapi_args(
1606
- version_method_added="2022-05-01",
1607
- )
1608
- def begin_multi_label_classify(
1609
- self,
1610
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
1611
- project_name: str,
1612
- deployment_name: str,
1613
- *,
1614
- continuation_token: Optional[str] = None,
1615
- disable_service_logs: Optional[bool] = None,
1616
- display_name: Optional[str] = None,
1617
- language: Optional[str] = None,
1618
- polling_interval: Optional[int] = None,
1619
- show_stats: Optional[bool] = None,
1620
- **kwargs: Any,
1621
- ) -> TextAnalysisLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]]:
1622
- """Start a long-running custom multi label classification operation.
1623
-
1624
- For information on regional support of custom features and how to train a model to
1625
- classify your documents, see https://aka.ms/azsdk/textanalytics/customfunctionalities
1626
-
1627
- :param documents: The set of documents to process as part of this batch.
1628
- If you wish to specify the ID and language on a per-item basis you must
1629
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
1630
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
1631
- `{"id": "1", "language": "en", "text": "hello world"}`.
1632
- :type documents:
1633
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
1634
- :param str project_name: Required. This field indicates the project name for the model.
1635
- :param str deployment_name: This field indicates the deployment name for the model.
1636
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
1637
- entire batch. For example, use "en" for English; "es" for Spanish etc.
1638
- For automatic language detection, use "auto" (Only supported by API version
1639
- 2022-10-01-preview and newer). If not set, uses "en" for English as default.
1640
- Per-document language will take precedence over whole batch language.
1641
- See https://aka.ms/talangs for supported languages in Language API.
1642
- :keyword bool show_stats: If set to true, response will contain document level statistics.
1643
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
1644
- logged on the service side for troubleshooting. By default, the Language service logs your
1645
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
1646
- the service's natural language processing functions. Setting this parameter to true,
1647
- disables input logging and may limit our ability to remediate issues that occur. Please see
1648
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
1649
- additional details, and Microsoft Responsible AI principles at
1650
- https://www.microsoft.com/ai/responsible-ai.
1651
- :keyword int polling_interval: Waiting time between two polls for LRO operations
1652
- if no Retry-After header is present. Defaults to 5 seconds.
1653
- :keyword str continuation_token:
1654
- Call `continuation_token()` on the poller object to save the long-running operation (LRO)
1655
- state into an opaque token. Pass the value as the `continuation_token` keyword argument
1656
- to restart the LRO from a saved state.
1657
- :keyword str display_name: An optional display name to set for the requested analysis.
1658
- :return: An instance of an TextAnalysisLROPoller. Call `result()` on the this
1659
- object to return a heterogeneous pageable of
1660
- :class:`~azure.ai.textanalytics.ClassifyDocumentResult` and
1661
- :class:`~azure.ai.textanalytics.DocumentError`.
1662
- :rtype:
1663
- ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[
1664
- ~azure.ai.textanalytics.ClassifyDocumentResult or ~azure.ai.textanalytics.DocumentError]]
1665
- :raises ~azure.core.exceptions.HttpResponseError:
1666
-
1667
- .. versionadded:: 2022-05-01
1668
- The *begin_multi_label_classify* client method.
1669
-
1670
- .. admonition:: Example:
1671
-
1672
- .. literalinclude:: ../samples/sample_multi_label_classify.py
1673
- :start-after: [START multi_label_classify]
1674
- :end-before: [END multi_label_classify]
1675
- :language: python
1676
- :dedent: 4
1677
- :caption: Perform multi label classification on a batch of documents.
1678
- """
1679
-
1680
- polling_interval_arg = polling_interval if polling_interval is not None else 5
1681
-
1682
- if continuation_token:
1683
- return cast(
1684
- TextAnalysisLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]],
1685
- _get_result_from_continuation_token(
1686
- self._client._client, # pylint: disable=protected-access
1687
- continuation_token,
1688
- AnalyzeActionsLROPoller,
1689
- AnalyzeActionsLROPollingMethod(
1690
- text_analytics_client=self._client,
1691
- timeout=polling_interval_arg,
1692
- **kwargs
1693
- ),
1694
- self._analyze_result_callback,
1695
- bespoke=True
1696
- )
1697
- )
1698
-
1699
- try:
1700
- return cast(
1701
- TextAnalysisLROPoller[
1702
- ItemPaged[Union[ClassifyDocumentResult, DocumentError]]
1703
- ],
1704
- self.begin_analyze_actions(
1705
- documents,
1706
- actions=[
1707
- MultiLabelClassifyAction(
1708
- project_name=project_name,
1709
- deployment_name=deployment_name,
1710
- disable_service_logs=disable_service_logs
1711
- )
1712
- ],
1713
- polling_interval=polling_interval_arg,
1714
- display_name=display_name,
1715
- show_stats=show_stats,
1716
- language=language,
1717
- bespoke=True,
1718
- **kwargs
1719
- )
1720
- )
1721
-
1722
- except HttpResponseError as error:
1723
- return process_http_response_error(error)
1724
-
1725
- @distributed_trace
1726
- @validate_multiapi_args(
1727
- version_method_added="2022-10-01-preview",
1728
- )
1729
- def dynamic_classification(
1730
- self,
1731
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
1732
- categories: List[str],
1733
- *,
1734
- classification_type: Optional[Union[str, ClassificationType]] = None,
1735
- disable_service_logs: Optional[bool] = None,
1736
- language: Optional[str] = None,
1737
- model_version: Optional[str] = None,
1738
- show_stats: Optional[bool] = None,
1739
- **kwargs: Any,
1740
- ) -> List[Union[DynamicClassificationResult, DocumentError]]:
1741
- """Perform dynamic classification on a batch of documents.
1742
-
1743
- On the fly classification of the input documents into one or multiple categories.
1744
- Assigns either one or multiple categories per document. This type of classification
1745
- doesn't require model training.
1746
-
1747
- .. note:: The dynamic classification feature is part of a gated preview. Request access here:
1748
- https://aka.ms/applyforgatedlanguagefeature
1749
-
1750
- See https://aka.ms/azsdk/textanalytics/data-limits for service data limits.
1751
-
1752
- :param documents: The set of documents to process as part of this batch.
1753
- If you wish to specify the ID and language on a per-item basis you must
1754
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list
1755
- of dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`,
1756
- like `{"id": "1", "language": "en", "text": "hello world"}`.
1757
- :type documents:
1758
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
1759
- :param list[str] categories: A list of categories to which input is classified to.
1760
- :keyword classification_type: Specifies either one or multiple categories per document. Defaults
1761
- to multi classification which may return more than one class for each document. Known values
1762
- are: "Single" and "Multi".
1763
- :paramtype classification_type: str or ~azure.ai.textanalytics.ClassificationType
1764
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
1765
- entire batch. For example, use "en" for English; "es" for Spanish etc.
1766
- If not set, uses "en" for English as default. Per-document language will
1767
- take precedence over whole batch language. See https://aka.ms/talangs for
1768
- supported languages in Language API.
1769
- :keyword str model_version: This value indicates which model will
1770
- be used for scoring, e.g. "latest", "2019-10-01". If a model-version
1771
- is not specified, the API will default to the latest, non-preview version.
1772
- See here for more info: https://aka.ms/text-analytics-model-versioning
1773
- :keyword bool show_stats: If set to true, response will contain document
1774
- level statistics in the `statistics` field of the document-level response.
1775
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
1776
- logged on the service side for troubleshooting. By default, the Language service logs your
1777
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
1778
- the service's natural language processing functions. Setting this parameter to true,
1779
- disables input logging and may limit our ability to remediate issues that occur. Please see
1780
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
1781
- additional details, and Microsoft Responsible AI principles at
1782
- https://www.microsoft.com/ai/responsible-ai.
1783
- :return: The combined list of :class:`~azure.ai.textanalytics.DynamicClassificationResult` and
1784
- :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents
1785
- were passed in.
1786
- :rtype: list[~azure.ai.textanalytics.DynamicClassificationResult or ~azure.ai.textanalytics.DocumentError]
1787
- :raises ~azure.core.exceptions.HttpResponseError:
1788
-
1789
- .. versionadded:: 2022-10-01-preview
1790
- The *dynamic_classification* client method.
1791
-
1792
- .. admonition:: Example:
1793
-
1794
- .. literalinclude:: ../samples/sample_dynamic_classification.py
1795
- :start-after: [START dynamic_classification]
1796
- :end-before: [END dynamic_classification]
1797
- :language: python
1798
- :dedent: 4
1799
- :caption: Perform dynamic classification on a batch of documents.
1800
- """
1801
-
1802
- language_arg = language if language is not None else self._default_language
1803
- docs = _validate_input(documents, "language", language_arg)
1804
-
1805
- try:
1806
- models = self._client.models(api_version=self._api_version)
1807
- return cast(
1808
- List[Union[DynamicClassificationResult, DocumentError]],
1809
- self._client.analyze_text(
1810
- body=models.AnalyzeTextDynamicClassificationInput(
1811
- analysis_input={"documents": docs},
1812
- parameters=models.DynamicClassificationTaskParameters(
1813
- categories=categories,
1814
- logging_opt_out=disable_service_logs,
1815
- model_version=model_version,
1816
- classification_type=classification_type,
1817
- )
1818
- ),
1819
- show_stats=show_stats,
1820
- cls=kwargs.pop("cls", dynamic_classification_result),
1821
- **kwargs
1822
- )
1823
- )
1824
- except HttpResponseError as error:
1825
- return process_http_response_error(error)
1826
-
1827
- @distributed_trace
1828
- @validate_multiapi_args(
1829
- version_method_added="2022-10-01-preview"
1830
- )
1831
- def begin_extract_summary(
1832
- self,
1833
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
1834
- *,
1835
- continuation_token: Optional[str] = None,
1836
- disable_service_logs: Optional[bool] = None,
1837
- display_name: Optional[str] = None,
1838
- language: Optional[str] = None,
1839
- polling_interval: Optional[int] = None,
1840
- show_stats: Optional[bool] = None,
1841
- model_version: Optional[str] = None,
1842
- string_index_type: Optional[str] = None,
1843
- max_sentence_count: Optional[int] = None,
1844
- order_by: Optional[str] = None,
1845
- **kwargs: Any,
1846
- ) -> TextAnalysisLROPoller[ItemPaged[Union[ExtractSummaryResult, DocumentError]]]:
1847
- """Start a long-running extractive summarization operation.
1848
-
1849
- For a conceptual discussion of extractive summarization, see the service documentation:
1850
- https://learn.microsoft.com/azure/cognitive-services/language-service/summarization/overview
1851
-
1852
- :param documents: The set of documents to process as part of this batch.
1853
- If you wish to specify the ID and language on a per-item basis you must
1854
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
1855
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
1856
- `{"id": "1", "language": "en", "text": "hello world"}`.
1857
- :type documents:
1858
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
1859
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
1860
- entire batch. For example, use "en" for English; "es" for Spanish etc.
1861
- For automatic language detection, use "auto" (Only supported by API version
1862
- 2022-10-01-preview and newer). If not set, uses "en" for English as default.
1863
- Per-document language will take precedence over whole batch language.
1864
- See https://aka.ms/talangs for supported languages in Language API.
1865
- :keyword bool show_stats: If set to true, response will contain document level statistics.
1866
- :keyword Optional[int] max_sentence_count: Maximum number of sentences to return. Defaults to 3.
1867
- :keyword Optional[str] order_by: Possible values include: "Offset", "Rank". Default value: "Offset".
1868
- :keyword Optional[str] model_version: The model version to use for the analysis.
1869
- :keyword Optional[str] string_index_type: Specifies the method used to interpret string offsets.
1870
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
1871
- logged on the service side for troubleshooting. By default, the Language service logs your
1872
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
1873
- the service's natural language processing functions. Setting this parameter to true,
1874
- disables input logging and may limit our ability to remediate issues that occur. Please see
1875
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
1876
- additional details, and Microsoft Responsible AI principles at
1877
- https://www.microsoft.com/ai/responsible-ai.
1878
- :keyword int polling_interval: Waiting time between two polls for LRO operations
1879
- if no Retry-After header is present. Defaults to 5 seconds.
1880
- :keyword str continuation_token:
1881
- Call `continuation_token()` on the poller object to save the long-running operation (LRO)
1882
- state into an opaque token. Pass the value as the `continuation_token` keyword argument
1883
- to restart the LRO from a saved state.
1884
- :keyword str display_name: An optional display name to set for the requested analysis.
1885
- :return: An instance of an TextAnalysisLROPoller. Call `result()` on the this
1886
- object to return a heterogeneous pageable of
1887
- :class:`~azure.ai.textanalytics.ExtractSummaryResult` and
1888
- :class:`~azure.ai.textanalytics.DocumentError`.
1889
- :rtype:
1890
- ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[
1891
- ~azure.ai.textanalytics.ExtractSummaryResult or ~azure.ai.textanalytics.DocumentError]]
1892
- :raises ~azure.core.exceptions.HttpResponseError:
1893
-
1894
- .. versionadded:: 2022-10-01-preview
1895
- The *begin_extract_summary* client method.
1896
-
1897
- .. admonition:: Example:
1898
-
1899
- .. literalinclude:: ../samples/sample_extract_summary.py
1900
- :start-after: [START extract_summary]
1901
- :end-before: [END extract_summary]
1902
- :language: python
1903
- :dedent: 4
1904
- :caption: Perform extractive summarization on a batch of documents.
1905
- """
1906
-
1907
- polling_interval_arg = polling_interval if polling_interval is not None else 5
1908
- string_index_type_arg = string_index_type if string_index_type is not None else self._string_index_type_default
1909
-
1910
- if continuation_token:
1911
- return cast(
1912
- TextAnalysisLROPoller[ItemPaged[Union[ExtractSummaryResult, DocumentError]]],
1913
- _get_result_from_continuation_token(
1914
- self._client._client, # pylint: disable=protected-access
1915
- continuation_token,
1916
- AnalyzeActionsLROPoller,
1917
- AnalyzeActionsLROPollingMethod(
1918
- text_analytics_client=self._client,
1919
- timeout=polling_interval_arg,
1920
- **kwargs
1921
- ),
1922
- self._analyze_result_callback,
1923
- bespoke=True
1924
- )
1925
- )
1926
-
1927
- try:
1928
- return cast(
1929
- TextAnalysisLROPoller[
1930
- ItemPaged[Union[ExtractSummaryResult, DocumentError]]
1931
- ],
1932
- self.begin_analyze_actions(
1933
- documents,
1934
- actions=[
1935
- ExtractSummaryAction(
1936
- model_version=model_version,
1937
- string_index_type=string_index_type_arg,
1938
- max_sentence_count=max_sentence_count,
1939
- order_by=order_by,
1940
- disable_service_logs=disable_service_logs,
1941
- )
1942
- ],
1943
- polling_interval=polling_interval_arg,
1944
- display_name=display_name,
1945
- show_stats=show_stats,
1946
- language=language,
1947
- bespoke=True,
1948
- **kwargs
1949
- )
1950
- )
1951
-
1952
- except HttpResponseError as error:
1953
- return process_http_response_error(error)
1954
-
1955
- @distributed_trace
1956
- @validate_multiapi_args(
1957
- version_method_added="2022-10-01-preview"
1958
- )
1959
- def begin_abstractive_summary(
1960
- self,
1961
- documents: Union[List[str], List[TextDocumentInput], List[Dict[str, str]]],
1962
- *,
1963
- continuation_token: Optional[str] = None,
1964
- disable_service_logs: Optional[bool] = None,
1965
- display_name: Optional[str] = None,
1966
- language: Optional[str] = None,
1967
- polling_interval: Optional[int] = None,
1968
- show_stats: Optional[bool] = None,
1969
- model_version: Optional[str] = None,
1970
- string_index_type: Optional[str] = None,
1971
- sentence_count: Optional[int] = None,
1972
- **kwargs: Any,
1973
- ) -> TextAnalysisLROPoller[ItemPaged[Union[AbstractiveSummaryResult, DocumentError]]]:
1974
- """Start a long-running abstractive summarization operation.
1975
-
1976
- For a conceptual discussion of abstractive summarization, see the service documentation:
1977
- https://learn.microsoft.com/azure/cognitive-services/language-service/summarization/overview
1978
-
1979
- .. note:: The abstractive summarization feature is part of a gated preview. Request access here:
1980
- https://aka.ms/applyforgatedsummarizationfeatures
1981
-
1982
- :param documents: The set of documents to process as part of this batch.
1983
- If you wish to specify the ID and language on a per-item basis you must
1984
- use as input a list[:class:`~azure.ai.textanalytics.TextDocumentInput`] or a list of
1985
- dict representations of :class:`~azure.ai.textanalytics.TextDocumentInput`, like
1986
- `{"id": "1", "language": "en", "text": "hello world"}`.
1987
- :type documents:
1988
- list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or list[dict[str, str]]
1989
- :keyword str language: The 2 letter ISO 639-1 representation of language for the
1990
- entire batch. For example, use "en" for English; "es" for Spanish etc.
1991
- For automatic language detection, use "auto" (Only supported by API version
1992
- 2022-10-01-preview and newer). If not set, uses "en" for English as default.
1993
- Per-document language will take precedence over whole batch language.
1994
- See https://aka.ms/talangs for supported languages in Language API.
1995
- :keyword bool show_stats: If set to true, response will contain document level statistics.
1996
- :keyword Optional[int] sentence_count: It controls the approximate number of sentences in the output summaries.
1997
- :keyword Optional[str] model_version: The model version to use for the analysis.
1998
- :keyword Optional[str] string_index_type: Specifies the method used to interpret string offsets.
1999
- :keyword bool disable_service_logs: If set to true, you opt-out of having your text input
2000
- logged on the service side for troubleshooting. By default, the Language service logs your
2001
- input text for 48 hours, solely to allow for troubleshooting issues in providing you with
2002
- the service's natural language processing functions. Setting this parameter to true,
2003
- disables input logging and may limit our ability to remediate issues that occur. Please see
2004
- Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
2005
- additional details, and Microsoft Responsible AI principles at
2006
- https://www.microsoft.com/ai/responsible-ai.
2007
- :keyword int polling_interval: Waiting time between two polls for LRO operations
2008
- if no Retry-After header is present. Defaults to 5 seconds.
2009
- :keyword str continuation_token:
2010
- Call `continuation_token()` on the poller object to save the long-running operation (LRO)
2011
- state into an opaque token. Pass the value as the `continuation_token` keyword argument
2012
- to restart the LRO from a saved state.
2013
- :keyword str display_name: An optional display name to set for the requested analysis.
2014
- :return: An instance of an TextAnalysisLROPoller. Call `result()` on the this
2015
- object to return a heterogeneous pageable of
2016
- :class:`~azure.ai.textanalytics.AbstractiveSummaryResult` and
2017
- :class:`~azure.ai.textanalytics.DocumentError`.
2018
- :rtype:
2019
- ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[
2020
- ~azure.ai.textanalytics.AbstractiveSummaryResult or ~azure.ai.textanalytics.DocumentError]]
2021
- :raises ~azure.core.exceptions.HttpResponseError:
2022
-
2023
- .. versionadded:: 2022-10-01-preview
2024
- The *begin_abstractive_summary* client method.
2025
-
2026
- .. admonition:: Example:
2027
-
2028
- .. literalinclude:: ../samples/sample_abstractive_summary.py
2029
- :start-after: [START abstractive_summary]
2030
- :end-before: [END abstractive_summary]
2031
- :language: python
2032
- :dedent: 4
2033
- :caption: Perform abstractive summarization on a batch of documents.
2034
- """
2035
-
2036
- polling_interval_arg = polling_interval if polling_interval is not None else 5
2037
- string_index_type_arg = string_index_type if string_index_type is not None else self._string_index_type_default
2038
-
2039
- if continuation_token:
2040
- return cast(
2041
- TextAnalysisLROPoller[ItemPaged[Union[AbstractiveSummaryResult, DocumentError]]],
2042
- _get_result_from_continuation_token(
2043
- self._client._client, # pylint: disable=protected-access
2044
- continuation_token,
2045
- AnalyzeActionsLROPoller,
2046
- AnalyzeActionsLROPollingMethod(
2047
- text_analytics_client=self._client,
2048
- timeout=polling_interval_arg,
2049
- **kwargs
2050
- ),
2051
- self._analyze_result_callback,
2052
- bespoke=True
2053
- )
2054
- )
2055
-
2056
- try:
2057
- return cast(
2058
- TextAnalysisLROPoller[
2059
- ItemPaged[Union[AbstractiveSummaryResult, DocumentError]]
2060
- ],
2061
- self.begin_analyze_actions(
2062
- documents,
2063
- actions=[
2064
- AbstractiveSummaryAction(
2065
- model_version=model_version,
2066
- string_index_type=string_index_type_arg,
2067
- sentence_count=sentence_count,
2068
- disable_service_logs=disable_service_logs,
2069
- )
2070
- ],
2071
- polling_interval=polling_interval_arg,
2072
- display_name=display_name,
2073
- show_stats=show_stats,
2074
- language=language,
2075
- bespoke=True,
2076
- **kwargs
2077
- )
2078
- )
2079
-
2080
- except HttpResponseError as error:
2081
- return process_http_response_error(error)