Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@ public static List<ModelResult<FoundChoice>> RecognizeChoices(string utterance,
var matched = Find.FindChoices(utterance, list, options);
if (matched.Count == 0)
{
// Next try finding by ordinal
var matches = RecognizeNumbers(utterance, locale, new NumberRecognizer(locale, NumberOptions.SuppressExtendedTypes).GetOrdinalModel(locale));
if (matches.Any())
var matches = new List<ModelResult<FoundChoice>>();
if (options == null || options.RecognizeOrdinals)
{
// Next try finding by ordinal
matches = RecognizeNumbers(utterance, locale, new NumberRecognizer(locale, NumberOptions.SuppressExtendedTypes).GetOrdinalModel(locale));
foreach (var match in matches)
{
MatchChoiceByIndex(list, matched, match);
}
}
else

if (matches.Count == 0 && (options == null || options.RecognizeNumbers))
{
// Then try by numerical index
matches = RecognizeNumbers(utterance, locale, new NumberRecognizer(locale, NumberOptions.SuppressExtendedTypes).GetNumberModel(locale));

foreach (var match in matches)
{
MatchChoiceByIndex(list, matched, match);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,25 @@ public class FindChoicesOptions : FindValuesOptions
/// </value>
[JsonProperty("noAction")]
public bool NoAction { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the recognizer should check for Numbers using the NumberRecognizer's
/// NumberModel.
/// </summary>
/// <value>
/// Default is <c>true</c>. If <c>false</c>, the Number Model will not be used to check the utterance for numbers.
/// </value>
[JsonProperty("recognizeNumbers")]
public bool RecognizeNumbers { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether the recognizer should check for Ordinal Numbers using the NumberRecognizer's
/// OrdinalModel.
/// </summary>
/// <value>
/// Default is <c>true</c>. If <c>false</c>, the Ordinal Model will not be used to check the utterance for ordinal numbers.
/// </value>
[JsonProperty("recognizeOrdinals")]
public bool RecognizeOrdinals { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ public void ShouldAcceptNullUtteranceInRecognizeChoices()
Assert.AreEqual(0, found.Count);
}

[TestMethod]
public void ShouldNOTFindAChoiceInAnUtteranceByOrdinalPosition_RecognizeOrdinalsFalseAndRecognizeNumbersFalse()
{
var found = ChoiceRecognizers.RecognizeChoices("the first one please.", colorChoices, new FindChoicesOptions() { RecognizeOrdinals = false, RecognizeNumbers = false });
Assert.AreEqual(0, found.Count);
}

[TestMethod]
public void ShouldNOTFindAChoiceInAnUtteranceByNumericalIndex_Text_RecognizeNumbersFalse()
{
var found = ChoiceRecognizers.RecognizeChoices("one", colorChoices, new FindChoicesOptions() { RecognizeNumbers = false });
Assert.AreEqual(0, found.Count);
}

// Helper functions
private static void AssertResult<T>(ModelResult<T> result, int start, int end, string text)
{
Expand Down