@azure/ai-language-text 1.1.0-alpha.20230228.2 → 1.1.0-alpha.20230302.1
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.
- package/dist/index.js +130 -17
- package/dist/index.js.map +1 -1
- package/dist-esm/src/lro.js +2 -2
- package/dist-esm/src/lro.js.map +1 -1
- package/dist-esm/src/transforms.js +114 -16
- package/dist-esm/src/transforms.js.map +1 -1
- package/dist-esm/src/util.js +15 -0
- package/dist-esm/src/util.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -166,6 +166,21 @@ function getOperationOptions(options) {
|
|
166
166
|
rest,
|
167
167
|
};
|
168
168
|
}
|
169
|
+
/**
|
170
|
+
*
|
171
|
+
* @param error - error with the target in the JSON error pointer format "#/items/0
|
172
|
+
* @returns number: the position of the task with error
|
173
|
+
*/
|
174
|
+
function extractErrorPointerIndex(error) {
|
175
|
+
if (!error.target) {
|
176
|
+
throw new Error("Unexpected response from service - no target present");
|
177
|
+
}
|
178
|
+
const position = parseInt(error.target.split("/").pop());
|
179
|
+
if (isNaN(position)) {
|
180
|
+
throw new Error(`Unexpected response from service - action pointer "${error.target}" is not a valid action pointer.`);
|
181
|
+
}
|
182
|
+
return position;
|
183
|
+
}
|
169
184
|
|
170
185
|
/*
|
171
186
|
* Copyright (c) Microsoft Corporation.
|
@@ -4076,74 +4091,172 @@ function toHealthcareResult(docIds, results) {
|
|
4076
4091
|
/**
|
4077
4092
|
* @internal
|
4078
4093
|
*/
|
4079
|
-
function transformAnalyzeBatchResults(docIds, response = []) {
|
4080
|
-
|
4081
|
-
|
4082
|
-
|
4094
|
+
function transformAnalyzeBatchResults(docIds, response = [], errors = []) {
|
4095
|
+
const errorMap = toIndexErrorMap(errors);
|
4096
|
+
return response.map((actionData, idx) => {
|
4097
|
+
const { lastUpdateDateTime: completedOn, actionName, kind: resultKind } = actionData;
|
4098
|
+
const error = errorMap.get(idx);
|
4099
|
+
switch (resultKind) {
|
4083
4100
|
case "SentimentAnalysisLROResults": {
|
4101
|
+
const kind = "SentimentAnalysis";
|
4102
|
+
if (actionData.status === "failed") {
|
4103
|
+
return returnErrorTask(kind, error, completedOn);
|
4104
|
+
}
|
4084
4105
|
const { results } = actionData;
|
4085
4106
|
const { modelVersion, statistics } = results;
|
4086
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4107
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toSentimentAnalysisResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4087
4108
|
}
|
4088
4109
|
case "EntityRecognitionLROResults": {
|
4110
|
+
const kind = "EntityRecognition";
|
4111
|
+
if (actionData.status === "failed") {
|
4112
|
+
return returnErrorTask(kind, error, completedOn);
|
4113
|
+
}
|
4089
4114
|
const { results } = actionData;
|
4090
4115
|
const { modelVersion, statistics } = results;
|
4091
4116
|
return Object.assign(Object.assign(Object.assign({ kind: "EntityRecognition", results: toEntityRecognitionResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4092
4117
|
}
|
4093
4118
|
case "PiiEntityRecognitionLROResults": {
|
4119
|
+
const kind = "PiiEntityRecognition";
|
4120
|
+
if (actionData.status === "failed") {
|
4121
|
+
return returnErrorTask(kind, error, completedOn);
|
4122
|
+
}
|
4094
4123
|
const { results } = actionData;
|
4095
4124
|
const { modelVersion, statistics } = results;
|
4096
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4125
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toPiiEntityRecognitionResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4097
4126
|
}
|
4098
4127
|
case "KeyPhraseExtractionLROResults": {
|
4128
|
+
const kind = "KeyPhraseExtraction";
|
4129
|
+
if (actionData.status === "failed") {
|
4130
|
+
return returnErrorTask(kind, error, completedOn);
|
4131
|
+
}
|
4099
4132
|
const { results } = actionData;
|
4100
4133
|
const { modelVersion, statistics } = results;
|
4101
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4134
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toKeyPhraseExtractionResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4102
4135
|
}
|
4103
4136
|
case "EntityLinkingLROResults": {
|
4137
|
+
const kind = "EntityLinking";
|
4138
|
+
if (actionData.status === "failed") {
|
4139
|
+
return returnErrorTask(kind, error, completedOn);
|
4140
|
+
}
|
4104
4141
|
const { results } = actionData;
|
4105
4142
|
const { modelVersion, statistics } = results;
|
4106
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4143
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toEntityLinkingResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4107
4144
|
}
|
4108
4145
|
case "HealthcareLROResults": {
|
4146
|
+
const kind = "Healthcare";
|
4147
|
+
if (actionData.status === "failed") {
|
4148
|
+
return returnErrorTask(kind, error, completedOn);
|
4149
|
+
}
|
4109
4150
|
const { results } = actionData;
|
4110
4151
|
const { modelVersion, statistics } = results;
|
4111
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4152
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: toHealthcareResult(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4112
4153
|
}
|
4113
4154
|
case "CustomEntityRecognitionLROResults": {
|
4155
|
+
const kind = "CustomEntityRecognition";
|
4156
|
+
if (actionData.status === "failed") {
|
4157
|
+
return returnErrorCustomTask(kind, error, completedOn);
|
4158
|
+
}
|
4114
4159
|
const { results } = actionData;
|
4115
4160
|
const { deploymentName, projectName, statistics } = results;
|
4116
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4161
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { deploymentName,
|
4117
4162
|
projectName });
|
4118
4163
|
}
|
4119
4164
|
case "CustomSingleLabelClassificationLROResults": {
|
4165
|
+
const kind = "CustomSingleLabelClassification";
|
4166
|
+
if (actionData.status === "failed") {
|
4167
|
+
return returnErrorCustomTask(kind, error, completedOn);
|
4168
|
+
}
|
4120
4169
|
const { results } = actionData;
|
4121
4170
|
const { deploymentName, projectName, statistics } = results;
|
4122
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4171
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { deploymentName,
|
4123
4172
|
projectName });
|
4124
4173
|
}
|
4125
4174
|
case "CustomMultiLabelClassificationLROResults": {
|
4175
|
+
const kind = "CustomMultiLabelClassification";
|
4176
|
+
if (actionData.status === "failed") {
|
4177
|
+
return returnErrorCustomTask(kind, error, completedOn);
|
4178
|
+
}
|
4126
4179
|
const { results } = actionData;
|
4127
4180
|
const { deploymentName, projectName, statistics } = results;
|
4128
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4181
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { deploymentName,
|
4129
4182
|
projectName });
|
4130
4183
|
}
|
4131
4184
|
case "ExtractiveSummarizationLROResults": {
|
4185
|
+
const kind = "ExtractiveSummarization";
|
4186
|
+
if (actionData.status === "failed") {
|
4187
|
+
return returnErrorTask(kind, error, completedOn);
|
4188
|
+
}
|
4132
4189
|
const { results } = actionData;
|
4133
4190
|
const { modelVersion, statistics } = results;
|
4134
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4191
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4135
4192
|
}
|
4136
4193
|
case "AbstractiveSummarizationLROResults": {
|
4194
|
+
const kind = "AbstractiveSummarization";
|
4195
|
+
if (actionData.status === "failed") {
|
4196
|
+
return returnErrorTask(kind, error, completedOn);
|
4197
|
+
}
|
4137
4198
|
const { results } = actionData;
|
4138
4199
|
const { modelVersion, statistics } = results;
|
4139
|
-
return Object.assign(Object.assign(Object.assign({ kind
|
4200
|
+
return Object.assign(Object.assign(Object.assign({ kind, results: transformDocumentResults(docIds, results), completedOn }, (actionName ? { actionName } : {})), (statistics ? { statistics } : {})), { modelVersion });
|
4140
4201
|
}
|
4141
4202
|
default: {
|
4142
|
-
throw new Error(`Unsupported results kind: ${
|
4203
|
+
throw new Error(`Unsupported results kind: ${resultKind}`);
|
4143
4204
|
}
|
4144
4205
|
}
|
4145
4206
|
});
|
4146
4207
|
}
|
4208
|
+
/**
|
4209
|
+
* @internal
|
4210
|
+
* Transform a list of error into index and error Map
|
4211
|
+
*/
|
4212
|
+
function toIndexErrorMap(errors) {
|
4213
|
+
const errorMap = new Map();
|
4214
|
+
for (const error of errors) {
|
4215
|
+
const position = extractErrorPointerIndex(error);
|
4216
|
+
const errorWithoutTarget = tslib.__rest(error, ["target"]);
|
4217
|
+
errorMap.set(position, toTextAnalysisError(errorWithoutTarget));
|
4218
|
+
}
|
4219
|
+
return errorMap;
|
4220
|
+
}
|
4221
|
+
/**
|
4222
|
+
* Return the error for non-custom task
|
4223
|
+
*
|
4224
|
+
* @param kind - non custom task kind
|
4225
|
+
* @param error - error returned from the service
|
4226
|
+
* @param failedOn - the LastUpdateDateTime from the service
|
4227
|
+
* @returns - AnalyzeBatchResult with error
|
4228
|
+
*/
|
4229
|
+
function returnErrorTask(kind, error, failedOn) {
|
4230
|
+
if (!error) {
|
4231
|
+
throw new Error("Unexpected response from service - no errors for missing action results.");
|
4232
|
+
}
|
4233
|
+
return {
|
4234
|
+
kind,
|
4235
|
+
modelVersion: "",
|
4236
|
+
failedOn,
|
4237
|
+
error,
|
4238
|
+
};
|
4239
|
+
}
|
4240
|
+
/**
|
4241
|
+
* Return the error for non-custom task
|
4242
|
+
*
|
4243
|
+
* @param kind - non custom task kind
|
4244
|
+
* @param error - error returned from the service
|
4245
|
+
* @param failedOn - the LastUpdateDateTime from the service
|
4246
|
+
* @returns AnalyzeBatchResult for custom task with error
|
4247
|
+
*/
|
4248
|
+
function returnErrorCustomTask(kind, error, failedOn) {
|
4249
|
+
if (!error) {
|
4250
|
+
throw new Error("Unexpected response from service - no errors for missing action results.");
|
4251
|
+
}
|
4252
|
+
return {
|
4253
|
+
kind,
|
4254
|
+
projectName: "",
|
4255
|
+
deploymentName: "",
|
4256
|
+
failedOn,
|
4257
|
+
error,
|
4258
|
+
};
|
4259
|
+
}
|
4147
4260
|
|
4148
4261
|
// Copyright (c) Microsoft Corporation.
|
4149
4262
|
const serializer$2 = coreClient.createSerializer(Mappers, /* isXml */ false);
|
@@ -4204,7 +4317,7 @@ function createSendPollRequest(settings) {
|
|
4204
4317
|
opOptions: addOnResponse(options, (_, response) => {
|
4205
4318
|
const castResponse = response;
|
4206
4319
|
if (castResponse.status.toLowerCase() === "partiallysucceeded") {
|
4207
|
-
castResponse.status = "
|
4320
|
+
castResponse.status = "succeeded";
|
4208
4321
|
}
|
4209
4322
|
}),
|
4210
4323
|
path,
|
@@ -4289,7 +4402,7 @@ function processAnalyzeResult(options) {
|
|
4289
4402
|
});
|
4290
4403
|
const flatResponse = response.flatResponse;
|
4291
4404
|
return {
|
4292
|
-
page: transformAnalyzeBatchResults(docIds, flatResponse.tasks.items),
|
4405
|
+
page: transformAnalyzeBatchResults(docIds, flatResponse.tasks.items, flatResponse.errors),
|
4293
4406
|
nextPageLink: flatResponse.nextLink,
|
4294
4407
|
};
|
4295
4408
|
},
|