Recent articles


Xamarin Forms and AI Bot Framework with LUIS - Part 1

Posted by seven.srikanth@gmail.com at 28 May 2018 in Article


 Overview

Hi Guys, We are about to discuss another Xamarin.Forms article which introduce the idea of conversational computing in an organic way (AI), where hoomans can use their natural language in making a command to apps which can have an IoT integration or can be simple conversational bot with a human understanding. First, we gonna discuss about Language Understanding Intelligent Services (LUIS) and how to utilize its capability. This is a three part series and if you already confident about the topic you can proceed to the next. Xamarin.Forms and AI Bot Framework with LUIS -  Part 2 Xamarin.Forms and AI Bot Framework with LUIS -  Part 3

Benefits to using LUIS

One of the key problems in human-computer interactions is the ability of the computer to understand what a person wants, and to find the pieces of information that are relevant to their intent. For example, in a travel agent app, you might say "Book me a ticket to Paris" in which case there is the intention to "BookTicket" while "Paris" is the location entity. Intention can be defined as the desired action and usually contains a verb, in this case "book", and the entity is the topic/subject, in this case "Paris", of the action.

Using LUIS for the first time

Language Understanding Intelligent Services (LUIS) brings the power of machine learning to your apps, you can custom design a set of intentions and entities that are relevant to your application, then let LUIS guide you through the process of building a language understanding system. To use LUIS, first make sure that you have an up-to-date version of Microsoft Edge, Internet Explorer or Google Chrome. Go to the home page www.luis.ai and log in. You will see a screen like the one below.

Creating your first LUIS application

LUIS applications are centered around a domain-specific topic, for example booking of tickets, flights, hotels, rental cars etc. or content related to exercising, tracking fitness efforts and setting goals. You need to decide on a domain-specific topic before you can create your LUIS application. In this case, let's take the example of a virtual travel booking agency application. In the application, you will bundle together the intents and entities that are important to your task. Two intents relevant to the domain of travel booking are "BookFlight" and "GetWeather". Two entities that are important are "Location" and "DateTime". Once you have identified the intents and entities, it is possible for LUIS to take appropriate action, when a user interacts with your application.

Step 1: Creating an application

Step 2: Adding intents, entities and labels

Next, we will add two intents to the application. At the top left of the menu panel, you will see an area for intents. All applications come with one pre-defined intent, None. This will recognize user statements that have nothing to do with the application, for example if someone says "Get me a great cookie recipe". Go ahead and click + next to Intents on the horizontal bar. You'll see a dialog box appear to add a new intent. Enter the intent name of "BookFlight", and the example command that triggers the intent as "Book flight to Paris". This will look like the screenshot below.
Click Save, and the utterance will be presented for labeling. The intent "BookFlight" (just click on it) will be highlighted, and you will see a drop-down with the entities you've defined. Click Submit to submit the utterance to your LUIS app.

Defining entities

  1. In the Application Editor workspace, find Entities in the left-hand menu panel, then click the + sign.
  2. In the Add a new Entity dialog box, type "Location" as the entity name.
  3. Click the plus sign next to the Entity Children.
  4. In the text box that appears, type the name of the first child, "ToLocation".
  5. Click the plus sign again to add the second child, “FromLocation”, and so on.
  6. To delete a child, if you made a mistake, click the trash can sign next to the entity child.
  7. When finished, click "Save".

Step 3: Seeding the system by labeling utterances

With a set of intents and entities defined, the next step is to provide more examples of utterances that illustrate these concepts. Click on the New Utterances tab at the top of the screen. Type "Book a flight to London" into the entry box and hit Enter. You will see a drop-down box showing the possible intents. Select "BookFlight" by highlighting it. Click on "london" and select "Location" from the drop-down box and you'll see the word "london" highlighted in yellow, indicating that you've labeled the word "london" as a "Location". Choose whether it is a "ToLocation" or "FromLocation", then click Submit to submit this label. The system needs to be seeded with several examples of each intent, and several examples of each entity. Don't forget to add an example or two of a None intent, for example, enter "I like ice cream". Note, that LUIS converts all utterances to lower case. The system has now been seeded with enough data to deploy an initial application. That is done by training and publishing a model.

Step 4: Training

When you "train" a model, LUIS generalizes from the examples you have labeled, and develops code to recognize the relevant intents and entities in the future. Internally, LUIS uses logistic regression classifiers to determine intents, and conditional random fields (CRFs) to determine the entities. The training process results in optimized classifiers and CRFs, referred to as models, that LUIS can use in the future. To do training, just click the Train button at the left bottom corner of the page. Training also occurs automatically with regular intervals.

Step 5: Publishing a model

The next step is to deploy the model to an HTTP endpoint that will interpret the sentences we send it. Click the Publish button in the upper left-hand corner, and then Publish web service in the resulting window. After a couple of moments, you will see a url that makes your model available as a web service. LUIS will look like the below screenshot. To acquire a subscription key, see Creating Subscription Keys Via Azure Ibiza.

