Cognitive Service Academic Knowledge API - Evaluate Method using UWP with Azure, XAML AND C#
Before reading this article, please go through the articles, mentioned below.
- Introduction To Universal Windows Platform (UWP) App Development Using Windows 10 And Visual Studio 2015
- How To Create Microsoft Cognitive Service Academic Knowledge API On Azure Portal
Microsoft Cognitive Services
Microsoft Cognitive Services (formerly Project Oxford) are a set of APIs, SDKs and the Services available to the 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 the developers to easily add intelligent features. Microsoft Cognitive Services allows you to 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.
Academic Knowledge API
Academic Knowledge API is able to interpret the user queries for academic intent and retrieve rich information from Microsoft Academic Graph (MAG). MAG knowledge base is a Web-scale heterogeneous entity graph, made of entities that model scholarly activities like field of study, author, institution, paper, venue and event.
Academic Knowledge API consists of three related REST endpoints.
Interpret
Interpret is a natural language user query string. It returns the annotated interpretations to enable rich search-box auto-completion experiences, which anticipates what the user is typing.
Evaluate
It evaluates a query expression and returns Academic Knowledge entity results.
Calchistogram
It calculates a histogram of the distribution of the attribute values for the academic entities returned by a query expression, such as the distribution of citations by year for a given author.
Reading this article, you can learn how to use Cognitive Service Academic Knowledge API - evaluate method in Universal Windows apps development with Azure, XAML and Visual C#.
The important tools, mentioned below, are required to develop UWP.
- Windows 10 (Recommended).
- Visual Studio 2015 Community Edition (It is a free software available online).
- Cognitive Service Academic Knowledge API Key (using Azure How To Create Microsoft Cognitive Service Academic Knowledge API On Azure Portal).
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 the suitable name for your app (UWPCogAcdSerEval)->OK.
After choosing the Target and minimum platform version your Windows Universal Application 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 on your project (UWPCogAcdSerEval) 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 TextBlock control, change the Name and text property for the title.
Add TextBlock control, set the Name, Text and Text Properties for expression string.
Add a Button control, set the Name and add the search icon for Find Academy info.
Step 4
Add GridView Resources, using the code, mentioned below.
- <Grid.Resources>
- <CollectionViewSource x:Name="SearchResultsCol" Source="{x:Bind SearchResults}" IsSourceGrouped="False" />
- </Grid.Resources>
- Add a GridView Control and set the ItemSource properties
- <GridView x:Name="gv" ItemsSource="{Binding Source={StaticResource SearchResultsCol}}" SelectionMode="None" IsItemClickEnabled="False" HorizontalAlignment="Left" Height="467" Margin="71,199,0,0" VerticalAlignment="Top" Width="1117" Background="#FFE7FDFD">
Add the code, mentioned below for Grid View Item Template for News details.
- <GridView.ItemTemplate>
- <DataTemplate>
- <Border Background="#FF07FDF2" Width="1098" Height="123" 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 evco.Title}" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" />
- <TextBlock TextWrapping="Wrap" Text="{Binding evco.Year}" Style="{StaticResource CaptionTextBlockStyle}" />
- <TextBlock TextWrapping="Wrap" Text="{Binding evco.Citationcount}" Style="{StaticResource CaptionTextBlockStyle}" />
- <TextBlock TextWrapping="Wrap" Text="{Binding evco.Authorname}" Style="{StaticResource CaptionTextBlockStyle}" />
- <TextBlock TextWrapping="Wrap" Text="{Binding evco.AuthorID}" Style="{StaticResource CaptionTextBlockStyle}" />
- </StackPanel>
- </Grid>
- </Grid>
- </Border>
- </DataTemplate>
- </GridView.ItemTemplate>
Step 5 Add the Click event method for Search button.
Note
Automatically, the code, mentioned below will be generated in XAML code view, while we are done in the design view.
- <Page x:Class="UWPCogAcdSerEval.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:UWPCogAcdSerEval" 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="SearchResultsCol" Source="{x:Bind SearchResults}" IsSourceGrouped="False" />
- </Grid.Resources>
- <TextBlock x:Name="tblTitle" HorizontalAlignment="Left" Margin="279,83,0,0" TextWrapping="Wrap" Text="UWP Cognitive Service Academic Search API Evaluate Method" VerticalAlignment="Top" FontWeight="Bold" Height="33" Width="672" FontSize="22" />
- <TextBlock x:Name="tblExpr" HorizontalAlignment="Left" Margin="215,165,0,0" TextWrapping="Wrap" Text="Expr String : Composite(AA.AuN=='jaime teevan')" VerticalAlignment="Top" Height="25" Width="477" FontSize="16" />
- <Button x:Name="btnAcdSerEval" HorizontalAlignment="Left" Margin="856,162,0,0" VerticalAlignment="Top" Click="btnAcdSerEval_Click">
- <SymbolIcon Symbol="Find"></SymbolIcon>
- </Button>
- <GridView x:Name="gv" ItemsSource="{Binding Source={StaticResource SearchResultsCol}}" SelectionMode="None" IsItemClickEnabled="False" HorizontalAlignment="Left" Height="467" Margin="71,199,0,0" VerticalAlignment="Top" Width="1117" Background="#FFE7FDFD">
- <GridView.ItemTemplate>
- <DataTemplate>
- <Border Background="#FF07FDF2" Width="1098" Height="123" 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 evco.Title}" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" />
- <TextBlock TextWrapping="Wrap" Text="{Binding evco.Year}" Style="{StaticResource CaptionTextBlockStyle}" />
- <TextBlock TextWrapping="Wrap" Text="{Binding evco.Citationcount}" Style="{StaticResource CaptionTextBlockStyle}" />
- <TextBlock TextWrapping="Wrap" Text="{Binding evco.Authorname}" Style="{StaticResource CaptionTextBlockStyle}" />
- <TextBlock TextWrapping="Wrap" Text="{Binding evco.AuthorID}" Style="{StaticResource CaptionTextBlockStyle}" />
- </StackPanel>
- </Grid>
- </Grid>
- </Border>
- </DataTemplate>
- </GridView.ItemTemplate>
- </GridView>
- </Grid>
- </Page>
Step 6
Add the namespaces, mentioned below in Mainpage.xaml.cs for Bing Video search,
- using System.Net.Http;
- using System.Threading.Tasks;
- using Newtonsoft.Json.Linq;
- using System.Collections.ObjectModel;
Step 7
Add the Academic Knowledge. Client keys use Azure Service and generate it (For more information, please refer the article
How To Create Microsoft Cognitive Service Academic Knowledge API On Azure Portal)
Academic Knowledge REST endpoint is mentioned below.
https://api.projectoxford.ai/academic/v1.0/evaluate?
Add the code, mentioned below with Azure generated key.
- public class evalc {
- public string Title {
- get;
- set;
- }
- public string Year {
- get;
- set;
- }
- public string Citationcount {
- get;
- set;
- }
- public string Authorname {
- get;
- set;
- }
- public string AuthorID {
- get;
- set;
- }
- }
- public class evalCol {
- public evalc evco {
- get;
- set;
- }
- }
- public ObservableCollection < evalCol > SearchResults {
- get;
- set;
- } = new ObservableCollection < evalCol > ();
- private async void btnAcdSerEval_Click(object sender, RoutedEventArgs e) {
- var eva = await eval();
- for (int i = 0; i < eva.Count(); i++) {
- evalc ev = eva.ElementAt(i);
- SearchResults.Add(new evalCol {
- evco = ev
- });
- }
- }
- async Task < IEnumerable < evalc >> eval() {
- https:
- List < evalc > evalcc = new List < evalc > ();
- var client = new HttpClient();
- client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "<Your Key>");
- var result = await client.GetAsync(string.Format("https://api.projectoxford.ai/academic/v1.0/evaluate?expr=Composite(AA.AuN=='jaime teevan')&model=latest&count=10&offset=0&attributes=Ti,Y,CC,AA.AuN,AA.AuId"));
- result.EnsureSuccessStatusCode();
- var json = await result.Content.ReadAsStringAsync();
- dynamic data = JObject.Parse(json);
- for (int i = 0; i < 10; i++) {
- evalcc.Add(new evalc {
- Title = "Title : " + data.entities[i].Ti,
- Year = "Year :" + data.entities[i].Y,
- Citationcount = "Citation Count :" + data.entities[i].CC,
- Authorname = "Authorname :" + data.entities[i].AA[0].AuN,
- AuthorID = "AuthorID :" + data.entities[i].AA[0].AuId
- });
- }
- return evalcc;
- }
Step 8
Deploy your app in the local machine and the output of UWPCogAcdSerEvalaApp is mentioned below.
Summary
Now, you have successfully tested Cognitive Service Academic Knowledge API - evaluation method, using Azure, XAML and C# with UWP environment.
If you are interested, please read the UWP Cognitive Service articles, mentioned below.
- Cognitive Service Bing Video Search API Using UWP With Azure, XAML And C#
- Cognitive Service Bing Image Search API Using UWP With Azure, XAML And C#
- Cognitive Service Bing News Search API Using UWP With Azure, XAML And C#
- Cognitive Service Bing AutoSuggest API Using UWP With Azure, XAML And C#
- Multiple People Emotions In UWP With Cognitive Service Emotion API, Azure, XAML And C#
- Cognitive Service Emotion API In UWP With Azure, XAML And C#
- Retrieving Face Attributes Using Cognitive Service Face API In UWP With Azure, XAML And C#
- Cognitive Service Face API, Using UWP With Azure, XAML And C#