async def datetime_prompt_validator(prompt_context: PromptValidatorContext) -> bool:
        if prompt_context.recognized.succeeded:
            timex = prompt_context.recognized.value[0].timex.split("T")[0]

            return "definite" in Timex(timex).types

        return False
示例#2
0
    async def initial_step(
        self, step_context: WaterfallStepContext
    ) -> DialogTurnResult:
        """Prompt for the date."""
        timex = step_context.options

        prompt_msg = "On what date would you like to travel?"
        reprompt_msg = (
            "I'm sorry, for best results, please enter your travel "
            "date including the month, day and year."
        )

        if timex is None:
            # We were not given any date at all so prompt the user.
            return await step_context.prompt(
                DateTimePrompt.__name__,
                PromptOptions(  # pylint: disable=bad-continuation
                    prompt=MessageFactory.text(prompt_msg),
                    retry_prompt=MessageFactory.text(reprompt_msg),
                ),
            )
        else:
            # We have a Date we just need to check it is unambiguous.
            if "definite" in Timex(timex).types:
                # This is essentially a "reprompt" of the data we were given up front.
                return await step_context.prompt(
                    DateTimePrompt.__name__, PromptOptions(prompt=reprompt_msg)
                )
            else:
                return await step_context.next(DateTimeResolution(timex=timex))
    async def initial_step(
        self, step_context: WaterfallStepContext
    ) -> DialogTurnResult:
        timex = step_context.options

        prompt_msg_text = "On what date would you like to travel?"
        prompt_msg = MessageFactory.text(
            prompt_msg_text, prompt_msg_text, InputHints.expecting_input
        )

        reprompt_msg_text = "I'm sorry, for best results, please enter your travel date " \
                            "including the month, day and year."
        reprompt_msg = MessageFactory.text(
            reprompt_msg_text, reprompt_msg_text, InputHints.expecting_input
        )

        if timex is None:
            # We were not given any date at all so prompt the user.
            return await step_context.prompt(
                DateTimePrompt.__name__,
                PromptOptions(prompt=prompt_msg, retry_prompt=reprompt_msg),
            )
        # We have a Date we just need to check it is unambiguous.
        if "definite" not in Timex(timex).types:
            # This is essentially a "reprompt" of the data we were given up front.
            return await step_context.prompt(
                DateTimePrompt.__name__, PromptOptions(prompt=reprompt_msg)
            )

        return await step_context.next(DateTimeResolution(timex=timex))
示例#4
0
    async def validate_timex(travel_date: str) -> bool:
        """Validate the time.
        Make sure time given in the right format. """
        # uncomment the following line for debugging.
        # import pdb; pdb.set_trace()
        timex_property = Timex(travel_date)

        return len(timex_property.types) > 0 and "definite" not in timex_property.types
示例#5
0
    async def datetime_prompt_validator(prompt_context: PromptValidatorContext) -> bool:
        """ Validate the date provided is in proper form. """
        if prompt_context.recognized.succeeded:
            timex = prompt_context.recognized.value[0].timex.split("T")[0]

            # TODO: Needs TimexProperty
            return "definite" in Timex(timex).types

        return False
    async def datetime_prompt_validator(
            prompt_context: PromptValidatorContext) -> bool:
        if prompt_context.recognized.succeeded:
            timex = prompt_context.recognized.value[0].timex.split('T')[0]

            #TODO: Needs TimexProperty
            return 'definite' in Timex(timex).types

        return False
    async def datetime_prompt_validator(prompt_context: PromptValidatorContext) -> bool:
        if prompt_context.recognized.succeeded:
            # This value will be a TIMEX. We are only interested in the Date part, so grab the first
            # result and drop the Time part.
            # TIMEX is a format that represents DateTime expressions that include some ambiguity,
            # such as a missing Year.
            timex = prompt_context.recognized.value[0].timex.split("T")[0]

            # If this is a definite Date that includes year, month and day we are good; otherwise, reprompt.
            # A better solution might be to let the user know what part is actually missing.
            return "definite" in Timex(timex).types

        return False
示例#8
0
 def is_ambiguous(self, timex: str) -> bool:
     timex_property = Timex(timex)
     return "definite" not in timex_property.types
 def is_ambiguous(self, timex: str) -> bool:
     """Ensure time is correct."""
     timex_property = Timex(timex)
     return 'definite' not in timex_property.types