{"id":705,"date":"2021-11-23T03:14:52","date_gmt":"2021-11-23T03:14:52","guid":{"rendered":"http:\/\/192.168.8.123\/?p=705"},"modified":"2022-02-11T11:14:12","modified_gmt":"2022-02-11T11:14:12","slug":"microsoft-azure-natural-language-processing-analyzing-text","status":"publish","type":"post","link":"https:\/\/exceedthecloud.com\/?p=705","title":{"rendered":"Microsoft Azure Natural Language Processing:  Analyzing Text"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <strong>Text Analytics API<\/strong> is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, suppose a travel agency wants to process hotel reviews that have been submitted to the company&#8217;s web site. By using the Text Analytics API, they can determine the language each review is written in, the sentiment (positive, neutral, or negative) of the reviews, key phrases that might indicate the main topics discussed in the review, and named entities, such as places, landmarks, or people mentioned in the reviews.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Prerequisites for this labs : <a rel=\"noreferrer noopener\" href=\"https:\/\/azure.microsoft.com\/en-us\/free\/\" target=\"_blank\">Azure Account<\/a> \/ <a rel=\"noreferrer noopener\" href=\"http:\/\/192.168.8.123\/index.php\/2021\/11\/20\/setting-up-windows-10-environment-for-ai-apps-with-azure-cognitive-services\/\" target=\"_blank\">Setting up Windows 10 environment for AI Apps with Azure Cognitive Services<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Clone the repository for this course<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have not already cloned <strong>AI-102-AIEngineer<\/strong> code repository to the environment where you&#8217;re working on this lab, follow these steps to do so. Otherwise, open the cloned folder in Visual Studio Code.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Start Visual Studio Code.<\/li><li>Open the palette (SHIFT+CTRL+P) and run a <strong>Git: Clone<\/strong> command to clone the https:\/\/github.com\/MicrosoftLearning\/AI-102-AIEngineer repository to a local folder (it doesn&#8217;t matter which folder).<\/li><li>When the repository has been cloned, open the folder in Visual Studio Code.<\/li><li>Wait while additional files are installed to support the C# code projects in the repo.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: If you are prompted to add required assets to build and debug, select <strong>Not Now<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Provision a Cognitive Services resource<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you don&#8217;t already have one in your subscription, you&#8217;ll need to provision a <strong>Cognitive Services<\/strong> resource.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Open the Azure portal at https:\/\/portal.azure.com, and sign in using the Microsoft account associated with your Azure subscription.<\/li><li>Select the <strong>\uff0bCreate a resource<\/strong> button, search for <em>cognitive services<\/em>, and create a <strong>Cognitive Services<\/strong> resource with the following settings:<ul><li><strong>Subscription<\/strong>: <em>Your Azure subscription<\/em><\/li><li><strong>Resource group<\/strong>: <em>Choose or create a resource group (if you are using a restricted subscription, you may not have permission to create a new resource group &#8211; use the one provided)<\/em><\/li><li><strong>Region<\/strong>: <em>Choose any available region<\/em><\/li><li><strong>Name<\/strong>: <em>Enter a unique name<\/em><\/li><li><strong>Pricing tier<\/strong>: Standard S0<\/li><\/ul><\/li><li>Select the required checkboxes and create the resource.<\/li><li>Wait for deployment to complete, and then view the deployment details.<\/li><li>When the resource has been deployed, go to it and view its <strong>Keys and Endpoint<\/strong> page. You will need the endpoint and one of the keys from this page in the next procedure.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prepare to use the Text Analytics SDK<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this exercise, you&#8217;ll complete a partially implemented client application that uses the Text Analysis SDK to analyze hotel reviews.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: You can choose to use the SDK for either <strong>C#<\/strong> or <strong>Python<\/strong>. In the steps below, perform the actions appropriate for your preferred language.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In Visual Studio Code, in the <strong>Explorer<\/strong> pane, browse to the <strong>05-analyze-text<\/strong> folder and expand the <strong>C-Sharp<\/strong> or <strong>Python<\/strong> folder depending on your language preference.<\/li><li>Right-click the <strong>text-analysis<\/strong> folder and open an integrated terminal. Then install the Text Analytics SDK package by running the appropriate command for your language preference:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet add package Azure.AI.TextAnalytics --version 5.0.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install azure-ai-textanalytics==5.0.0<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\" start=\"3\"><li>View the contents of the <strong>text-analysis<\/strong> folder, and note that it contains a file for configuration settings:<ul><li><strong>C#<\/strong>: appsettings.json<\/li><li><strong>Python<\/strong>: .env<\/li><\/ul><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Open the configuration file and update the configuration values it contains to reflect the <strong>endpoint<\/strong> and an authentication <strong>key<\/strong> for your cognitive services resource. Save your changes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img1-5-1024x136.png\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Note that the <strong>text-analysis<\/strong> folder contains a code file for the client application:<ul><li><strong>C#<\/strong>: Program.cs<\/li><li><strong>Python<\/strong>: text-analysis.py<\/li><\/ul><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Open the code file and at the top, under the existing namespace references, find the comment <strong>Import namespaces<\/strong>. Then, under this comment, add the following language-specific code to import the namespaces you will need to use the Text Analytics SDK:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ import namespaces\nusing Azure;\nusing Azure.AI.TextAnalytics;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># import namespaces\nfrom azure.core.credentials import AzureKeyCredential\nfrom azure.ai.textanalytics import TextAnalyticsClient<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img2-5-1024x269.png\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the <strong>Main<\/strong> function, note that code to load the cognitive services endpoint and key from the configuration file has already been provided. Then find the comment <strong>Create client using endpoint and key<\/strong>, and add the following code to create a client for the Text Analysis API:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Create client using endpoint and key\nAzureKeyCredential credentials = new AzureKeyCredential(cogSvcKey);\nUri endpoint = new Uri(cogSvcEndpoint);\nTextAnalyticsClient CogClient = new TextAnalyticsClient(endpoint, credentials);\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create client using endpoint and key\ncredential = AzureKeyCredential(cog_key)\ncog_client = TextAnalyticsClient(endpoint=cog_endpoint, credential=credential)\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img3-4-1024x417.png\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Save your changes and return to the integrated terminal for the <strong>text-analysis<\/strong> folder, and enter the following command to run the program:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet run<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python text-analysis.py<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\" start=\"2\"><li>Observe the output as the code should run without error, displaying the contents of each review text file in the <strong>reviews<\/strong> folder. The application successfully creates a client for the Text Analytics API but doesn&#8217;t make use of it. We&#8217;ll fix that in the next procedure.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Observe the output as the code should run without error, displaying the contents of each review text file in the <strong>reviews<\/strong> folder. The application successfully creates a client for the Text Analytics API but doesn&#8217;t make use of it. We&#8217;ll fix that in the next procedure.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img4-4.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Detect language<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you have created a client for the Text Analytics API, let&#8217;s use it to detect the language in which each review is written.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the <strong>Main<\/strong> function for your program, find the comment <strong>Get language<\/strong>. Then, under this comment, add the code necessary to detect the language in each review document:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Get language\nDetectedLanguage detectedLanguage = CogClient.DetectLanguage(text);\nConsole.WriteLine($\"\\nLanguage: {detectedLanguage.Name}\");\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Get language\ndetectedLanguage = cog_client.detect_language(documents=&#91;text])&#91;0]\nprint('\\nLanguage: {}'.format(detectedLanguage.primary_language.name))\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img5-4-1024x289.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: <em>In this example, each review is analyzed individually, resulting in a separate call to the service for each file. An alternative approach is to create a collection of documents and pass them to the service in a single call. In both approaches, the response from the service consists of a collection of documents; which is why in the Python code above, the index of the first (and only) document in the response ([0]) is specified.<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Save your changes and return to the integrated terminal for the <strong>text-analysis<\/strong> folder, and enter the following command to run the program:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet run<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python text-analysis.py<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Observe the output, noting that this time the language for each review is identified.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img6-4.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Evaluate sentiment<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Sentiment analysis<\/em> is a commonly used technique to classify text as <em>positive<\/em> or <em>negative<\/em> (or possible <em>neutral<\/em> or <em>mixed<\/em>). It&#8217;s commonly used to analyze social media posts, product reviews, and other items where the sentiment of the text may provide useful insights.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the <strong>Main<\/strong> function for your program, find the comment <strong>Get sentiment<\/strong>. Then, under this comment, add the code necessary to detect the sentiment of each review document:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Get sentiment\nDocumentSentiment sentimentAnalysis = CogClient.AnalyzeSentiment(text);\nConsole.WriteLine($\"\\nSentiment: {sentimentAnalysis.Sentiment}\");\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Get sentiment\nsentimentAnalysis = cog_client.analyze_sentiment(documents=&#91;text])&#91;0]\nprint(\"\\nSentiment: {}\".format(sentimentAnalysis.sentiment))\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img7-4-1024x232.png\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Save your changes and return to the integrated terminal for the <strong>text-analysis<\/strong> folder, and enter the following command to run the program:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet run<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python text-analysis.py<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Observe the output, noting that the sentiment of the reviews is detected.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img8-4.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Identify key phrases<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It can be useful to identify key phrases in a body of text to help determine the main topics that it discusses.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the <strong>Main<\/strong> function for your program, find the comment <strong>Get key phrases<\/strong>. Then, under this comment, add the code necessary to detect the key phrases in each review document:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Get key phrases\nKeyPhraseCollection phrases = CogClient.ExtractKeyPhrases(text);\nif (phrases.Count &gt; 0)\n{\n    Console.WriteLine(\"\\nKey Phrases:\");\n    foreach(string phrase in phrases)\n    {\n        Console.WriteLine($\"\\t{phrase}\");\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Get key phrases\nphrases = cog_client.extract_key_phrases(documents=&#91;text])&#91;0].key_phrases\nif len(phrases) &gt; 0:\n    print(\"\\nKey Phrases:\")\n    for phrase in phrases:\n        print('\\t{}'.format(phrase))\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img9-4-1024x240.png\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Save your changes and return to the integrated terminal for the <strong>text-analysis<\/strong> folder, and enter the following command to run the program:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet run<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python text-analysis.py<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\" start=\"2\"><li>Observe the output, noting that each document contains key phrases that give some insights into what the review is about.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img10-4.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Extract entities<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Often, documents or other bodies of text mention people, places, time periods, or other entities. The text Analytics API can detect multiple categories (and subcategories) of entity in your text.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the <strong>Main<\/strong> function for your program, find the comment <strong>Get entities<\/strong>. Then, under this comment, add the code necessary to identify entities that are mentioned in each review:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Get entities\nCategorizedEntityCollection entities = CogClient.RecognizeEntities(text);\nif (entities.Count &gt; 0)\n{\n    Console.WriteLine(\"\\nEntities:\");\n    foreach(CategorizedEntity entity in entities)\n    {\n        Console.WriteLine($\"\\t{entity.Text} ({entity.Category})\");\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Get entities\nentities = cog_client.recognize_entities(documents=&#91;text])&#91;0].entities\nif len(entities) &gt; 0:\n    print(\"\\nEntities\")\n    for entity in entities:\n        print('\\t{} ({})'.format(entity.text, entity.category))\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img11-3-1024x312.png\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Save your changes and return to the integrated terminal for the <strong>text-analysis<\/strong> folder, and enter the following command to run the program:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet run<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python text-analysis.py<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\" start=\"2\"><li>Observe the output, noting the entities that have been detected in the text.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img12-2.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Extract linked entities<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition to categorized entities, the Text Analytics API can detect entities for which there are known links to data sources, such as Wikipedia.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the <strong>Main<\/strong> function for your program, find the comment <strong>Get linked entities<\/strong>. Then, under this comment, add the code necessary to identify linked entities that are mentioned in each review:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Get linked entities\nLinkedEntityCollection linkedEntities = CogClient.RecognizeLinkedEntities(text);\nif (linkedEntities.Count &gt; 0)\n{\n    Console.WriteLine(\"\\nLinks:\");\n    foreach(LinkedEntity linkedEntity in linkedEntities)\n    {\n        Console.WriteLine($\"\\t{linkedEntity.Name} ({linkedEntity.Url})\");\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Get linked entities\nentities = cog_client.recognize_linked_entities(documents=&#91;text])&#91;0].entities\nif len(entities) &gt; 0:\n    print(\"\\nLinks\")\n    for linked_entity in entities:\n        print('\\t{} ({})'.format(linked_entity.name, linked_entity.url))\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img13-2-1024x317.png\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Save your changes and return to the integrated terminal for the <strong>text-analysis<\/strong> folder, and enter the following command to run the program:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C#<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet run<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python text-analysis.py<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\" start=\"2\"><li>Observe the output, noting the linked entities that are identified.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/02\/img14-3.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><mark class=\"kt-highlight\"><strong>Reminder<\/strong>: Don\u2019t forget to delete or shutdown all unused Azure resources after your labs for cost saving<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>More information<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For more information about using the <strong>Text Analytics<\/strong> service, see the <a href=\"https:\/\/docs.microsoft.com\/azure\/cognitive-services\/text-analytics\/\" target=\"_blank\" rel=\"noreferrer noopener\">Text Analytics documentation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Text Analytics API is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition. For example, suppose a travel agency wants to process hotel reviews that have been submitted to &hellip; <a href=\"https:\/\/exceedthecloud.com\/?p=705\">Continued<\/a><\/p>\n","protected":false},"author":1,"featured_media":862,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"kt_blocks_editor_width":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[14,15,4],"tags":[7,56,8,57,53,55,54],"class_list":["post-705","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence","category-cognitive-services","category-practical-labs-series","tag-ai","tag-api","tag-azure","tag-cognitive-service","tag-git","tag-python","tag-visual-studio-code"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"The Text Analytics API is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition. For example, suppose a travel agency wants to process hotel reviews that have been submitted to the company&#039;s web site. By using the Text Analytics API, they can determine the language\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marcelin NDJILA\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/exceedthecloud.com\/?p=705\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"exceedthecloud.com - Going beyond the cloud, learning new stuffs everyday !\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Microsoft Azure Natural Language Processing: Analyzing Text - exceedthecloud.com\" \/>\n\t\t<meta property=\"og:description\" content=\"The Text Analytics API is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition. For example, suppose a travel agency wants to process hotel reviews that have been submitted to the company&#039;s web site. By using the Text Analytics API, they can determine the language\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/exceedthecloud.com\/?p=705\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2021-11-23T03:14:52+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-02-11T11:14:12+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Microsoft Azure Natural Language Processing: Analyzing Text - exceedthecloud.com\" \/>\n\t\t<meta name=\"twitter:description\" content=\"The Text Analytics API is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition. For example, suppose a travel agency wants to process hotel reviews that have been submitted to the company&#039;s web site. By using the Text Analytics API, they can determine the language\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#blogposting\",\"name\":\"Microsoft Azure Natural Language Processing: Analyzing Text - exceedthecloud.com\",\"headline\":\"Microsoft Azure Natural Language Processing:  Analyzing Text\",\"author\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?author=1#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/exceedthecloud.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/NLP.jpg\",\"width\":643,\"height\":269,\"caption\":\"Hand of Businessman touching hologram screen with world map background. NLP Natural Language Processing cognitive computing technology concept.\"},\"datePublished\":\"2021-11-23T03:14:52+00:00\",\"dateModified\":\"2022-02-11T11:14:12+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#webpage\"},\"articleSection\":\"Artificial Intelligence, Cognitive Services, Practical Labs Series, AI, API, Azure, Cognitive Service, Git, Python, Visual Studio Code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/exceedthecloud.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/exceedthecloud.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?cat=4#listItem\",\"name\":\"Practical Labs Series\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?cat=4#listItem\",\"position\":2,\"name\":\"Practical Labs Series\",\"item\":\"https:\\\/\\\/exceedthecloud.com\\\/?cat=4\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#listItem\",\"name\":\"Microsoft Azure Natural Language Processing:  Analyzing Text\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/exceedthecloud.com#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#listItem\",\"position\":3,\"name\":\"Microsoft Azure Natural Language Processing:  Analyzing Text\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?cat=4#listItem\",\"name\":\"Practical Labs Series\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/#organization\",\"name\":\"exceedthecloud.com\",\"description\":\"Going beyond the cloud, learning new stuffs everyday !\",\"url\":\"https:\\\/\\\/exceedthecloud.com\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?author=1#author\",\"url\":\"https:\\\/\\\/exceedthecloud.com\\\/?author=1\",\"name\":\"Marcelin NDJILA\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/313fe81244bf3b0904f504f4f7306bd513918093551c74d1201a23374c87e9b2?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marcelin NDJILA\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#webpage\",\"url\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705\",\"name\":\"Microsoft Azure Natural Language Processing: Analyzing Text - exceedthecloud.com\",\"description\":\"The Text Analytics API is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition. For example, suppose a travel agency wants to process hotel reviews that have been submitted to the company's web site. By using the Text Analytics API, they can determine the language\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?author=1#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?author=1#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/exceedthecloud.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/NLP.jpg\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705\\\/#mainImage\",\"width\":643,\"height\":269,\"caption\":\"Hand of Businessman touching hologram screen with world map background. NLP Natural Language Processing cognitive computing technology concept.\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/?p=705#mainImage\"},\"datePublished\":\"2021-11-23T03:14:52+00:00\",\"dateModified\":\"2022-02-11T11:14:12+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/#website\",\"url\":\"https:\\\/\\\/exceedthecloud.com\\\/\",\"name\":\"exceedthecloud.com\",\"description\":\"Going beyond the cloud, learning new stuffs everyday !\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/exceedthecloud.com\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Microsoft Azure Natural Language Processing: Analyzing Text - exceedthecloud.com","description":"The Text Analytics API is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition. For example, suppose a travel agency wants to process hotel reviews that have been submitted to the company's web site. By using the Text Analytics API, they can determine the language","canonical_url":"https:\/\/exceedthecloud.com\/?p=705","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/exceedthecloud.com\/?p=705#blogposting","name":"Microsoft Azure Natural Language Processing: Analyzing Text - exceedthecloud.com","headline":"Microsoft Azure Natural Language Processing:  Analyzing Text","author":{"@id":"https:\/\/exceedthecloud.com\/?author=1#author"},"publisher":{"@id":"https:\/\/exceedthecloud.com\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2021\/11\/NLP.jpg","width":643,"height":269,"caption":"Hand of Businessman touching hologram screen with world map background. NLP Natural Language Processing cognitive computing technology concept."},"datePublished":"2021-11-23T03:14:52+00:00","dateModified":"2022-02-11T11:14:12+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/exceedthecloud.com\/?p=705#webpage"},"isPartOf":{"@id":"https:\/\/exceedthecloud.com\/?p=705#webpage"},"articleSection":"Artificial Intelligence, Cognitive Services, Practical Labs Series, AI, API, Azure, Cognitive Service, Git, Python, Visual Studio Code"},{"@type":"BreadcrumbList","@id":"https:\/\/exceedthecloud.com\/?p=705#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/exceedthecloud.com#listItem","position":1,"name":"Home","item":"https:\/\/exceedthecloud.com","nextItem":{"@type":"ListItem","@id":"https:\/\/exceedthecloud.com\/?cat=4#listItem","name":"Practical Labs Series"}},{"@type":"ListItem","@id":"https:\/\/exceedthecloud.com\/?cat=4#listItem","position":2,"name":"Practical Labs Series","item":"https:\/\/exceedthecloud.com\/?cat=4","nextItem":{"@type":"ListItem","@id":"https:\/\/exceedthecloud.com\/?p=705#listItem","name":"Microsoft Azure Natural Language Processing:  Analyzing Text"},"previousItem":{"@type":"ListItem","@id":"https:\/\/exceedthecloud.com#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/exceedthecloud.com\/?p=705#listItem","position":3,"name":"Microsoft Azure Natural Language Processing:  Analyzing Text","previousItem":{"@type":"ListItem","@id":"https:\/\/exceedthecloud.com\/?cat=4#listItem","name":"Practical Labs Series"}}]},{"@type":"Organization","@id":"https:\/\/exceedthecloud.com\/#organization","name":"exceedthecloud.com","description":"Going beyond the cloud, learning new stuffs everyday !","url":"https:\/\/exceedthecloud.com\/"},{"@type":"Person","@id":"https:\/\/exceedthecloud.com\/?author=1#author","url":"https:\/\/exceedthecloud.com\/?author=1","name":"Marcelin NDJILA","image":{"@type":"ImageObject","@id":"https:\/\/exceedthecloud.com\/?p=705#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/313fe81244bf3b0904f504f4f7306bd513918093551c74d1201a23374c87e9b2?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marcelin NDJILA"}},{"@type":"WebPage","@id":"https:\/\/exceedthecloud.com\/?p=705#webpage","url":"https:\/\/exceedthecloud.com\/?p=705","name":"Microsoft Azure Natural Language Processing: Analyzing Text - exceedthecloud.com","description":"The Text Analytics API is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition. For example, suppose a travel agency wants to process hotel reviews that have been submitted to the company's web site. By using the Text Analytics API, they can determine the language","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/exceedthecloud.com\/#website"},"breadcrumb":{"@id":"https:\/\/exceedthecloud.com\/?p=705#breadcrumblist"},"author":{"@id":"https:\/\/exceedthecloud.com\/?author=1#author"},"creator":{"@id":"https:\/\/exceedthecloud.com\/?author=1#author"},"image":{"@type":"ImageObject","url":"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2021\/11\/NLP.jpg","@id":"https:\/\/exceedthecloud.com\/?p=705\/#mainImage","width":643,"height":269,"caption":"Hand of Businessman touching hologram screen with world map background. NLP Natural Language Processing cognitive computing technology concept."},"primaryImageOfPage":{"@id":"https:\/\/exceedthecloud.com\/?p=705#mainImage"},"datePublished":"2021-11-23T03:14:52+00:00","dateModified":"2022-02-11T11:14:12+00:00"},{"@type":"WebSite","@id":"https:\/\/exceedthecloud.com\/#website","url":"https:\/\/exceedthecloud.com\/","name":"exceedthecloud.com","description":"Going beyond the cloud, learning new stuffs everyday !","inLanguage":"en-US","publisher":{"@id":"https:\/\/exceedthecloud.com\/#organization"}}]},"og:locale":"en_US","og:site_name":"exceedthecloud.com - Going beyond the cloud, learning new stuffs everyday !","og:type":"article","og:title":"Microsoft Azure Natural Language Processing: Analyzing Text - exceedthecloud.com","og:description":"The Text Analytics API is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition. For example, suppose a travel agency wants to process hotel reviews that have been submitted to the company's web site. By using the Text Analytics API, they can determine the language","og:url":"https:\/\/exceedthecloud.com\/?p=705","article:published_time":"2021-11-23T03:14:52+00:00","article:modified_time":"2022-02-11T11:14:12+00:00","twitter:card":"summary","twitter:title":"Microsoft Azure Natural Language Processing: Analyzing Text - exceedthecloud.com","twitter:description":"The Text Analytics API is a cognitive service that supports analysis of text, including language detection, sentiment analysis, key phrase extraction, and entity recognition. For example, suppose a travel agency wants to process hotel reviews that have been submitted to the company's web site. By using the Text Analytics API, they can determine the language"},"aioseo_meta_data":{"post_id":"705","title":null,"description":null,"keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"#aioseo-article-646b9bf1e5cdd","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-01-31 18:34:09","updated":"2025-09-02 22:02:52","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/exceedthecloud.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/exceedthecloud.com\/?cat=4\" title=\"Practical Labs Series\">Practical Labs Series<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tMicrosoft Azure Natural Language Processing:  Analyzing Text\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/exceedthecloud.com"},{"label":"Practical Labs Series","link":"https:\/\/exceedthecloud.com\/?cat=4"},{"label":"Microsoft Azure Natural Language Processing:  Analyzing Text","link":"https:\/\/exceedthecloud.com\/?p=705"}],"jetpack_featured_media_url":"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2021\/11\/NLP.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/posts\/705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=705"}],"version-history":[{"count":3,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/posts\/705\/revisions"}],"predecessor-version":[{"id":2332,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/posts\/705\/revisions\/2332"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/media\/862"}],"wp:attachment":[{"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}