{"id":5125,"date":"2017-03-09T12:03:53","date_gmt":"2017-03-09T17:03:53","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?p=5125"},"modified":"2017-03-09T12:03:53","modified_gmt":"2017-03-09T17:03:53","slug":"building-a-solution-on-azure-government-part-i-cognitive-services","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azuregov\/building-a-solution-on-azure-government-part-i-cognitive-services\/","title":{"rendered":"Building a solution on Azure Government Part I: Cognitive Services"},"content":{"rendered":"<p>The Microsoft Azure Government platform is rapidly innovating with new services being introduced all the time. We have recently announced HDInsight and Power BI as GA on Azure Government. These data-centric services unlock a world of possibilities for your organization to process massive amount of data.<\/p>\n<p>In this developer-centric walk-through, I will show you how you can leverage Azure Government to implement a Government-focused scenario. In this scenario, we will translate a Chinese document to English and then perform data analytics and visualizations on that translation. This walk-through will consist of 3 major parts:<\/p>\n<ol>\n<li>Cognitive Services to translate a Chinese document to English.<\/li>\n<li>HDInsight to perform data analytics on that translation and produce basic word counts.<\/li>\n<li>Power BI to visualize the data produced by HDInsight.<\/li>\n<\/ol>\n<p>If you prefer, you can follow along with a <a href=\"https:\/\/channel9.msdn.com\/Blogs\/Azure\/Cognitive-Services-HDInsight-and-Power-BI-on-Azure-Government\">video walk-through<\/a> of this blog post.<\/p>\n<h2>Cognitive Services<\/h2>\n<p>First, we will use Cognitive Services for document translation. Cognitive Services is currently available in Azure public \u2013 and will soon be available in Azure Government.<\/p>\n<p>In the screenshot below, you can see that I already have a Cognitive Services account set up that is specifically for the \u201cTranslator Text API\u201d.<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?attachment_id=5205\"><img decoding=\"async\" width=\"931\" height=\"324\" class=\"aligncenter  wp-image-5205\" alt=\"1\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/126.png\" \/><\/a><\/p>\n<p>We can click the \u201cKeys\u201d tab to see the access keys and we can copy Key 1 to our clipboard.<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?attachment_id=5195\"><img decoding=\"async\" width=\"372\" height=\"214\" class=\"aligncenter size-full wp-image-5195\" alt=\"2\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/211.png\" \/><\/a><\/p>\n<p>Now that we have our access key, let\u2019s familiarize ourselves with the basic Cognitive Services Translator API. First, we need to get an access token to make our translation calls. Let\u2019s use <a href=\"https:\/\/www.getpostman.com\/\">Postman<\/a> to make our HTTP calls. Postman is a free, cross-platform tool that enables developers to easily make direct calls to HTTP web APIs.<\/p>\n<p>We must first call the cognitive services issueToken endpoint to get a bearer token:<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?attachment_id=5185\"><img decoding=\"async\" width=\"892\" height=\"491\" class=\"aligncenter size-full wp-image-5185\" alt=\"3\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/39.png\" \/><\/a><\/p>\n<p>We execute an HTTP POST to <strong>https:\/\/api.cognitive.microsoft.com\/sts\/v1.0\/issueToken<\/strong> while sending the Key we copied from the portal as the <strong>Ocp-Apim-Subscription-Key<\/strong> header. This returns a large string that we\u2019ll use as the bearer token. Since we need to send this token on subsequent requests, let\u2019s store it in Postman as a \u201cglobal\u201d to make subsequent calls easier. We\u2019ll store it in a Postman global called \u201ccs-bearer-token\u201d \u2013 the value will be \u201cBearer\u201d followed by a space and the value returned from the issueToken call:<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?attachment_id=5175\"><img decoding=\"async\" width=\"732\" height=\"237\" class=\"aligncenter size-full wp-image-5175\" alt=\"4\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/45.png\" \/><\/a><\/p>\n<p>Now let\u2019s make a call to the Cognitive Services text translation API. As shown in the screen shot below, we\u2019ll call the <strong>\/translate<\/strong> endpoint with the following query string parameters:<\/p>\n<ul>\n<li><strong>appId = {{cs-bearer-token}}<\/strong>\n<ul>\n<li>This was the Postman global we saved in the previous step<\/li>\n<\/ul>\n<\/li>\n<li><strong>to = fr<\/strong>\n<ul>\n<li>The \u201cfr\u201d code shows that we are translating <strong>to<\/strong> French<\/li>\n<\/ul>\n<\/li>\n<li><strong>text = the quick brown fox jumped over the lazy dog<\/strong>\n<ul>\n<li>This is the text that we\u2019ll translate to another language<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?attachment_id=5165\"><img decoding=\"async\" width=\"1234\" height=\"375\" class=\"aligncenter size-full wp-image-5165\" alt=\"5\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/56.png\" \/><\/a><\/p>\n<p>Now that we\u2019ve seen how basic translation works on a simple string, let\u2019s translate an entire document. To do this, we\u2019ll use the SpeechTranslator sample app that can be <a href=\"https:\/\/github.com\/microsofttranslator\/speechtranslator\/tree\/AzureAuth\">found in GitHub<\/a>. This sample app provides a simple user interface that calls the translator APIs behind the scenes.<\/p>\n<p>We have an existing text file in Chinese that we want to translate to English \u2013 this text file contains the book \u201cThe Art of War\u201d:<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?attachment_id=5155\"><img decoding=\"async\" width=\"418\" height=\"655\" class=\"aligncenter size-full wp-image-5155\" alt=\"6\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/65.png\" \/><\/a><\/p>\n<p>We\u2019ll use the SpeechTranslator app to translate this to English:<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?attachment_id=5145\"><img decoding=\"async\" width=\"800\" height=\"640\" class=\"aligncenter size-full wp-image-5145\" alt=\"7\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/74.png\" \/><\/a><\/p>\n<p>In just a few seconds, we now have a text file translated to English:<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?attachment_id=5135\"><img decoding=\"async\" width=\"328\" height=\"250\" class=\"aligncenter size-full wp-image-5135\" alt=\"8\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/86.png\" \/><\/a><\/p>\n<p>Now that we have our document translated, we\u2019re ready to perform some text analytics on the document. In the next section, we\u2019ll leverage HDInsight to perform this analysis.<\/p>\n<p><span>We welcome your comments and suggestions to help us continually\u00a0improve your Azure Government experience. To stay up to date on all things Azure Government, be sure to subscribe to our <a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/feed\/\">RSS feed<\/a> and to receive emails, click \u201cSubscribe by Email!\u201d on the <a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/\">Azure Government Blog<\/a>. To experience the power of Azure Government for your organization, sign up for an <a href=\"https:\/\/azuregov.microsoft.com\/trial\/azuregovtrial\">Azure Government Trial<\/a>.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Microsoft Azure Government platform is rapidly innovating with new services being introduced all the time. We have recently announced HDInsight and Power BI as GA on Azure Government. These data-centric services unlock a world of possibilities for your organization to process massive amount of data. In this developer-centric walk-through, I will show you how [&hellip;]<\/p>\n","protected":false},"author":1789,"featured_media":5215,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[15,21,25],"tags":[75,95,188,328,457],"class_list":["post-5125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-management","category-onboarding","category-portalpreview","tag-azure","tag-azure-government","tag-cognitive-services","tag-hdinsight","tag-power-bi"],"acf":[],"blog_post_summary":"<p>The Microsoft Azure Government platform is rapidly innovating with new services being introduced all the time. We have recently announced HDInsight and Power BI as GA on Azure Government. These data-centric services unlock a world of possibilities for your organization to process massive amount of data. In this developer-centric walk-through, I will show you how [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts\/5125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/users\/1789"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/comments?post=5125"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts\/5125\/revisions"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/media?parent=5125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/categories?post=5125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/tags?post=5125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}