/
analyzeSentimentResult.ts
70 lines (64 loc) · 2 KB
/
analyzeSentimentResult.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
makeTextAnalyticsSuccessResult,
TextAnalyticsSuccessResult,
TextAnalyticsErrorResult,
makeTextAnalyticsErrorResult
} from "./textAnalyticsResult";
import {
TextDocumentStatistics,
TextAnalyticsError,
DocumentSentimentLabel,
SentenceSentiment,
SentimentConfidenceScores,
TextAnalyticsWarning
} from "./generated/models";
/**
* The result of the analyze sentiment operation on a single document.
*/
export type AnalyzeSentimentResult = AnalyzeSentimentSuccessResult | AnalyzeSentimentErrorResult;
/**
* The result of the analyze sentiment operation on a single document,
* containing the predicted sentiment for each sentence as well as for the full document.
*/
export interface AnalyzeSentimentSuccessResult extends TextAnalyticsSuccessResult {
/**
* Predicted sentiment for document. Possible values
* include: 'positive', 'neutral', 'negative', 'mixed'
*/
sentiment: DocumentSentimentLabel;
/**
* Document level sentiment confidence scores between 0 and 1 for each sentiment class.
*/
confidenceScores: SentimentConfidenceScores;
/**
* The predicted sentiment for each sentence in the corresponding document.
*/
sentences: SentenceSentiment[];
}
/**
* An error result from the analyze sentiment operation on a single document.
*/
export type AnalyzeSentimentErrorResult = TextAnalyticsErrorResult;
export function makeAnalyzeSentimentResult(
id: string,
sentiment: DocumentSentimentLabel,
confidenceScores: SentimentConfidenceScores,
sentences: SentenceSentiment[],
warnings: TextAnalyticsWarning[],
statistics?: TextDocumentStatistics
): AnalyzeSentimentSuccessResult {
return {
...makeTextAnalyticsSuccessResult(id, warnings, statistics),
sentiment,
confidenceScores,
sentences
};
}
export function makeAnalyzeSentimentErrorResult(
id: string,
error: TextAnalyticsError
): AnalyzeSentimentErrorResult {
return makeTextAnalyticsErrorResult(id, error);
}