Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This version of the SDK defaults to the latest supported API version, which curr
- Added support for Custom Entities Recognition through the `begin_analyze_actions` API with the `RecognizeCustomEntitiesAction` and `RecognizeCustomEntitiesResult` types.
- Added support for Custom Single Classification through the `begin_analyze_actions` API with the `SingleCategoryClassifyAction` and `SingleCategoryClassifyActionResult` types.
- Added support for Custom Multi Classification through the `begin_analyze_actions` API with the `MultiCategoryClassifyAction` and `MultiCategoryClassifyActionResult` types.
- Multiple of the same action type is now supported with `begin_analyze_actions`.

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ def __repr__(self, **kwargs):
:1024
]

def _to_generated(self, api_version):
def _to_generated(self, api_version, task_id):
if api_version == DEFAULT_API_VERSION:
from ._generated.v3_2_preview_2 import models
else:
Expand All @@ -1808,7 +1808,8 @@ def _to_generated(self, api_version):
model_version=self.model_version,
string_index_type=self.string_index_type,
logging_opt_out=self.disable_service_logs,
)
),
task_name=task_id
)


Expand Down Expand Up @@ -1875,7 +1876,7 @@ def __repr__(self, **kwargs):
)[:1024]
)

def _to_generated(self, api_version):
def _to_generated(self, api_version, task_id):
if api_version == DEFAULT_API_VERSION:
from ._generated.v3_2_preview_2 import models
else:
Expand All @@ -1886,7 +1887,8 @@ def _to_generated(self, api_version):
opinion_mining=self.show_opinion_mining,
string_index_type=self.string_index_type,
logging_opt_out=self.disable_service_logs,
)
),
task_name=task_id
)


Expand Down Expand Up @@ -1957,7 +1959,7 @@ def __repr__(self, **kwargs):
)[:1024]
)

def _to_generated(self, api_version):
def _to_generated(self, api_version, task_id):
if api_version == DEFAULT_API_VERSION:
from ._generated.v3_2_preview_2 import models
else:
Expand All @@ -1969,7 +1971,8 @@ def _to_generated(self, api_version):
pii_categories=self.categories_filter,
string_index_type=self.string_index_type,
logging_opt_out=self.disable_service_logs,
)
),
task_name=task_id
)


Expand Down Expand Up @@ -2012,7 +2015,7 @@ def __repr__(self, **kwargs):
)[:1024]
)

def _to_generated(self, api_version):
def _to_generated(self, api_version, task_id):
if api_version == DEFAULT_API_VERSION:
from ._generated.v3_2_preview_2 import models
else:
Expand All @@ -2021,7 +2024,8 @@ def _to_generated(self, api_version):
parameters=models.KeyPhrasesTaskParameters(
model_version=self.model_version,
logging_opt_out=self.disable_service_logs,
)
),
task_name=task_id
)


Expand Down Expand Up @@ -2074,7 +2078,7 @@ def __repr__(self, **kwargs):
)[:1024]
)

def _to_generated(self, api_version):
def _to_generated(self, api_version, task_id):
if api_version == DEFAULT_API_VERSION:
from ._generated.v3_2_preview_2 import models
else:
Expand All @@ -2084,7 +2088,8 @@ def _to_generated(self, api_version):
model_version=self.model_version,
string_index_type=self.string_index_type,
logging_opt_out=self.disable_service_logs,
)
),
task_name=task_id
)


Expand Down Expand Up @@ -2143,15 +2148,16 @@ def __repr__(self):
)[:1024]
)

def _to_generated(self, api_version): # pylint: disable=unused-argument
def _to_generated(self, api_version, task_id): # pylint: disable=unused-argument
return _v3_2_preview_models.ExtractiveSummarizationTask(
parameters=_v3_2_preview_models.ExtractiveSummarizationTaskParameters(
model_version=self.model_version,
string_index_type=self.string_index_type,
logging_opt_out=self.disable_service_logs,
sentence_count=self.max_sentence_count,
sort_by=self.order_by,
)
),
task_name=task_id
)


Expand Down Expand Up @@ -2304,14 +2310,15 @@ def __repr__(self):
self.string_index_type,
)[:1024]

def _to_generated(self, api_version): # pylint: disable=unused-argument
def _to_generated(self, api_version, task_id): # pylint: disable=unused-argument
return _v3_2_preview_models.CustomEntitiesTask(
parameters=_v3_2_preview_models.CustomEntitiesTaskParameters(
project_name=self.project_name,
deployment_name=self.deployment_name,
string_index_type=self.string_index_type,
logging_opt_out=self.disable_service_logs,
)
),
task_name=task_id
)


Expand Down Expand Up @@ -2417,13 +2424,14 @@ def __repr__(self):
self.disable_service_logs,
)[:1024]

def _to_generated(self, api_version): # pylint: disable=unused-argument
def _to_generated(self, api_version, task_id): # pylint: disable=unused-argument
return _v3_2_preview_models.CustomMultiClassificationTask(
parameters=_v3_2_preview_models.CustomMultiClassificationTaskParameters(
project_name=self.project_name,
deployment_name=self.deployment_name,
logging_opt_out=self.disable_service_logs,
)
),
task_name=task_id
)


