Reader small image

You're reading from  Learning Microsoft Cognitive Services, - Third Edition

Product typeBook
Published inSep 2018
Reading LevelBeginner
PublisherPackt
ISBN-139781789800616
Edition3rd Edition
Languages
Right arrow
Author (1)
Leif Larsen
Leif Larsen
author image
Leif Larsen

Leif Larsen is a software engineer based in Norway. After earning a degree in computer engineering, he went on to work with the design and configuration of industrial control systems, for the most part, in the oil and gas industry. Over the last few years, he has worked as a developer, developing and maintaining geographical information systems, working with .NET technology. Today, he is working with a start-up, developing a brand new SaaS product. In his spare time, he develops mobile apps and explores new technologies to keep up with the high-paced tech world. You can find out more about him by checking out his blog, "Leif Larsen", and following him on Twitter (@leif_larsen) and LinkedIn (lhlarsen).
Read more about Leif Larsen

Right arrow

Chapter 6. Understanding Text

The previous chapter covered the speech APIs. Throughout this chapter, we will look closer at more language APIs. We will learn how to use spellcheck features. We will then discover how to detect languages, key phrases, and sentiment in text. Finally, we will look at the translator text API to see how we can detect languages and translate text.

By the end of this chapter, we will have covered the following topics:

  • Checking spelling and recognizing slang and informal language, common names, homonyms, and brands

  • Detecting language, key phrases, and sentiment in text

  • Translating text on the fly

Setting up a common core


Before we get into the details, we want to set ourselves up for success. At the time of writing, none of the language APIs that we will be covering have NuGet client packages. As such, we will need to call directly to the REST endpoints. Because of this, we will do some work beforehand to make sure that we get away with writing less code.

New project

We will not be adding the APIs to our smart-house application. Using the following steps, create a new project using the MVVM template that we created in Chapter 1, Getting Started with Microsoft Cognitive Services:

  1. Go into the NuGet package manager and install Newtonsoft.Json. This will help us deserialize API responses and serialize request bodies.

  2. Right-click on References.

  3. In the Assemblies tab, select System.Web and System.Runtime.Serialization.

  4. Click OK.

  5. In the MainView.xaml file, add a TabControl element. All our additional views will be added as TabItems in the MainView.

Web requests

All the APIs follow the same pattern...

Correcting spelling errors


The Bing Spell Check API leverages the power of machine learning and statistical machine translation to train and evolve a highly contextual algorithm for spellchecking. Doing so allows us to utilize this to perform spellchecking using context.

A typical spellchecker will follow dictionary-based rule sets. As you can imagine, this will need continuous updates and expansions.

Using the Bing Spell Check API, we can recognize and correct slang and informal language. It can recognize common naming errors and correct word-breaking issues. It can detect and correct words that sound the same, but differ in meaning and spelling (homophones). It can also detect and correct brands and popular expressions.

Create a new View in the View folder; call the file SpellCheckView.xaml. Add a TextBox element for the input query. We will also need two TextBox elements for the pre- and post-context. Add a TextBox element to show the result and a Button element to execute the spellcheck...

Extracting information through textual analysis


Using the text analytics API, we are able to analyze text. We will cover language detection, key-phrase analysis, and sentiment analysis. In addition, a new feature is the ability to detect topics. This does, however, require a lot of sample text, and as such, we will not go into detail on this last feature.

For all our text-analysis tasks, we will be using a new View. Add a new View into the View folder called TextAnalysisView.xaml. This should contain a TextBox element for the input query. It should also have a TextBox element for the result. We will need three Button elements, one for each detection analysis that we will perform.

We will also need a new ViewModel, so add TextAnalysisViewModel.cs to the ViewModel folder. In this, we need two string properties, one for each TextBox. Also add three ICommand properties, one for each of our buttons.

If you have not already done so, register for an API key at https://portal.azure.com.

Add a private...

Translating text on the fly


Using the translator text API, you can easily add translations to your application. The API allows you to automatically detect the language. This can be used to serve localized content, or to quickly translate content. It also allows us to look up alternative translations that can be used to translate words into different contexts.

In addition, the translator text API can be used to build customized translation systems. This means that you can improve the existing models. This can be done by adding existing human translations related to expressions and vocabulary in your industry.

The translator text API is available as a REST API. We will cover the four endpoints that you can reach. To use the API, the following root URL should be used:

https://api.cognitive.microsofttranslator.com

Sign up for an API key at Microsoft Azure Portal.

Translating text

To translate text from one language to another, you should call the following URL path:

/translate

The following parameters...

Summary


In this chapter, we have focused on the language APIs. We started by creating the parts that are needed to execute the API calls to the different services. Following this, we looked at the Bing Spell Check API. We moved on to more analytical APIs, where we learned how to detect languages, key phrases, and sentiment. Finally, we looked into how we can use the translator text API.

The next chapter will take us from language APIs to knowledge APIs. In the following chapter, we will learn how to recognize and identify entities based on context. In addition, we will learn how to use the recommendations API.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning Microsoft Cognitive Services, - Third Edition
Published in: Sep 2018Publisher: PacktISBN-13: 9781789800616
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Leif Larsen

Leif Larsen is a software engineer based in Norway. After earning a degree in computer engineering, he went on to work with the design and configuration of industrial control systems, for the most part, in the oil and gas industry. Over the last few years, he has worked as a developer, developing and maintaining geographical information systems, working with .NET technology. Today, he is working with a start-up, developing a brand new SaaS product. In his spare time, he develops mobile apps and explores new technologies to keep up with the high-paced tech world. You can find out more about him by checking out his blog, "Leif Larsen", and following him on Twitter (@leif_larsen) and LinkedIn (lhlarsen).
Read more about Leif Larsen