1
2
3
4
5
6
7
8 package textanalytics
9
10
11
12
13
14
15
16 import (
17 "context"
18 "github.com/Azure/go-autorest/autorest"
19 "github.com/Azure/go-autorest/autorest/azure"
20 "github.com/Azure/go-autorest/tracing"
21 "net/http"
22 )
23
24
25 type BaseClient struct {
26 autorest.Client
27 Endpoint string
28 }
29
30
31 func New(endpoint string) BaseClient {
32 return NewWithoutDefaults(endpoint)
33 }
34
35
36 func NewWithoutDefaults(endpoint string) BaseClient {
37 return BaseClient{
38 Client: autorest.NewClientWithUserAgent(UserAgent()),
39 Endpoint: endpoint,
40 }
41 }
42
43
44
45
46
47
48 func (client BaseClient) DetectLanguage(ctx context.Context, showStats *bool, languageBatchInput *LanguageBatchInput) (result LanguageBatchResult, err error) {
49 if tracing.IsEnabled() {
50 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectLanguage")
51 defer func() {
52 sc := -1
53 if result.Response.Response != nil {
54 sc = result.Response.Response.StatusCode
55 }
56 tracing.EndSpan(ctx, sc, err)
57 }()
58 }
59 req, err := client.DetectLanguagePreparer(ctx, showStats, languageBatchInput)
60 if err != nil {
61 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "DetectLanguage", nil, "Failure preparing request")
62 return
63 }
64
65 resp, err := client.DetectLanguageSender(req)
66 if err != nil {
67 result.Response = autorest.Response{Response: resp}
68 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "DetectLanguage", resp, "Failure sending request")
69 return
70 }
71
72 result, err = client.DetectLanguageResponder(resp)
73 if err != nil {
74 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "DetectLanguage", resp, "Failure responding to request")
75 return
76 }
77
78 return
79 }
80
81
82 func (client BaseClient) DetectLanguagePreparer(ctx context.Context, showStats *bool, languageBatchInput *LanguageBatchInput) (*http.Request, error) {
83 urlParameters := map[string]interface{}{
84 "Endpoint": client.Endpoint,
85 }
86
87 queryParameters := map[string]interface{}{}
88 if showStats != nil {
89 queryParameters["showStats"] = autorest.Encode("query", *showStats)
90 }
91
92 preparer := autorest.CreatePreparer(
93 autorest.AsContentType("application/json; charset=utf-8"),
94 autorest.AsPost(),
95 autorest.WithCustomBaseURL("{Endpoint}/text/analytics/v2.1", urlParameters),
96 autorest.WithPath("/languages"),
97 autorest.WithQueryParameters(queryParameters))
98 if languageBatchInput != nil {
99 preparer = autorest.DecoratePreparer(preparer,
100 autorest.WithJSON(languageBatchInput))
101 }
102 return preparer.Prepare((&http.Request{}).WithContext(ctx))
103 }
104
105
106
107 func (client BaseClient) DetectLanguageSender(req *http.Request) (*http.Response, error) {
108 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
109 }
110
111
112
113 func (client BaseClient) DetectLanguageResponder(resp *http.Response) (result LanguageBatchResult, err error) {
114 err = autorest.Respond(
115 resp,
116 azure.WithErrorUnlessStatusCode(http.StatusOK),
117 autorest.ByUnmarshallingJSON(&result),
118 autorest.ByClosing())
119 result.Response = autorest.Response{Response: resp}
120 return
121 }
122
123
124
125
126
127
128
129
130 func (client BaseClient) Entities(ctx context.Context, showStats *bool, multiLanguageBatchInput *MultiLanguageBatchInput) (result EntitiesBatchResult, err error) {
131 if tracing.IsEnabled() {
132 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.Entities")
133 defer func() {
134 sc := -1
135 if result.Response.Response != nil {
136 sc = result.Response.Response.StatusCode
137 }
138 tracing.EndSpan(ctx, sc, err)
139 }()
140 }
141 req, err := client.EntitiesPreparer(ctx, showStats, multiLanguageBatchInput)
142 if err != nil {
143 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "Entities", nil, "Failure preparing request")
144 return
145 }
146
147 resp, err := client.EntitiesSender(req)
148 if err != nil {
149 result.Response = autorest.Response{Response: resp}
150 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "Entities", resp, "Failure sending request")
151 return
152 }
153
154 result, err = client.EntitiesResponder(resp)
155 if err != nil {
156 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "Entities", resp, "Failure responding to request")
157 return
158 }
159
160 return
161 }
162
163
164 func (client BaseClient) EntitiesPreparer(ctx context.Context, showStats *bool, multiLanguageBatchInput *MultiLanguageBatchInput) (*http.Request, error) {
165 urlParameters := map[string]interface{}{
166 "Endpoint": client.Endpoint,
167 }
168
169 queryParameters := map[string]interface{}{}
170 if showStats != nil {
171 queryParameters["showStats"] = autorest.Encode("query", *showStats)
172 }
173
174 preparer := autorest.CreatePreparer(
175 autorest.AsContentType("application/json; charset=utf-8"),
176 autorest.AsPost(),
177 autorest.WithCustomBaseURL("{Endpoint}/text/analytics/v2.1", urlParameters),
178 autorest.WithPath("/entities"),
179 autorest.WithQueryParameters(queryParameters))
180 if multiLanguageBatchInput != nil {
181 preparer = autorest.DecoratePreparer(preparer,
182 autorest.WithJSON(multiLanguageBatchInput))
183 }
184 return preparer.Prepare((&http.Request{}).WithContext(ctx))
185 }
186
187
188
189 func (client BaseClient) EntitiesSender(req *http.Request) (*http.Response, error) {
190 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
191 }
192
193
194
195 func (client BaseClient) EntitiesResponder(resp *http.Response) (result EntitiesBatchResult, err error) {
196 err = autorest.Respond(
197 resp,
198 azure.WithErrorUnlessStatusCode(http.StatusOK),
199 autorest.ByUnmarshallingJSON(&result),
200 autorest.ByClosing())
201 result.Response = autorest.Response{Response: resp}
202 return
203 }
204
205
206
207
208
209
210
211
212 func (client BaseClient) KeyPhrases(ctx context.Context, showStats *bool, multiLanguageBatchInput *MultiLanguageBatchInput) (result KeyPhraseBatchResult, err error) {
213 if tracing.IsEnabled() {
214 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.KeyPhrases")
215 defer func() {
216 sc := -1
217 if result.Response.Response != nil {
218 sc = result.Response.Response.StatusCode
219 }
220 tracing.EndSpan(ctx, sc, err)
221 }()
222 }
223 req, err := client.KeyPhrasesPreparer(ctx, showStats, multiLanguageBatchInput)
224 if err != nil {
225 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "KeyPhrases", nil, "Failure preparing request")
226 return
227 }
228
229 resp, err := client.KeyPhrasesSender(req)
230 if err != nil {
231 result.Response = autorest.Response{Response: resp}
232 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "KeyPhrases", resp, "Failure sending request")
233 return
234 }
235
236 result, err = client.KeyPhrasesResponder(resp)
237 if err != nil {
238 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "KeyPhrases", resp, "Failure responding to request")
239 return
240 }
241
242 return
243 }
244
245
246 func (client BaseClient) KeyPhrasesPreparer(ctx context.Context, showStats *bool, multiLanguageBatchInput *MultiLanguageBatchInput) (*http.Request, error) {
247 urlParameters := map[string]interface{}{
248 "Endpoint": client.Endpoint,
249 }
250
251 queryParameters := map[string]interface{}{}
252 if showStats != nil {
253 queryParameters["showStats"] = autorest.Encode("query", *showStats)
254 }
255
256 preparer := autorest.CreatePreparer(
257 autorest.AsContentType("application/json; charset=utf-8"),
258 autorest.AsPost(),
259 autorest.WithCustomBaseURL("{Endpoint}/text/analytics/v2.1", urlParameters),
260 autorest.WithPath("/keyPhrases"),
261 autorest.WithQueryParameters(queryParameters))
262 if multiLanguageBatchInput != nil {
263 preparer = autorest.DecoratePreparer(preparer,
264 autorest.WithJSON(multiLanguageBatchInput))
265 }
266 return preparer.Prepare((&http.Request{}).WithContext(ctx))
267 }
268
269
270
271 func (client BaseClient) KeyPhrasesSender(req *http.Request) (*http.Response, error) {
272 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
273 }
274
275
276
277 func (client BaseClient) KeyPhrasesResponder(resp *http.Response) (result KeyPhraseBatchResult, err error) {
278 err = autorest.Respond(
279 resp,
280 azure.WithErrorUnlessStatusCode(http.StatusOK),
281 autorest.ByUnmarshallingJSON(&result),
282 autorest.ByClosing())
283 result.Response = autorest.Response{Response: resp}
284 return
285 }
286
287
288
289
290
291
292
293
294 func (client BaseClient) Sentiment(ctx context.Context, showStats *bool, multiLanguageBatchInput *MultiLanguageBatchInput) (result SentimentBatchResult, err error) {
295 if tracing.IsEnabled() {
296 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.Sentiment")
297 defer func() {
298 sc := -1
299 if result.Response.Response != nil {
300 sc = result.Response.Response.StatusCode
301 }
302 tracing.EndSpan(ctx, sc, err)
303 }()
304 }
305 req, err := client.SentimentPreparer(ctx, showStats, multiLanguageBatchInput)
306 if err != nil {
307 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "Sentiment", nil, "Failure preparing request")
308 return
309 }
310
311 resp, err := client.SentimentSender(req)
312 if err != nil {
313 result.Response = autorest.Response{Response: resp}
314 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "Sentiment", resp, "Failure sending request")
315 return
316 }
317
318 result, err = client.SentimentResponder(resp)
319 if err != nil {
320 err = autorest.NewErrorWithError(err, "textanalytics.BaseClient", "Sentiment", resp, "Failure responding to request")
321 return
322 }
323
324 return
325 }
326
327
328 func (client BaseClient) SentimentPreparer(ctx context.Context, showStats *bool, multiLanguageBatchInput *MultiLanguageBatchInput) (*http.Request, error) {
329 urlParameters := map[string]interface{}{
330 "Endpoint": client.Endpoint,
331 }
332
333 queryParameters := map[string]interface{}{}
334 if showStats != nil {
335 queryParameters["showStats"] = autorest.Encode("query", *showStats)
336 }
337
338 preparer := autorest.CreatePreparer(
339 autorest.AsContentType("application/json; charset=utf-8"),
340 autorest.AsPost(),
341 autorest.WithCustomBaseURL("{Endpoint}/text/analytics/v2.1", urlParameters),
342 autorest.WithPath("/sentiment"),
343 autorest.WithQueryParameters(queryParameters))
344 if multiLanguageBatchInput != nil {
345 preparer = autorest.DecoratePreparer(preparer,
346 autorest.WithJSON(multiLanguageBatchInput))
347 }
348 return preparer.Prepare((&http.Request{}).WithContext(ctx))
349 }
350
351
352
353 func (client BaseClient) SentimentSender(req *http.Request) (*http.Response, error) {
354 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
355 }
356
357
358
359 func (client BaseClient) SentimentResponder(resp *http.Response) (result SentimentBatchResult, err error) {
360 err = autorest.Respond(
361 resp,
362 azure.WithErrorUnlessStatusCode(http.StatusOK),
363 autorest.ByUnmarshallingJSON(&result),
364 autorest.ByClosing())
365 result.Response = autorest.Response{Response: resp}
366 return
367 }
368
View as plain text