Skip to content

Commit 238db33

Browse files
committed
began ChoiceRecognizers class -- pending Recognizers-Numbers publishing however to cont. further
1 parent 5c37f06 commit 238db33

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

libraries/botbuilder-dialogs/botbuilder/dialogs/choices/choice_recognizers.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
from typing import List, Union
5+
6+
7+
from .choice import Choice
8+
from .find import Find
9+
from .find_choices_options import FindChoicesOptions
10+
from .found_choice import FoundChoice
11+
from .model_result import ModelResult
12+
413
class ChoiceRecognizers:
514
""" Contains methods for matching user input against a list of choices. """
615

@@ -13,3 +22,45 @@ class ChoiceRecognizers:
1322
# TS has only 1 recognizer funtion, recognizeChoices()
1423
# nested within recognizeChoices() is matchChoiceByIndex()
1524

25+
@staticmethod
26+
def recognize_choices(
27+
utterance: str,
28+
choices: List[Union[str, Choice]],
29+
options: FindChoicesOptions = None
30+
) -> ModelResult:
31+
"""
32+
Matches user input against a list of choices.
33+
34+
Parameters:
35+
-----------
36+
37+
utterance: The input.
38+
39+
choices: The list of choices.
40+
41+
options: (Optional) Options to control the recognition strategy.
42+
43+
Returns:
44+
--------
45+
A list of found choices, sorted by most relevant first.
46+
"""
47+
if utterance == None:
48+
utterance = ''
49+
50+
# Try finding choices by text search first
51+
# - We only want to use a single strategy for returning results to avoid issues where utterances
52+
# like the "the third one" or "the red one" or "the first division book" would miss-recognize as
53+
# a numerical index or ordinal as well
54+
locale = options.locale if options.locale else 'FILL IN WITH RECOGNIZERS-NUMBER (C# Recognizers.Text.Culture.English)'
55+
matched = Find.find_choices(utterance, choices, options)
56+
57+
if len(matched) == 0:
58+
# Next try finding by ordinal
59+
# matches = WRITE RecognizeOrdinal()
60+
pass
61+
62+
@staticmethod
63+
def _recognize_ordinal(utterance: str, culture: str) -> List[ModelResult]:
64+
# NEED NumberRecognizer class from recognizers-numbers
65+
pass
66+

0 commit comments

Comments
 (0)