Skip to content

Commit

Permalink
[CSharp-LUIS] Update to Microsoft.Bot.Builder v3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ejadib authored Jan 6, 2017
1 parent a3f6f89 commit 7be7985
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 71 deletions.
8 changes: 4 additions & 4 deletions CSharp/intelligence-LUIS/Controllers/MessagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
using System.Web.Configuration;
using System.Web.Http;
using Dialogs;
using Services;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using Services;

[BotAuthentication]
public class MessagesController : ApiController
{
private readonly BingSpellCheckService spellService = new BingSpellCheckService();
private static readonly bool IsSpellCorrectionEnabled = bool.Parse(WebConfigurationManager.AppSettings["IsSpellCorrectionEnabled"]);

private static readonly bool IsSpellCorrectionEnabled = Boolean.Parse(WebConfigurationManager.AppSettings["IsSpellCorrectionEnabled"]);
private readonly BingSpellCheckService spellService = new BingSpellCheckService();

/// <summary>
/// POST: api/Messages
Expand All @@ -33,7 +33,7 @@ public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
activity.Text = await this.spellService.GetCorrectedTextAsync(activity.Text);
}
catch(Exception ex)
catch (Exception ex)
{
Trace.TraceError(ex.ToString());
}
Expand Down
3 changes: 1 addition & 2 deletions CSharp/intelligence-LUIS/Dialogs/RootLuisDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public async Task None(IDialogContext context, LuisResult result)
[LuisIntent("SearchHotels")]
public async Task Search(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{

var message = await activity;
await context.PostAsync($"Welcome to the Hotels finder! we are analyzing your message: '{message.Text}'...");
await context.PostAsync($"Welcome to the Hotels finder! We are analyzing your message: '{message.Text}'...");

var hotelsQuery = new HotelsQuery();

Expand Down
31 changes: 17 additions & 14 deletions CSharp/intelligence-LUIS/LuisBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,42 +42,42 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>packages\Autofac.3.5.2\lib\net40\Autofac.dll</HintPath>
<Reference Include="Autofac, Version=4.2.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>packages\Autofac.4.2.1\lib\net45\Autofac.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Chronic, Version=0.3.2.0, Culture=neutral, PublicKeyToken=3bd1f1ef638b0d3c, processorArchitecture=MSIL">
<HintPath>packages\Chronic.Signed.0.3.2\lib\net40\Chronic.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Builder, Version=3.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.2.1\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Reference Include="Microsoft.Bot.Builder, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.5.0\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Connector, Version=3.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.2.1\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Reference Include="Microsoft.Bot.Connector, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.5.0\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.2.33, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.3.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.3.308261200\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Rest.ClientRuntime.2.3.2\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<HintPath>packages\Microsoft.Rest.ClientRuntime.2.3.4\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.1\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
<HintPath>packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.20622.1351, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.30826.1200, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\System.IdentityModel.Tokens.Jwt.4.0.3.308261200\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net" />
Expand Down Expand Up @@ -128,8 +128,11 @@
<Compile Include="Hotel.cs" />
<Compile Include="HotelsQuery.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\BingSpellCheckError.cs" />
<Compile Include="Services\BingSpellCheckFlaggedToken.cs" />
<Compile Include="Services\BingSpellCheckResponse.cs" />
<Compile Include="Services\BingSpellCheckService.cs" />
<Compile Include="Services\BingSpellCheckSuggestion.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="packages.config" />
Expand Down
1 change: 1 addition & 0 deletions CSharp/intelligence-LUIS/LuisBot.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
}
],
"composites": [],
"closedLists": [],
"bing_entities": [
"geography"
],
Expand Down
8 changes: 5 additions & 3 deletions CSharp/intelligence-LUIS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A sample bot using LuisDialog to integrate with a LUIS.ai application.

