Skip to content

Commit

Permalink
Merge pull request #477 from Microsoft/chrimc
Browse files Browse the repository at this point in the history
Update IRecognizer and LUIS to support strongly typed results
  • Loading branch information
chrimc62 authored Apr 21, 2018
2 parents 1d53bb3 + b228ba9 commit 7d89262
Show file tree
Hide file tree
Showing 23 changed files with 1,002 additions and 236 deletions.
4 changes: 2 additions & 2 deletions Microsoft.Bot.Builder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ Global
{8D6F4046-0971-4E24-8E4D-F8175C6DFF2B}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
{8D6F4046-0971-4E24-8E4D-F8175C6DFF2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D6F4046-0971-4E24-8E4D-F8175C6DFF2B}.Release|Any CPU.Build.0 = Release|Any CPU
{183B3324-4CFF-477A-8EAE-73953D3E383D}.Debug - NuGet Packages|Any CPU.ActiveCfg = Debug - NuGet Packages|Any CPU
{183B3324-4CFF-477A-8EAE-73953D3E383D}.Debug - NuGet Packages|Any CPU.Build.0 = Debug - NuGet Packages|Any CPU
{183B3324-4CFF-477A-8EAE-73953D3E383D}.Debug - NuGet Packages|Any CPU.ActiveCfg = Debug|Any CPU
{183B3324-4CFF-477A-8EAE-73953D3E383D}.Debug - NuGet Packages|Any CPU.Build.0 = Debug|Any CPU
{183B3324-4CFF-477A-8EAE-73953D3E383D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{183B3324-4CFF-477A-8EAE-73953D3E383D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{183B3324-4CFF-477A-8EAE-73953D3E383D}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Bot.Builder.Ai.LUIS
{
/// <summary>
/// Type for LUIS builtin_datetime.
/// </summary>
/// <remarks>
/// LUIS recognizes time expressions like "next monday" and converts those to a type and set of timex expressions.
/// More information on timex can be found here: http://www.timeml.org/publications/timeMLdocs/timeml_1.2.1.html#timex3
/// More information on the library which does the recognition can be found here: https://github.com/Microsoft/Recognizers-Text
/// </remarks>
public class DateTimeSpec
{
/// <summary>
/// Type of expression.
/// </summary>
/// <remarks>Example types include:
/// <list type="*">
/// <item>time -- simple time expression like "3pm".</item>
/// <item>date -- simple date like "july 3rd".</item>
/// <item>datetime -- combination of date and time like "march 23 2pm".</item>
/// <item>timerange -- a range of time like "2pm to 4pm".</item>
/// <item>daterange -- a range of dates like "march 23rd to 24th".</item>
/// <item>datetimerang -- a range of dates and times like "july 3rd 2pm to 5th 4pm".</item>
/// <item>set -- a recurrence like "every monday".</item>
/// </list>
/// </remarks>
[JsonProperty("type")]
public readonly string Type;

/// <summary>
/// Timex expressions.
/// </summary>
[JsonProperty("timex")]
public readonly IList<string> Expressions;

public DateTimeSpec(string type, IEnumerable<string> expressions)
{
if (string.IsNullOrWhiteSpace(type)) throw new ArgumentNullException(nameof(type));
if (expressions == null) throw new ArgumentNullException(nameof(expressions));
Type = type;
Expressions = expressions.ToList();
}

public override string ToString()
{
return $"DateTimeSpec({Type}, [{String.Join(", ", Expressions)}]";
}
}
}
36 changes: 36 additions & 0 deletions libraries/Microsoft.Bot.Builder.Ai.LUIS/Generator/InstanceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Ai.LUIS
{
/// <summary>
/// Strongly typed information corresponding to LUIS $instance value.
/// </summary>
public class InstanceData
{
/// <summary>
/// 0-based index in the analyzed text for where entity starts.
/// </summary>
[JsonProperty("startIndex")]
public int StartIndex;

/// <summary>
/// 0-based index of the first character beyond the recognized entity.
/// </summary>
[JsonProperty("endIndex")]
public int EndIndex;

/// <summary>
/// Word broken and normalized text for the entity.
/// </summary>
[JsonProperty("text")]
public string Text;

/// <summary>
/// Optional confidence in the recognition.
/// </summary>
[JsonProperty("score")]
public double? Score;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Ai.LUIS
{
/// <summary>
/// Strongly typed class for LUIS number and unit entity recognition.
/// </summary>
/// <remarks>
/// Specific subtypes of this class are generated to match the builtin age, currency, dimension and temperature entities.
/// </remarks>
public class NumberWithUnit
{
/// <summary>
/// Recognized number, or null if unit only.
/// </summary>
[JsonProperty("number")]
public readonly double? Number;

/// <summary>
/// Normalized recognized unit.
/// </summary>
[JsonProperty("units")]
public readonly string Units;

public NumberWithUnit(double? number, string units)
{
Number = number;
Units = units;
}
}

/// <summary>
/// Strongly typed LUIS builtin_age.
/// </summary>
public class Age: NumberWithUnit
{
public Age(double number, string units) : base(number, units) { }

public override string ToString() => $"Age({Number} {Units})";
}

/// <summary>
/// Strongly typed LUIS builtin_dimension.
/// </summary>
public class Dimension: NumberWithUnit
{
public Dimension(double number, string units) : base(number, units) { }
public override string ToString() => $"Dimension({Number} {Units})";
}

/// <summary>
/// Strongly typed LUIS builtin_money.
/// </summary>
public class Money : NumberWithUnit
{
public Money(double number, string units) : base(number, units) { }
public override string ToString() => $"Currency({Number} {Units})";
}

/// <summary>
/// Strongly typed LUIS builtin_temperature.
/// </summary>
public class Temperature : NumberWithUnit
{
public Temperature(double number, string units) : base(number, units) { }
public override string ToString() => $"Temperature({Number} {Units})";
}
}
19 changes: 0 additions & 19 deletions libraries/Microsoft.Bot.Builder.Ai.LUIS/ILuisRecognizer.cs

This file was deleted.

23 changes: 0 additions & 23 deletions libraries/Microsoft.Bot.Builder.Ai.LUIS/IRecognizer.cs

This file was deleted.

Loading

0 comments on commit 7d89262

Please sign in to comment.