Building a solution on Azure Government Part I: Cognitive Services

Steve Michelotti

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 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:

  1. Cognitive Services to translate a Chinese document to English.
  2. HDInsight to perform data analytics on that translation and produce basic word counts.
  3. Power BI to visualize the data produced by HDInsight.

If you prefer, you can follow along with a video walk-through of this blog post.

Cognitive Services

First, we will use Cognitive Services for document translation. Cognitive Services is currently available in Azure public – and will soon be available in Azure Government.

In the screenshot below, you can see that I already have a Cognitive Services account set up that is specifically for the “Translator Text API”.

1

We can click the “Keys” tab to see the access keys and we can copy Key 1 to our clipboard.

2

Now that we have our access key, let’s familiarize ourselves with the basic Cognitive Services Translator API. First, we need to get an access token to make our translation calls. Let’s use Postman to make our HTTP calls. Postman is a free, cross-platform tool that enables developers to easily make direct calls to HTTP web APIs.

We must first call the cognitive services issueToken endpoint to get a bearer token:

3

We execute an HTTP POST to https://api.cognitive.microsoft.com/sts/v1.0/issueToken while sending the Key we copied from the portal as the Ocp-Apim-Subscription-Key header. This returns a large string that we’ll use as the bearer token. Since we need to send this token on subsequent requests, let’s store it in Postman as a “global” to make subsequent calls easier. We’ll store it in a Postman global called “cs-bearer-token” – the value will be “Bearer” followed by a space and the value returned from the issueToken call:

4

Now let’s make a call to the Cognitive Services text translation API. As shown in the screen shot below, we’ll call the /translate endpoint with the following query string parameters:

  • appId = {{cs-bearer-token}}
    • This was the Postman global we saved in the previous step
  • to = fr
    • The “fr” code shows that we are translating to French
  • text = the quick brown fox jumped over the lazy dog
    • This is the text that we’ll translate to another language

5

Now that we’ve seen how basic translation works on a simple string, let’s translate an entire document. To do this, we’ll use the SpeechTranslator sample app that can be found in GitHub. This sample app provides a simple user interface that calls the translator APIs behind the scenes.

We have an existing text file in Chinese that we want to translate to English – this text file contains the book “The Art of War”:

6

We’ll use the SpeechTranslator app to translate this to English:

7

In just a few seconds, we now have a text file translated to English:

8

Now that we have our document translated, we’re ready to perform some text analytics on the document. In the next section, we’ll leverage HDInsight to perform this analysis.

We welcome your comments and suggestions to help us continually improve your Azure Government experience. To stay up to date on all things Azure Government, be sure to subscribe to our RSS feed and to receive emails, click “Subscribe by Email!” on the Azure Government Blog. To experience the power of Azure Government for your organization, sign up for an Azure Government Trial.

0 comments

Discussion is closed.

Feedback usabilla icon