Skip to content

Commit

Permalink
Minor fixes on number_prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
ceciliaavila committed May 15, 2019
1 parent 66d6e00 commit 06afcc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .prompt import Prompt
from .prompt_options import PromptOptions
from .prompt_recognizer_result import PromptRecognizerResult
from recognizers_date_time import recognize_datetime

class DateTimePrompt(Prompt):
def __init__(self, dialog_id: str, validator: object = None, default_locale: str = None):
Expand Down Expand Up @@ -48,10 +49,9 @@ async def on_recognize(self, turn_context: TurnContext, state: Dict[str, object]
if turn_context.activity.type == ActivityTypes.message:
# Recognize utterance
message = turn_context.activity
# TODO: English contsant needs to be ported.
# TODO: English constant needs to be ported.
culture = message.locale if message.locale != None else "English"
# TODO: Move this import to top of file when recognizers package is published
from recognizers_date_time import recognize_datetime

results = recognize_datetime(message.text, culture)
if len(results) > 0:
result.succeeded = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,57 @@
from typing import Dict
from botbuilder.core.turn_context import TurnContext
from botbuilder.schema import (ActivityTypes, Activity)
from .datetime_resolution import DateTimeResolution
from .prompt import Prompt
from .prompt_options import PromptOptions
from .prompt_recognizer_result import PromptRecognizerResult

from recognizers_number import recognize_number

class NumberPrompt(Prompt):
# TODO: PromptValidator
def __init__(self, dialog_id: str, validator: object, default_locale: str):
super(ConfirmPrompt, self).__init__(dialog_id, validator)
super(NumberPrompt, self).__init__(dialog_id, validator)
self._default_locale = default_locale

@property
def default_locale(self) -> str:
"""Gets the locale used if `TurnContext.activity.locale` is not specified.
"""Gets the locale used if `TurnContext.activity.locale` is not specified.
"""
return self._default_locale

@default_locale.setter
def default_locale(self, value: str) -> None:
"""Gets the locale used if `TurnContext.activity.locale` is not specified.
:param value: The locale used if `TurnContext.activity.locale` is not specified.
"""
self._default_locale = value


async def on_prompt(self, turn_context: TurnContext, state: Dict[str, object], options: PromptOptions, is_retry: bool):
if not turn_context:
raise TypeError('NumberPrompt.on_prompt(): turn_context cannot be None.')
if not options:
raise TypeError('NumberPrompt.on_prompt(): options cannot be None.')

if is_retry == True and options.retry_prompt != None:
prompt = turn_context.send_activity(options.retry_prompt)
prompt = turn_context.send_activity(options.retry_prompt)
else:
if options.prompt != None:
turn_context.send_activity(options.prompt)

await turn_context.send_activity(options.prompt)

async def on_recognize(self, turn_context: TurnContext, state: Dict[str, object], options: PromptOptions) -> PromptRecognizerResult:
if not turn_context:
raise TypeError('NumberPrompt.on_recognize(): turn_context cannot be None.')

result = PromptRecognizerResult()
if turn_context.activity.type == ActivityTypes.message:
message = turn_context.activity

# TODO: Fix constant English with correct constant from text recognizer
culture = turn_context.activity.locale if turn_context.activity.locale != None else 'English'
# TODO: Port ChoiceRecognizer
results = ChoiceRecognizer.recognize_number(message.text, culture)
if results.Count > 0:

results = recognize_number(message.text, culture)
if len(results) > 0:
result.succeeded = True
result.value = results[0].resolution["value"]
return result

return result

0 comments on commit 06afcc7

Please sign in to comment.