Expand Down Expand Up @@ -2529,13 +2537,14 @@ def __repr__(self):
self.disable_service_logs,
)[:1024]

def _to_generated(self, api_version): # pylint: disable=unused-argument
def _to_generated(self, api_version, task_id): # pylint: disable=unused-argument
return _v3_2_preview_models.CustomSingleClassificationTask(
parameters=_v3_2_preview_models.CustomSingleClassificationTaskParameters(
project_name=self.project_name,
deployment_name=self.deployment_name,
logging_opt_out=self.disable_service_logs,
)
),
task_name=task_id
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@


import six

from ._generated.models import (
EntitiesTask,
PiiTask,
EntityLinkingTask,
SentimentAnalysisTask,
ExtractiveSummarizationTask,
CustomEntitiesTask,
CustomSingleClassificationTask,
CustomMultiClassificationTask,
)
from ._models import (
DetectLanguageInput,
TextDocumentInput,
RecognizeEntitiesAction,
RecognizePiiEntitiesAction,
RecognizeLinkedEntitiesAction,
AnalyzeSentimentAction,
ExtractSummaryAction,
RecognizeCustomEntitiesAction,
SingleCategoryClassifyAction,
MultiCategoryClassifyAction,
_AnalyzeActionsType,
)

Expand Down Expand Up @@ -92,21 +93,21 @@ def _validate_input(documents, hint, whole_input_hint):


def _determine_action_type(action): # pylint: disable=too-many-return-statements
if isinstance(action, RecognizeEntitiesAction):
if isinstance(action, EntitiesTask):
Comment thread
mssfang marked this conversation as resolved.
return _AnalyzeActionsType.RECOGNIZE_ENTITIES
if isinstance(action, RecognizePiiEntitiesAction):
if isinstance(action, PiiTask):
return _AnalyzeActionsType.RECOGNIZE_PII_ENTITIES
if isinstance(action, RecognizeLinkedEntitiesAction):
if isinstance(action, EntityLinkingTask):
return _AnalyzeActionsType.RECOGNIZE_LINKED_ENTITIES
if isinstance(action, AnalyzeSentimentAction):
if isinstance(action, SentimentAnalysisTask):
return _AnalyzeActionsType.ANALYZE_SENTIMENT
if isinstance(action, ExtractSummaryAction):
if isinstance(action, ExtractiveSummarizationTask):
return _AnalyzeActionsType.EXTRACT_SUMMARY
if isinstance(action, RecognizeCustomEntitiesAction):
if isinstance(action, CustomEntitiesTask):
return _AnalyzeActionsType.RECOGNIZE_CUSTOM_ENTITIES
if isinstance(action, SingleCategoryClassifyAction):
if isinstance(action, CustomSingleClassificationTask):
return _AnalyzeActionsType.SINGLE_CATEGORY_CLASSIFY
if isinstance(action, MultiCategoryClassifyAction):
if isinstance(action, CustomMultiClassificationTask):
return _AnalyzeActionsType.MULTI_CATEGORY_CLASSIFY
return _AnalyzeActionsType.EXTRACT_KEY_PHRASES

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,44 +340,32 @@ def _get_property_name_from_task_type(task_type): # pylint: disable=too-many-re
return "key_phrase_extraction_tasks"


def _get_good_result(
current_task_type,
index_of_task_result,
doc_id_order,
response_headers,
returned_tasks_object,
):
def _get_good_result(task, doc_id_order, response_headers, returned_tasks_object):
current_task_type, task_name = task
deserialization_callback = _get_deserialization_callback_from_task_type(
current_task_type
)
property_name = _get_property_name_from_task_type(current_task_type)
response_task_to_deserialize = getattr(returned_tasks_object, property_name)[
index_of_task_result
]
response_task_to_deserialize = \
[task for task in getattr(returned_tasks_object, property_name) if task.task_name == task_name][0]
Comment thread
kristapratico marked this conversation as resolved.
Outdated
return deserialization_callback(
doc_id_order, response_task_to_deserialize.results, response_headers, lro=True
)


def get_iter_items(doc_id_order, task_order, response_headers, analyze_job_state):
iter_items = defaultdict(list) # map doc id to action results
task_type_to_index = defaultdict(
int
) # need to keep track of how many of each type of tasks we've seen
returned_tasks_object = analyze_job_state.tasks
for current_task_type in task_order:
index_of_task_result = task_type_to_index[current_task_type]
for task in task_order:
results = _get_good_result(
current_task_type,
index_of_task_result,
task,
doc_id_order,
response_headers,
returned_tasks_object,
)
for result in results:
iter_items[result.id].append(result)

task_type_to_index[current_task_type] += 1
return [iter_items[doc_id] for doc_id in doc_id_order if doc_id in iter_items]


Expand Down
Loading