22
22
_validate_input ,
23
23
_determine_action_type ,
24
24
_check_string_index_type_arg ,
25
+ is_language_api
25
26
)
26
27
from ._version import DEFAULT_API_VERSION
27
28
from ._response_handlers import (
@@ -198,13 +199,29 @@ def detect_language(
198
199
model_version = kwargs .pop ("model_version" , None )
199
200
show_stats = kwargs .pop ("show_stats" , None )
200
201
disable_service_logs = kwargs .pop ("disable_service_logs" , None )
201
- if disable_service_logs is not None :
202
- kwargs ["logging_opt_out" ] = disable_service_logs
202
+
203
203
try :
204
+ if is_language_api (self ._api_version ):
205
+ models = self ._client .models (api_version = self ._api_version )
206
+ return self ._client .analyze_text (
207
+ body = models .AnalyzeTextLanguageDetectionInput (
208
+ analysis_input = {"documents" : docs },
209
+ parameters = models .LanguageDetectionTaskParameters (
210
+ logging_opt_out = disable_service_logs ,
211
+ model_version = model_version
212
+ )
213
+ ),
214
+ show_stats = show_stats ,
215
+ cls = kwargs .pop ("cls" , language_result ),
216
+ ** kwargs
217
+ )
218
+
219
+ # api_versions 3.0, 3.1
204
220
return self ._client .languages (
205
221
documents = docs ,
206
222
model_version = model_version ,
207
223
show_stats = show_stats ,
224
+ logging_opt_out = disable_service_logs ,
208
225
cls = kwargs .pop ("cls" , language_result ),
209
226
** kwargs
210
227
)
@@ -283,19 +300,34 @@ def recognize_entities(
283
300
self ._api_version ,
284
301
string_index_type_default = self ._string_index_type_default ,
285
302
)
286
- if string_index_type :
287
- kwargs .update ({"string_index_type" : string_index_type })
288
303
disable_service_logs = kwargs .pop ("disable_service_logs" , None )
289
- if disable_service_logs is not None :
290
- kwargs ["logging_opt_out" ] = disable_service_logs
291
304
292
305
try :
306
+ if is_language_api (self ._api_version ):
307
+ models = self ._client .models (api_version = self ._api_version )
308
+ return self ._client .analyze_text (
309
+ body = models .AnalyzeTextEntityRecognitionInput (
310
+ analysis_input = {"documents" : docs },
311
+ parameters = models .EntitiesTaskParameters (
312
+ logging_opt_out = disable_service_logs ,
313
+ model_version = model_version ,
314
+ string_index_type = string_index_type
315
+ )
316
+ ),
317
+ show_stats = show_stats ,
318
+ cls = kwargs .pop ("cls" , entities_result ),
319
+ ** kwargs
320
+ )
321
+
322
+ # api_versions 3.0, 3.1
293
323
return self ._client .entities_recognition_general (
294
324
documents = docs ,
295
325
model_version = model_version ,
296
326
show_stats = show_stats ,
327
+ string_index_type = string_index_type ,
328
+ logging_opt_out = disable_service_logs ,
297
329
cls = kwargs .pop ("cls" , entities_result ),
298
- ** kwargs
330
+ ** kwargs ,
299
331
)
300
332
except HttpResponseError as error :
301
333
return process_http_response_error (error )
@@ -377,25 +409,41 @@ def recognize_pii_entities(
377
409
show_stats = kwargs .pop ("show_stats" , None )
378
410
domain_filter = kwargs .pop ("domain_filter" , None )
379
411
categories_filter = kwargs .pop ("categories_filter" , None )
380
-
381
412
string_index_type = _check_string_index_type_arg (
382
413
kwargs .pop ("string_index_type" , None ),
383
414
self ._api_version ,
384
415
string_index_type_default = self ._string_index_type_default ,
385
416
)
386
- if string_index_type :
387
- kwargs .update ({"string_index_type" : string_index_type })
388
417
disable_service_logs = kwargs .pop ("disable_service_logs" , None )
389
- if disable_service_logs is not None :
390
- kwargs ["logging_opt_out" ] = disable_service_logs
391
418
392
419
try :
420
+ if is_language_api (self ._api_version ):
421
+ models = self ._client .models (api_version = self ._api_version )
422
+ return self ._client .analyze_text (
423
+ body = models .AnalyzeTextPiiEntitiesRecognitionInput (
424
+ analysis_input = {"documents" : docs },
425
+ parameters = models .PiiTaskParameters (
426
+ logging_opt_out = disable_service_logs ,
427
+ model_version = model_version ,
428
+ domain = domain_filter ,
429
+ pii_categories = categories_filter ,
430
+ string_index_type = string_index_type
431
+ )
432
+ ),
433
+ show_stats = show_stats ,
434
+ cls = kwargs .pop ("cls" , pii_entities_result ),
435
+ ** kwargs
436
+ )
437
+
438
+ # api_versions 3.0, 3.1
393
439
return self ._client .entities_recognition_pii (
394
440
documents = docs ,
395
441
model_version = model_version ,
396
442
show_stats = show_stats ,
397
443
domain = domain_filter ,
398
444
pii_categories = categories_filter ,
445
+ logging_opt_out = disable_service_logs ,
446
+ string_index_type = string_index_type ,
399
447
cls = kwargs .pop ("cls" , pii_entities_result ),
400
448
** kwargs
401
449
)
@@ -480,21 +528,35 @@ def recognize_linked_entities(
480
528
model_version = kwargs .pop ("model_version" , None )
481
529
show_stats = kwargs .pop ("show_stats" , None )
482
530
disable_service_logs = kwargs .pop ("disable_service_logs" , None )
483
- if disable_service_logs is not None :
484
- kwargs ["logging_opt_out" ] = disable_service_logs
485
-
486
531
string_index_type = _check_string_index_type_arg (
487
532
kwargs .pop ("string_index_type" , None ),
488
533
self ._api_version ,
489
534
string_index_type_default = self ._string_index_type_default ,
490
535
)
491
- if string_index_type :
492
- kwargs .update ({"string_index_type" : string_index_type })
493
536
494
537
try :
538
+ if is_language_api (self ._api_version ):
539
+ models = self ._client .models (api_version = self ._api_version )
540
+ return self ._client .analyze_text (
541
+ body = models .AnalyzeTextEntityLinkingInput (
542
+ analysis_input = {"documents" : docs },
543
+ parameters = models .EntityLinkingTaskParameters (
544
+ logging_opt_out = disable_service_logs ,
545
+ model_version = model_version ,
546
+ string_index_type = string_index_type
547
+ )
548
+ ),
549
+ show_stats = show_stats ,
550
+ cls = kwargs .pop ("cls" , linked_entities_result ),
551
+ ** kwargs
552
+ )
553
+
554
+ # api_versions 3.0, 3.1
495
555
return self ._client .entities_linking (
496
556
documents = docs ,
557
+ logging_opt_out = disable_service_logs ,
497
558
model_version = model_version ,
559
+ string_index_type = string_index_type ,
498
560
show_stats = show_stats ,
499
561
cls = kwargs .pop ("cls" , linked_entities_result ),
500
562
** kwargs
@@ -724,14 +786,29 @@ def extract_key_phrases(
724
786
model_version = kwargs .pop ("model_version" , None )
725
787
show_stats = kwargs .pop ("show_stats" , None )
726
788
disable_service_logs = kwargs .pop ("disable_service_logs" , None )
727
- if disable_service_logs is not None :
728
- kwargs ["logging_opt_out" ] = disable_service_logs
729
789
730
790
try :
791
+ if is_language_api (self ._api_version ):
792
+ models = self ._client .models (api_version = self ._api_version )
793
+ return self ._client .analyze_text (
794
+ body = models .AnalyzeTextKeyPhraseExtractionInput (
795
+ analysis_input = {"documents" : docs },
796
+ parameters = models .KeyPhraseTaskParameters (
797
+ logging_opt_out = disable_service_logs ,
798
+ model_version = model_version ,
799
+ )
800
+ ),
801
+ show_stats = show_stats ,
802
+ cls = kwargs .pop ("cls" , key_phrases_result ),
803
+ ** kwargs
804
+ )
805
+
806
+ # api_versions 3.0, 3.1
731
807
return self ._client .key_phrases (
732
808
documents = docs ,
733
809
model_version = model_version ,
734
810
show_stats = show_stats ,
811
+ logging_opt_out = disable_service_logs ,
735
812
cls = kwargs .pop ("cls" , key_phrases_result ),
736
813
** kwargs
737
814
)
@@ -813,17 +890,11 @@ def analyze_sentiment(
813
890
show_stats = kwargs .pop ("show_stats" , None )
814
891
show_opinion_mining = kwargs .pop ("show_opinion_mining" , None )
815
892
disable_service_logs = kwargs .pop ("disable_service_logs" , None )
816
- if disable_service_logs is not None :
817
- kwargs ["logging_opt_out" ] = disable_service_logs
818
-
819
893
string_index_type = _check_string_index_type_arg (
820
894
kwargs .pop ("string_index_type" , None ),
821
895
self ._api_version ,
822
896
string_index_type_default = self ._string_index_type_default ,
823
897
)
824
- if string_index_type :
825
- kwargs .update ({"string_index_type" : string_index_type })
826
-
827
898
if show_opinion_mining is not None :
828
899
if (
829
900
self ._api_version == TextAnalyticsApiVersion .V3_0
@@ -832,12 +903,32 @@ def analyze_sentiment(
832
903
raise ValueError (
833
904
"'show_opinion_mining' is only available for API version v3.1 and up"
834
905
)
835
- kwargs .update ({"opinion_mining" : show_opinion_mining })
836
906
837
907
try :
908
+ if is_language_api (self ._api_version ):
909
+ models = self ._client .models (api_version = self ._api_version )
910
+ return self ._client .analyze_text (
911
+ body = models .AnalyzeTextSentimentAnalysisInput (
912
+ analysis_input = {"documents" : docs },
913
+ parameters = models .SentimentAnalysisTaskParameters (
914
+ logging_opt_out = disable_service_logs ,
915
+ model_version = model_version ,
916
+ string_index_type = string_index_type ,
917
+ opinion_mining = show_opinion_mining ,
918
+ )
919
+ ),
920
+ show_stats = show_stats ,
921
+ cls = kwargs .pop ("cls" , sentiment_result ),
922
+ ** kwargs
923
+ )
924
+
925
+ # api_versions 3.0, 3.1
838
926
return self ._client .sentiment (
839
927
documents = docs ,
928
+ logging_opt_out = disable_service_logs ,
840
929
model_version = model_version ,
930
+ string_index_type = string_index_type ,
931
+ opinion_mining = show_opinion_mining ,
841
932
show_stats = show_stats ,
842
933
cls = kwargs .pop ("cls" , sentiment_result ),
843
934
** kwargs
0 commit comments