/
textAnalyticsResult.ts
130 lines (116 loc) · 3.09 KB
/
textAnalyticsResult.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
TextDocumentStatistics,
TextAnalyticsError as GeneratedTextAnalyticsErrorModel,
InnerError,
ErrorCodeValue,
InnerErrorCodeValue,
TextAnalyticsWarning
} from "./generated/models";
/**
* The result of a text analytics operation on a single input document.
*/
export type TextAnalyticsResult = TextAnalyticsSuccessResult | TextAnalyticsErrorResult;
/**
* An Error Code returned from the Text Analytics service. Possible
* values include:
*
* For more information about the error, see the `message` property of the associated error.
*/
export type ErrorCode = ErrorCodeValue | InnerErrorCodeValue;
/**
* Type describing an error from the Text Analytics service
*/
export interface TextAnalyticsError {
/**
* A code describing the kind of error produced
*/
readonly code: ErrorCode;
/**
* A message from the service explaining the error
*/
readonly message: string;
/**
* The target of the particular error (for example, the name of an invalid parameter)
*/
readonly target?: string;
}
/**
* Base type for results of text analytics operations corresponding to a single
* input document.
*/
export interface TextAnalyticsSuccessResult {
/**
* Unique, non-empty document identifier.
*/
readonly id: string;
/**
* Statistics about the input document and how it was processed
* by the service. This property will have a value when includeStatistics is set to true
* in the client call.
*/
readonly statistics?: TextDocumentStatistics;
/**
* An array of warning data corresponding to this document.
*
* If no warnings were returned, this array will be empty.
*/
readonly warnings: TextAnalyticsWarning[];
/**
* Discriminant to determine if that this is an error result.
*/
readonly error?: undefined;
}
/**
* Base type for error results of text analytics operations corresponding to a
* single document.
*/
export interface TextAnalyticsErrorResult {
/**
* Unique, non-empty document identifier.
*/
readonly id: string;
/**
* The Error for this document result.
*/
readonly error: TextAnalyticsError;
}
/**
* Helper function for converting nested service error into
* the unified TextAnalyticsError
*/
function intoTextAnalyticsError(
errorModel: GeneratedTextAnalyticsErrorModel | InnerError
): TextAnalyticsError {
// Return the deepest error. This will always be at most
// one level for TextAnalytics
if (errorModel.innererror !== undefined) {
return intoTextAnalyticsError(errorModel.innererror);
}
return {
code: errorModel.code,
message: errorModel.message,
target: errorModel.target
};
}
export function makeTextAnalyticsSuccessResult(
id: string,
warnings: TextAnalyticsWarning[],
statistics?: TextDocumentStatistics
): TextAnalyticsSuccessResult {
return {
id,
statistics,
warnings
};
}
export function makeTextAnalyticsErrorResult(
id: string,
error: GeneratedTextAnalyticsErrorModel
): TextAnalyticsErrorResult {
return {
id,
error: intoTextAnalyticsError(error)
};
}