-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #477 from Microsoft/chrimc
Update IRecognizer and LUIS to support strongly typed results
- Loading branch information
Showing
23 changed files
with
1,002 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
libraries/Microsoft.Bot.Builder.Ai.LUIS/Generator/DateTimeExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
libraries/Microsoft.Bot.Builder.Ai.LUIS/Generator/InstanceData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
libraries/Microsoft.Bot.Builder.Ai.LUIS/Generator/NumberWithUnit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
libraries/Microsoft.Bot.Builder.Ai.LUIS/ILuisRecognizer.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.