I have been fascinated with all of the new services launched within the Microsoft Azure environment in recent months. There are a vast number of services available (and more added all of the time), however it’s easy to be intimidated with the various services available.

What Microsoft have been able to achieve with the Azure platform, is the lowering of the point of entry to interact with the various Azure services and deliver real business value.

A great example of this is Text Analytics which has recently been launched within the Microsoft Azure Marketplace. Text Analytics is based on Azure Machine Learning (artificial intelligence) which can help you to understand the sentiment of unstructured text.

I personally am quite excited by the prospect of being able to quickly and more importantly automatically analyze unstructured data in order to drive business insight and/or value.

The Text Analytics services will look at a string of text and either extract key phrases, or identify the sentiment of that text between 0 and 1 whereby results closer to 1 indicate positive sentiments, and those closer to 0 represent negative sentiments.

Why is this useful you may wonder? Well let’s keep things simple and look at business workflows with Nintex Workflow.

In many scenarios we need to assign tasks or perform actions based on a particular input. If this input happened to be customer feedback inserted into a form via Nintex Forms, a Twitter comment (ref Nintex Live Twitter actions), or perhaps internal support calls which you are logging into a SharePoint list (ref. email enabled libraries).

Looking at the Twitter action as an example, whilst we can write a Nintex Workflow to monitor specific hash tags on Twitter (to capture any mention of our organisation perhaps) – this can be quite an onerous task to monitor.

What if we could automatically analyse the tweet and depending on whether this was a positive or negative tweet (complaint) route a workflow task through to the applicable internal team such as your public relations or marketing team.

Now enter Azure Text Analytics.

Integrating Azure Text Analytics with Nintex Workflow is surprisingly simple. The steps below will create a user defined action to interact with the Azure Text Analytics API and then return the result to a test workflow for further development.

Text Analytics Setup

Head over to http://datamarket.azure.com/dataset/amla/text-analytics and sign up for the service

Next, you need to click through and request an account key for you Azure account. This is important as a key is how you authenticate with the API

In order to use your account key in a web request for the API, you need to base64 encode it (see documentation at http://azure.microsoft.com/en-us/documentation/articles/machine-learning-apps-text-analytics/). All I did was search for a website which did this conversion for me (http://www.motobit.com/util/base64-decoder-encoder.asp) and encode my account key using their converter. As per the documentation above, you need to prepend “AccountKey:” to your actual account key e.g. encode “AccountKey:<your Azure API account key>”.

This resulting string is what we use within Nintex Workflow to authenticate against the Text Analytics API.

User Defined Action

Creating a UDA makes sense for this requirement as it makes the API simple to reuse.

All we need to do to interrogate the API is to insert a Web Request action into our UDA.

Sentiment Analysis 3

In the action the URL needs to be configured as
https://api.datamarket.azure.com/data.ashx/amla/text-analytics/v1/GetSentiment?Text=<TextToAnalyse>

For the headers, this is where the account key that we encoded earlier comes into play. You need to create a header with name Authorization and for the value insert “Basic <your encoded API key>”.

This is all you need to do in order to get a valid response back from the API. Once the output is stored in a variable, you then need to parse this to extract the sentiment score.

{
  "odata.metadata":"https://api.datamarket.azure.com/data.ashx/amla/text-analytics/v1/$metadata#TextAnalytics.FrontEndService.Models.SentimentResult","Score":0.8626977
}

The above HTTP result can be parsed with a regular expression. I approached this with:

\.[0-9]{2}

Which will return a 2 decimal place number e.g. 0.86

Sentiment Analysis 4

Whilst the above essentially gives us a score of 86/100 for sentiment (i.e. very positive), I wanted to convert this to a number in order to make a decision whether the sentiment was essentially good or bad.

The applicable workflow so far is summarised below:

Sentiment Analysis 1

The next step is to convert the resulting string into a number so we can then simply decide the status of the text. In my condition rules, if the sentiment if above “50” then I consider the text sentiment to be good for example.

Sentiment Analysis 2

We now have a very straight forward implementation of the Text Analytics service wrapped up within a UDA in Nintex.

Implementing the UDA

As per the introduction, depending on your business problem e.g. analysing the sentiment on twitter comments – we can now include our new UDA into a workflow.

To demonstrate this end-to-end, I created as workflow which returns a basic Good or Bad for the sentiment of the text used in the title of a list item.

Analyse Text

From this point, the process is essentially identical to implement a more complex example.

Example Output

I have included a screenshot below of how some sample text may be interpretted by the Text Analytics service.

Examples

Conclusion

Whilst my post is light on detail, hopefully you can see the possibilities for integrating advanced functionality such as Text Analytics into your Nintex Workflows to deliver even more business value through more productive automation.

One thought on “Sentiment analysis with Nintex Workflow and Azure Machine Learning”

Leave a Reply

Your email address will not be published. Required fields are marked *