The minimum prerequisites to run this sample are:
* The latest update of Visual Studio 2015. You can download the community version [here](http://www.visualstudio.com) for free.
* The Bot Framework Emulator. To install the Bot Framework Emulator, download it from [here](https://aka.ms/bf-bc-emulator). Please refer to [this documentation article](https://docs.botframework.com/en-us/csharp/builder/sdkreference/gettingstarted.html#emulator) to know more about the Bot Framework Emulator.
* The Bot Framework Emulator. To install the Bot Framework Emulator, download it from [here](https://emulator.botframework.com/). Please refer to [this documentation article](https://github.com/microsoft/botframework-emulator/wiki/Getting-Started) to know more about the Bot Framework Emulator.


#### LUIS Application
Expand Down Expand Up @@ -42,11 +42,13 @@ Finally, edit the [RootLuisDialog.cs](Dialogs/RootLuisDialog.cs#L20) file and up
You'll need these two values to configure the LuisDialog through the LuisModel attribute:

1. Application ID
In the LUIS application's dashboard, select the App Settings option in the right side bar and copy the App ID field value.

In the LUIS application's dashboard, select the _App Settings_ option in the right side bar and copy the App ID field value.

![App Settings](images/prereqs-appid.png)

2. Subscription Key

In the [user's settings page](https://www.luis.ai/Home/UserSettings), select the _Subscription Keys_ option and copy the Programmatic API Key.

![Programmatic API Key](images/prereqs-apikey.png)
Expand Down Expand Up @@ -93,7 +95,7 @@ Another LUIS Model Feature used is Phrase List Features, for instance, the model

### Spelling Correction

If you want to enable spelling correction, set the `IsSpellCorrectionEnabled` key to `true` in the [web.config](web.config) file.
If you want to enable spelling correction, set the `IsSpellCorrectionEnabled` key to `true` in the [Web.config](Web.config) file.

Bing Spell Check API provides a module that allows you to to correct the spelling of the text. Check out the [reference](https://dev.cognitive.microsoft.com/docs/services/56e73033cf5ff80c2008c679/operations/56e73036cf5ff81048ee6727) to know more about the modules available.

Expand Down
9 changes: 9 additions & 0 deletions CSharp/intelligence-LUIS/Services/BingSpellCheckError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace LuisBot.Services
{
public class BingSpellCheckError
{
public int StatusCode { get; set; }

public string Message { get; set; }
}
}
13 changes: 13 additions & 0 deletions CSharp/intelligence-LUIS/Services/BingSpellCheckFlaggedToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace LuisBot.Services
{
public class BingSpellCheckFlaggedToken
{
public int Offset { get; set; }

public string Token { get; set; }

public string Type { get; set; }

public BingSpellCheckSuggestion[] Suggestions { get; set; }
}
}
29 changes: 6 additions & 23 deletions CSharp/intelligence-LUIS/Services/BingSpellCheckResponse.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
namespace LuisBot.Services
{
public class BingSpellCheckResponse
{
public string _type { get; set; }

public Flaggedtoken[] flaggedTokens { get; set; }

public Error error { get; set; }
}
using Newtonsoft.Json;

public class Flaggedtoken
public class BingSpellCheckResponse
{
public int offset { get; set; }
public string token { get; set; }
public string type { get; set; }
public Suggestion[] suggestions { get; set; }
}
[JsonProperty("_type")]
public string Type { get; set; }

public class Suggestion
{
public string suggestion { get; set; }
public int score { get; set; }
}
public BingSpellCheckFlaggedToken[] FlaggedTokens { get; set; }

public class Error
{
public int statusCode { get; set; }
public string message { get; set; }
public BingSpellCheckError Error { get; set; }
}
}
34 changes: 17 additions & 17 deletions CSharp/intelligence-LUIS/Services/BingSpellCheckService.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Configuration;
using Newtonsoft.Json;

namespace LuisBot.Services
namespace LuisBot.Services
{
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Configuration;
using Newtonsoft.Json;

public class BingSpellCheckService
{
/// <summary>
/// Microsoft Bing Spell Check Api Key.
/// The Bing Spell Check Api Url.
/// </summary>
private static readonly string ApiKey = WebConfigurationManager.AppSettings["BingSpellCheckApiKey"];
private const string SpellCheckApiUrl = "https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?form=BCSSCK";

/// <summary>
/// The Bing Spell Check Api Url.
/// Microsoft Bing Spell Check Api Key.
/// </summary>
private const string SpellCheckApiUrl = "https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?form=BCSSCK";
private static readonly string ApiKey = WebConfigurationManager.AppSettings["BingSpellCheckApiKey"];

/// <summary>
/// Gets the correct spelling for the given text
Expand Down Expand Up @@ -51,16 +51,16 @@ public async Task<string> GetCorrectedTextAsync(string text)
StringBuilder sb = new StringBuilder();
int previousOffset = 0;

foreach (var flaggedToken in spellCheckResponse.flaggedTokens)
foreach (var flaggedToken in spellCheckResponse.FlaggedTokens)
{
// Append the text from the previous offset to the current misspelled word offset
sb.Append(text.Substring(previousOffset, flaggedToken.offset - previousOffset));
sb.Append(text.Substring(previousOffset, flaggedToken.Offset - previousOffset));

// Append the corrected word instead of the misspelled word
sb.Append(flaggedToken.suggestions.First().suggestion);
sb.Append(flaggedToken.Suggestions.First().Suggestion);

// Increment the offset by the length of the misspelled word
previousOffset = flaggedToken.offset + flaggedToken.token.Length;
previousOffset = flaggedToken.Offset + flaggedToken.Token.Length;
}

// Append the text after the last misspelled word.
Expand Down
9 changes: 9 additions & 0 deletions CSharp/intelligence-LUIS/Services/BingSpellCheckSuggestion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace LuisBot.Services
{
public class BingSpellCheckSuggestion
{
public string Suggestion { get; set; }

public double Score { get; set; }
}
}
14 changes: 13 additions & 1 deletion CSharp/intelligence-LUIS/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
Expand All @@ -74,6 +74,18 @@
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.30826.1200" newVersion="4.0.30826.1200" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Protocol.Extensions" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.3.42" newVersion="1.0.3.42" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
14 changes: 7 additions & 7 deletions CSharp/intelligence-LUIS/packages.config
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.5.2" targetFramework="net46" />
<package id="Autofac" version="4.2.1" targetFramework="net46" />
<package id="Chronic.Signed" version="0.3.2" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.2.1" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.2.206221351" targetFramework="net46" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net46" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.1" targetFramework="net46" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.5.0" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.3.308261200" targetFramework="net46" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.4" targetFramework="net46" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.3" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.3.308261200" targetFramework="net46" />
</packages>

0 comments on commit 7be7985

Please sign in to comment.