Before reading this article, please go through the following articles.
- Introduction To Universal Windows Platform (UWP) App Development Using Windows 10 And Visual Studio 2015
- Getting Started With Microsoft Azure Cognitive Services - Text Analytics API
Microsoft Cognitive Services (formerly Project Oxford) are a set of APIs, SDKs and services available to developers to make their applications more intelligent, engaging and discoverable. Microsoft Cognitive Services expands on Microsoft’s evolving portfolio of machine learning APIs and enables developers to easily add intelligent features. Microsoft Cognitive Services let you build apps with powerful algorithms using just a few lines of code. They work across devices and platforms such as iOS, Android, and Windows, keep improving, and are easy to set up.
Text Analytics API, as described by Microsoft, is designed to detect sentiment, key phrases, topics, and language from your text.
Reading this article, you can learn how to do Cognitive Text Analytics API – Key Phrase Extraction in Universal Windows apps development with Azure, XAML and Visual C#.
The following important tools are required for developing UWP,
- Windows 10 (Recommended)
- Visual Studio 2015 Community Edition (It is a free software available online)
- Cognitive Service Text Analytics API Key (using azure Getting Started With Microsoft Azure Cognitive Services - Text Analytics API)
Now we can discuss step by step App development.
Step 1
Open Visual studio 2015 -> Start -> New Project-> Select Universal (under Visual C#->Windows)-> Blank App -> Give a suitable name for your app (UWPCogTextAnaly)->OK.

After choosing the target and minimum platform version that your app will support, the Project creates App.xaml and MainPage.xaml.

Step 2
Open (double click) the file MainPage.xaml in the Solution Explorer and add the Newtonsoft.Json reference in the project. Right click your project (UWPCogTextAnaly) and select "Manage NuGet Packages".

For adding Newtonsoft.Json reference, choose Browse and Search Newtonsoft.Json. Select the package and install it.

Reference is added to your project

Step 3
Add 2 TextBlock controls, change the name and text property for SampleText.

Add a Button Control, set the Name, and add the Edit icon for Listing Key Phrases.

Step 4
Add GridView Resources, using the code, mentioned below.
- <Grid.Resources>
- <CollectionViewSource x:Name="KeyPhraseResultsCol" Source="{x:Bind KeyPharseResults}" IsSourceGrouped="False" />
- </Grid.Resources>
- <GridView x:Name="gvKeyPhr" ItemsSource="{Binding Source={StaticResource KeyPhraseResultsCol}}" SelectionMode="None" IsItemClickEnabled="False" HorizontalAlignment="Left" Height="276" Margin="96,233,0,0" VerticalAlignment="Top" Width="1054">

Add the following code for GridView Item Template for Phrase list.
- <GridView.ItemTemplate>
- <DataTemplate>
- <Border Background="AliceBlue" Width="330" Height="38" Margin="8">
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="auto" />
- <ColumnDefinition/>
- </Grid.ColumnDefinitions>
- <Grid Grid.Column="1" Margin="3,3,3,10">
- <Grid.RowDefinitions>
- <RowDefinition Height="auto" />
- </Grid.RowDefinitions>
- <StackPanel Margin="0,0,0,-143">
- <TextBlock TextWrapping="Wrap" Text="{Binding kpco.phrases}" Style="{StaticResource CaptionTextBlockStyle}" Height="28" />
- </StackPanel>
- </Grid>
- </Grid>
- </Border>
- </DataTemplate>
- </GridView.ItemTemplate>

Step 5
Add the Click Event method for Phrase find button.

Note
Automatically, the following code will be generated in XAML code view, while we are done in the design view.
- <Page x:Class="UWPCogTextAnaly.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:UWPCogTextAnaly" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <Grid.Resources>
- <CollectionViewSource x:Name="KeyPhraseResultsCol" Source="{x:Bind KeyPharseResults}" IsSourceGrouped="False" />
- </Grid.Resources>
- <TextBlock x:Name="tblTitle" HorizontalAlignment="Left" Margin="324,73,0,0" TextWrapping="Wrap" Text="UWP Cognitive Service Text Analytics - Key Phrase Extraction Demo" VerticalAlignment="Top" FontWeight="Bold" FontSize="20" />
- <TextBlock x:Name="tbltest" HorizontalAlignment="Left" Margin="46,166,0,0" TextWrapping="Wrap" Text="Sample Text : " VerticalAlignment="Top" FontWeight="Bold" FontSize="20" />
- <TextBlock x:Name="tblText" HorizontalAlignment="Left" Height="36" Margin="178,166,0,0" TextWrapping="Wrap" Text="The manual transmission is a bit twitchy. Also, the vehicle is old-school" VerticalAlignment="Top" Width="748" FontSize="22" />
- <Button x:Name="btnKeyPhrase" HorizontalAlignment="Left" Margin="952,170,0,0" VerticalAlignment="Top" Click="btnKeyPhrase_Click" RenderTransformOrigin="3.6,0.312" ToolTipService.ToolTip="Click to Key Phrase">
- <SymbolIcon Symbol="Edit"></SymbolIcon>
- </Button>
- <GridView x:Name="gvKeyPhr" ItemsSource="{Binding Source={StaticResource KeyPhraseResultsCol}}" SelectionMode="None" IsItemClickEnabled="False" HorizontalAlignment="Left" Height="276" Margin="96,233,0,0" VerticalAlignment="Top" Width="1054">
- <GridView.ItemTemplate>
- <DataTemplate>
- <Border Background="AliceBlue" Width="330" Height="38" Margin="8">
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="auto" />
- <ColumnDefinition/>
- </Grid.ColumnDefinitions>
- <Grid Grid.Column="1" Margin="3,3,3,10">
- <Grid.RowDefinitions>
- <RowDefinition Height="auto" />
- </Grid.RowDefinitions>
- <StackPanel Margin="0,0,0,-143">
- <TextBlock TextWrapping="Wrap" Text="{Binding kpco.phrases}" Style="{StaticResource CaptionTextBlockStyle}" Height="28" />
- </StackPanel>
- </Grid>
- </Grid>
- </Border>
- </DataTemplate>
- </GridView.ItemTemplate>
- </GridView>
- </Grid>
- </Page>



Vignesh ManiPosted Nov 15, 2016, 5:46 PM
Good article. Nice share..