1+ # <imports>
12# -*- coding: utf-8 -*-
23
34import os
45from azure .cognitiveservices .language .textanalytics import TextAnalyticsClient
56from msrest .authentication import CognitiveServicesCredentials
7+ # </imports>
68
9+ # <initialVars>
710key_var_name = 'TEXT_ANALYTICS_SUBSCRIPTION_KEY'
811if not key_var_name in os .environ :
912 raise Exception ('Please set/export the environment variable: {}' .format (key_var_name ))
1316if not endpoint_var_name in os .environ :
1417 raise Exception ('Please set/export the environment variable: {}' .format (endpoint_var_name ))
1518endpoint = os .environ [endpoint_var_name ]
19+ # <initialVars>
1620
17- def language_extraction (subscription_key ):
18- """Language extraction.
21+ """Language detection.
1922
2023 This example detects the language of several strings.
2124 """
25+ # <languageDetection>
26+ def language_detection ():
27+
2228 credentials = CognitiveServicesCredentials (subscription_key )
2329 text_analytics = TextAnalyticsClient (
2430 endpoint = endpoint , credentials = credentials )
@@ -37,13 +43,17 @@ def language_extraction(subscription_key):
3743
3844 except Exception as err :
3945 print ("Encountered exception. {}" .format (err ))
46+ language_detection ()
47+ # </languageDetection>
4048
4149
42- def key_phrases (subscription_key ):
43- """Key-phrases.
50+ """Key-phrases.
4451
45- Returns the key talking points in several text examples.
46- """
52+ Returns the key talking points in several text examples.
53+ """
54+ # <keyPhrases>
55+ def key_phrases ():
56+
4757 credentials = CognitiveServicesCredentials (subscription_key )
4858 text_analytics = TextAnalyticsClient (
4959 endpoint = endpoint , credentials = credentials )
@@ -72,13 +82,17 @@ def key_phrases(subscription_key):
7282
7383 except Exception as err :
7484 print ("Encountered exception. {}" .format (err ))
85+ key_phrases ()
86+ # </keyPhrases>
7587
88+ """Sentiment.
7689
77- def sentiment ( subscription_key ):
78- """Sentiment.
90+ Scores close to 1 indicate positive sentiment, while scores close to 0 indicate negative sentiment.
91+ """
7992
80- Scores close to 1 indicate positive sentiment, while scores close to 0 indicate negative sentiment.
81- """
93+ # <sentimentAnalysis>
94+ def sentiment ():
95+
8296 credentials = CognitiveServicesCredentials (subscription_key )
8397 text_analytics = TextAnalyticsClient (
8498 endpoint = endpoint , credentials = credentials )
@@ -100,13 +114,16 @@ def sentiment(subscription_key):
100114
101115 except Exception as err :
102116 print ("Encountered exception. {}" .format (err ))
117+ sentiment ()
118+ # </sentimentAnalysis>
103119
120+ """EntityRecognition.
121+ Extracts the entities from sentences and prints out their properties.
122+ """
104123
105- def entity_extraction (subscription_key ):
106- """EntityExtraction.
107-
108- Extracts the entities from sentences and prints out their properties.
109- """
124+ # <entityRecognition>
125+ def entity_recognition ():
126+
110127 credentials = CognitiveServicesCredentials (subscription_key )
111128 text_analytics = TextAnalyticsClient (
112129 endpoint = endpoint , credentials = credentials )
@@ -131,7 +148,8 @@ def entity_extraction(subscription_key):
131148
132149 except Exception as err :
133150 print ("Encountered exception. {}" .format (err ))
134-
151+ entity_recognition ()
152+ # </entityExtraction>
135153
136154if __name__ == "__main__" :
137155 import sys
0 commit comments