Understanding the JSON response

  1. Set the URL parameter to be your query/utterance, for example, "Book me a flight to Boston on May 4", then click Update published application..
  2. Hit the Enter key or click on the generated URL in the dialog box.
FieldJson typeDescription of content in example
QuerystringQuery/utterance: "Book me a flight to Boston on May 4"
IntentsobjectAll intents listed (each with their highest score): "BookFlight", "None", "GetWeather"
ScorenumberConfidence score, between 0 and 1. Only the highest score is listed for each intent.
Entitiesobject"boston", Type: Location::ToLocation (parent::child). "may 4", Type: builtin.datetime.date
ScorenumberConfidence score, between 0 and 1. Only the highest score is listed for each entity.
"date"string"XXXX-05-04"

Oh right, we are good but we are not done yet

On our part 2 we gonna continue by creating our Bot Connector using Microsoft Bot Framework,

Summary

You have now built a basic LUIS application. This application can be enhanced by adding more advanced features.
Original Author: 
Source: http://winstongubantes.blogspot.in/2017/02/xamarinforms-and-ai-bot-framework-with_9.html

Tags: Xamarin Forms and AI Bot Framework with LUIS




Xamarin Forms and Azure Easy Tables (as easy as 1 2 3)

Posted by seven.srikanth@gmail.com at 28 May 2018 in Article


 Overview

Hi Guys, we are about to discuss Xamarin.Forms with Azure Appservices Easy Tables, great front-end apps need great back-end and there is tons of solution or options of doing it, But today we will see how Azure has done a great job making it relatively easy for developers to connect on back-end service without coding it.

Getting Started

Now lets create a Mobile App Service in Azure Portal, Go ahead by clicking "Mobile App" as shown in a screenshot below. Now click create. Name your app accordingly, in our case we named it "conversationapp". If you have no existing resource you can create new one or you can use your existing one. Now click create. Now click "Easy Tables" in order for us to create table. You will notice that, you will need to configure your easy tables as it has detected that no database has been created for use in your easy tables. Now click the highlighted link below to create a new database. Click add to create database. Now name your database, in our example we name it "conversationdb". You can select pricing accordingly, in our case we use free since this is for testing purpose. But in production we should use a more appropriate capacity according to our app's scaling need. We also gonna need to create a server for our db, in our case we use the location "East Asia". When you are done with creating a database, you are now ready to initialize App Service to use easy tables. Now click Initialize App. Now go and create a table named "Message", we make it more simple as possible. You can create as many tables depending on your app. We can also set table relationship when it needs to, be aware to editing deleting columns created by Azure tables that might cause an issue with syncing. And that's it for the App Service.

Creating our app to Connect With Easy Tables

