Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow choice recognizer to accept null and empty string #1333

Merged
merged 1 commit into from
Jan 29, 2019
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 @@ -17,6 +17,11 @@ public static List<ModelResult<FoundChoice>> RecognizeChoices(string utterance,

public static List<ModelResult<FoundChoice>> RecognizeChoices(string utterance, IList<Choice> list, FindChoicesOptions options = null)
{
if (utterance == null)
{
utterance = string.Empty;
}

// Try finding choices by text search first
// - We only want to use a single strategy for returning results to avoid issues where utterances
// like the "the third one" or "the red one" or "the first division book" would miss-recognize as
Expand Down
5 changes: 0 additions & 5 deletions libraries/Microsoft.Bot.Builder.Dialogs/Choices/Find.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public static List<ModelResult<FoundChoice>> FindChoices(string utterance, IList

public static List<ModelResult<FoundChoice>> FindChoices(string utterance, IList<Choice> choices, FindChoicesOptions options = null)
{
if (string.IsNullOrEmpty(utterance))
{
throw new ArgumentNullException(nameof(utterance));
}

if (choices == null)
{
throw new ArgumentNullException(nameof(choices));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ public void ShouldFindMultipleChoicesInAnUtteranceByNumerical_index()
AssertChoice(found[1], "blue", 2, 1.0f);
}

[TestMethod]
public void ShouldAcceptNullForUtterance()
{
var found = ChoiceRecognizers.RecognizeChoices(null, colorChoices);
Assert.AreEqual(0, found.Count);
}

// Helper functions

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