This commit is contained in:
Ahmed Elhinidy 2016-08-23 17:32:22 +02:00
Родитель 4f46f1be24
Коммит 9088efb1ce
4 изменённых файлов: 73 добавлений и 22 удалений

Просмотреть файл

@ -135,12 +135,8 @@ namespace Microsoft.Cognitive.LUIS
}
var entities = (JArray)result["entities"] ?? new JArray();
Entities = ParseEntityArrayToDictionary(entities);
if (result["compositeEntities"] != null)
{
var compositeEntities = (JArray)result["compositeEntities"] ?? new JArray();
CompositeEntities = ParseCompositeEntityArrayToDictionary(compositeEntities);
}
var compositeEntities = (JArray)result["compositeEntities"] ?? new JArray();
CompositeEntities = ParseCompositeEntityArrayToDictionary(compositeEntities);
}
/// <summary>

Просмотреть файл

@ -49,6 +49,7 @@ namespace Sample
{
new Scenario { Title = "Scenario 1: Make a prediction", PageClass=typeof(MakePredictionPage)}
};
_scenariosControl.Disclaimer = "Microsoft will receive the uploaded text and may use it to improve LUIS and related services. By submitting the text, you confirm that you consent.";
}
public string SubscriptionKey
@ -58,5 +59,10 @@ namespace Sample
return _scenariosControl.SubscriptionKey;
}
}
public void Log(string logMessage)
{
_scenariosControl.Log(logMessage);
}
}
}

Просмотреть файл

@ -4,16 +4,61 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Sample"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="MakePredictionPage">
mc:Ignorable="d" d:DesignWidth="300"
Title="MakePredictionPage" Height="403">
<Grid>
<TextBox x:Name="txtAppId" HorizontalAlignment="Left" Height="23" Margin="28,30,0,0" TextWrapping="Wrap" Text="Enter your App Id" VerticalAlignment="Top" Width="234"/>
<TextBox x:Name="txtPredict" HorizontalAlignment="Left" Height="23" Margin="28,73,0,0" TextWrapping="Wrap" Text="Enter the text to predict" VerticalAlignment="Top" Width="234"/>
<TextBox x:Name="txtAppId" HorizontalAlignment="Left" Height="23" Margin="28,30,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="234" ToolTip="">
<TextBox.Style>
<Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Style.Resources>
<VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None">
<VisualBrush.Visual>
<Label Content="Enter your Application Id" Foreground="DarkGray" />
</VisualBrush.Visual>
</VisualBrush>
</Style.Resources>
<Style.Triggers>
<Trigger Property="Text" Value="{x:Static sys:String.Empty}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<TextBox x:Name="txtPredict" HorizontalAlignment="Left" Height="23" Margin="28,73,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="234">
<TextBox.Style>
<Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Style.Resources>
<VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None">
<VisualBrush.Visual>
<Label Content="Enter the text to predict" Foreground="DarkGray" />
</VisualBrush.Visual>
</VisualBrush>
</Style.Resources>
<Style.Triggers>
<Trigger Property="Text" Value="{x:Static sys:String.Empty}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Button x:Name="btnPredict" Content="Predict" HorizontalAlignment="Left" Margin="28,130,0,0" VerticalAlignment="Top" Width="75" Click="btnPredict_Click"/>
<Button x:Name="btnReply" Content="Reply" HorizontalAlignment="Left" Margin="187,130,0,0" VerticalAlignment="Top" Width="75" Click="btnReply_Click"/>
<TextBlock x:Name="txtBlockResMsg" HorizontalAlignment="Left" Margin="28,173,0,0" TextWrapping="Wrap" VerticalAlignment="Top"/>
<Label x:Name="queryLabel" Content="Query:" HorizontalAlignment="Left" Margin="28,170,0,0" VerticalAlignment="Top" FontWeight="Bold"/>
<TextBlock x:Name="queryTextBlock" HorizontalAlignment="Left" Margin="81,175,0,0" TextWrapping="Wrap" VerticalAlignment="Top"/>
<Label x:Name="topIntentLabel" Content="Top Intent:" HorizontalAlignment="Left" Margin="28,200,0,0" VerticalAlignment="Top" FontWeight="Bold"/>
<TextBlock x:Name="topIntentTextBlock" HorizontalAlignment="Left" Margin="104,205,0,0" TextWrapping="Wrap" VerticalAlignment="Top"/>
<Label x:Name="dialogLabel" Content="Dialog:" HorizontalAlignment="Left" Margin="28,230,0,0" VerticalAlignment="Top" FontWeight="Bold"/>
<TextBlock x:Name="dialogTextBlock" HorizontalAlignment="Left" Margin="83,235,0,0" TextWrapping="Wrap" VerticalAlignment="Top"/>
<Label x:Name="entitiesLabel" Content="Entities:" HorizontalAlignment="Left" Margin="28,260,0,0" VerticalAlignment="Top" FontWeight="Bold"/>
<ListBox x:Name="entitiesListBox" HorizontalAlignment="Left" Height="85" Margin="34,286,0,0" VerticalAlignment="Top" Width="190"/>
</Grid>
</Page>

Просмотреть файл

@ -34,6 +34,8 @@
using System.Windows;
using System.Windows.Controls;
using System.Threading.Tasks;
using System.Collections.Generic;
using SampleUserControlLibrary;
using Microsoft.Cognitive.LUIS;
namespace Sample
@ -60,7 +62,7 @@ namespace Sample
if (prevResult == null || (prevResult.DialogResponse != null
&& prevResult.DialogResponse.Status == "Finished"))
{
txtBlockResMsg.Text = "Nothing to reply to!";
((MainWindow)Application.Current.MainWindow).Log("There is nothing to reply to.");
return;
}
Reply();
@ -75,6 +77,7 @@ namespace Sample
LuisClient client = new LuisClient(_appId, _subscriptionKey, _preview);
LuisResult res = await client.Predict(_textToPredict);
processRes(res);
((MainWindow)Application.Current.MainWindow).Log("Predicted successfully.");
}
public async Task Reply()
@ -86,32 +89,33 @@ namespace Sample
LuisClient client = new LuisClient(_appId, _subscriptionKey, _preview);
LuisResult res = await client.Reply(prevResult, _textToPredict);
processRes(res);
((MainWindow)Application.Current.MainWindow).Log("Replied successfully.");
}
private void processRes(LuisResult res)
{
txtPredict.Text = "";
prevResult = res;
string resMsg = res.OriginalQuery;
resMsg += "\nTop Intent: " + res.TopScoringIntent.Name;
resMsg += "\nEntities:";
queryTextBlock.Text = res.OriginalQuery;
topIntentTextBlock.Text = res.TopScoringIntent.Name;
List<string> entitiesNames = new List<string>();
var entities = res.GetAllEntities();
for (int i = 0; i < entities.Count; i++)
foreach(Entity entity in entities)
{
resMsg += "\n" + entities[i].Name;
entitiesNames.Add(entity.Name);
}
entitiesListBox.ItemsSource = entitiesNames;
if (res.DialogResponse != null)
{
if (res.DialogResponse.Status != "Finished")
{
resMsg += "\nDialog Prompt: " + res.DialogResponse.Prompt;
dialogTextBlock.Text = res.DialogResponse.Prompt;
}
else
{
resMsg += "\nFinished";
dialogTextBlock.Text = "Finished";
}
}
txtBlockResMsg.Text = resMsg;
}
}
}