Now that our app service is ready to rock in roll, we can now create our app to connect with easy tables. First create a new Xamarin.Forms project and name it "ConversationApp". Create model for Message -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConversationApp.Models
{
public class Message
{
public string Id { get; set; }
public string Sender { get; set; }
public string Messagetext { get; set; }
public string UserImageUrl { get; set; }
}
- Creata ViewModel for ConversationPage and name it "ConversationPageViewModel" -
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ConversationApp.Models;
using Xamarin.Forms;
namespace ConversationApp.ViewModels
{
public class ConversationPageViewModel : INotifyPropertyChanged
{
private ObservableCollection<Message> _messages;
private string _userName;
private string _textMessage;
private ICommand _sendMessageCommand;
public event PropertyChangedEventHandler PropertyChanged;
public ConversationPageViewModel()
{
Messages = new ObservableCollection<Message>();
Messages.Add(new Message {Messagetext = "Hello", Sender = "Sender", UserImageUrl = "me_user.png"});
}
public ObservableCollection<Message> Messages
{
get { return _messages; }
set
{
_messages = value;
OnPropertyChanged("Messages");
}
}
public string UserName
{
get { return _userName; }
set
{
_userName = value;
OnPropertyChanged("UserName");
}
}
public string TextMessage
{
get { return _textMessage; }
set
{
_textMessage = value;
OnPropertyChanged("TextMessage");
}
}
public ICommand SendMessageCommand
{
get { return _sendMessageCommand = _sendMessageCommand ?? new Command(() =>
{
}); }
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
- Create a new Page and name it ConversationPage.xaml -
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewModels="clr-namespace:ConversationApp.ViewModels;assembly=ConversationApp"
x:Class="ConversationApp.Pages.ConversationPage">
<ContentPage.BindingContext>
<viewModels:ConversationPageViewModel></viewModels:ConversationPageViewModel>
</ContentPage.BindingContext>
<ContentPage.Content>
<StackLayout Orientation="Vertical"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<ListView ItemsSource="{Binding Messages}"
Margin="10"
HasUnevenRows="True"
IsPullToRefreshEnabled="True"
IsRefreshing="{Binding IsRefreshing }">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Orientation="Horizontal">
<Image Source="{Binding UserImageUrl}"></Image>
<StackLayout Orientation="Vertical">
<Label Text="{Binding Messagetext, StringFormat='Message: {0}'}"></Label>
<Label Text="{Binding Sender, StringFormat='Sender: {0}'}"></Label>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout VerticalOptions="End" HorizontalOptions="FillAndExpand">
<Entry Placeholder="Please enter you name.." Text="{Binding UserName}"></Entry>
<Entry Placeholder="Please enter message.." Text="{Binding TextMessage}"></Entry>
<Button Text="Send" Command="{Binding SendMessageCommand}"></Button>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
view raw ConversationPage.cs hosted with ❤ by GitHub
- Now create our AzureService client class to make a sync calls to our easy tables, but before that, we will need to install nuget packages for MobileServiceClient in our PCL and Platform projects as shown below.

Initialize the Azure Mobile Client

Add the Azure Mobile Client SDK initialization code in the platform projects. For iOS, the following code must be added to the FinishedLaunching method of the AppDelegate class:
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init(); SQLitePCL.CurrentPlatform.Init(); For Android, add the following to the OnCreate method of your MainActivity: Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init(); We will now create AzureDataService , the following are the code -
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConversationApp.Models;
using Microsoft.WindowsAzure.MobileServices;
using Microsoft.WindowsAzure.MobileServices.SQLiteStore;
using Microsoft.WindowsAzure.MobileServices.Sync;
namespace ConversationApp.Services
{
public class AzureDataService
{
private MobileServiceClient _mobileServiceClient = new MobileServiceClient("http://conversationapp.azurewebsites.net");
IMobileServiceSyncTable<Message> _messageTable;
public async Task Initialize()
{
if (_mobileServiceClient?.SyncContext?.IsInitialized ?? false)
return;
const string path = "syncstore.db";
//setup our local sqlite store and intialize our table
var store = new MobileServiceSQLiteStore(path);
store.DefineTable<Message>();
await _mobileServiceClient.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
//Get our sync table that will call out to azure
_messageTable = _mobileServiceClient.GetSyncTable<Message>();
}
public async Task<IEnumerable<Message>> GetMessages()
{
await Initialize();
await SyncMessage();
return await _messageTable.ToEnumerableAsync();
}
public async Task AddMessage(Message msg)
{
await Initialize();
await _messageTable.InsertAsync(msg);
await SyncMessage();
}
public async Task SyncMessage()
{
try
{
await _messageTable.PullAsync("allMessage", _messageTable.CreateQuery());
await _mobileServiceClient.SyncContext.PushAsync();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
- We will now be able to run our Xamarin project, please make sure to make platform project as a startup. It should look like this. You should be able to see the data you sync in Azure Easy Tables, without a sweat :D Please check the full source code here.

Wrapping Up

Azure App Services provides more flexibility for mobile development integrating Authentication, Notification and that what makes it a developer centric tool. To learn more of this please check our Xamarin Blog  https://blog.xamarin.com . Please dont hesitate to leave a message if you have clarification or question. Thats all.
Original Author: 
Source: http://winstongubantes.blogspot.in/2017/02/xamarinforms-and-azure-easy-tables-as.html

Tags: Xamarin Forms and Azure Easy Tables (as easy as 1 2 3)




Xamarin Forms Creating Your Own Custom Dialog

Posted by seven.srikanth@gmail.com at 28 May 2018 in Article


 Overview

Sometimes the existing dialogs from Xamarin.forms does not conforms to what we need like custom dialog which contains some entry and ok cancel button or perhaps a listview inside a dialog that may contain complex UI, existing libraries like in this link and acr dialog doesnt give us what exactly we want in a dialog. And worst we will resort with custom renderers to achieve this. So i made a custom dialog made purely in xaml without custom renderer. Yes you read it right its pure xaml, you can check the full source code here.

How to use

Just copy the source implementation of PopUpDialogView just like you see in the screen below, you can customize it to conform with your design Or may add another animation transition during show and hide. Adding PopUpDialogView in your page is simple, you will  need to add a Grid Layout without rows and columns, please take a look at the code below. -
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CustomPopupDialog"
xmlns:views="clr-namespace:CustomPopupDialog.Views;assembly=CustomPopupDialog"
x:Class="CustomPopupDialog.MainPage"
Title="Custom Dialog Test">
<ContentPage.Content>
<Grid>
<Button VerticalOptions="End" x:Name="BtnShowDialog" Text="ShowDialog"></Button>
<views:PopUpDialogView x:Name="PopUpDialog" HeaderTitle="Test Dialog">
<!--CREATE YOUR BINDABLE ELEMENTS HERE BASE FROM THE PAGES VIEW MODELS-->
<Label Text="This is a content"></Label>
</views:PopUpDialogView>
</Grid>
</ContentPage.Content>
</ContentPage>
-

Wrapping Up

You can check the full source here, For more about Xamarin.Forms you can always check their site and if you want something fresh you can check their blog. If you have questions please feel free to comment just below this article.
Original Author: 

Tags: Xamarin Forms Creating Your Own Custom Dialog