/
analyzeSentimentResultArray.ts
67 lines (64 loc) · 1.87 KB
/
analyzeSentimentResultArray.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
TextDocumentBatchStatistics,
DocumentError,
DocumentSentiment,
TextDocumentInput
} from "./generated/models";
import {
AnalyzeSentimentResult,
makeAnalyzeSentimentResult,
makeAnalyzeSentimentErrorResult
} from "./analyzeSentimentResult";
import { sortResponseIdObjects } from "./util";
/**
* Array of `AnalyzeSentimentResult` objects corresponding to a batch of input documents, and
* annotated with information about the batch operation.
*/
export interface AnalyzeSentimentResultArray extends Array<AnalyzeSentimentResult> {
/**
* Statistics about the input document batch and how it was processed
* by the service. This property will have a value when includeStatistics is set to true
* in the client call.
*/
statistics?: TextDocumentBatchStatistics;
/**
* The version of the text analytics model used by this operation on this
* batch of input documents.
*/
modelVersion: string;
}
export function makeAnalyzeSentimentResultArray(
input: TextDocumentInput[],
documents: DocumentSentiment[],
errors: DocumentError[],
modelVersion: string,
statistics?: TextDocumentBatchStatistics
): AnalyzeSentimentResultArray {
const unsortedResult = documents
.map(
(document): AnalyzeSentimentResult => {
return makeAnalyzeSentimentResult(
document.id,
document.sentiment,
document.confidenceScores,
document.sentenceSentiments,
document.warnings,
document.statistics
);
}
)
.concat(
errors.map(
(error): AnalyzeSentimentResult => {
return makeAnalyzeSentimentErrorResult(error.id, error.error);
}
)
);
const result = sortResponseIdObjects(input, unsortedResult);
return Object.assign(result, {
statistics,
modelVersion
});
}