无法使用日期时间提示验证器验证德文中的日期。

问题描述 投票:1回答:1

我有一个DateResolverDialog,如果Date被datetime_prompt_validator识别,它就会接收日期并返回一个有效的日期。

它在使用default_locale时工作得很好,但不能识别以德语输入的日期。例如 23. Mai 2020

class DateResolverDialog(CancelAndHelpDialog):
def __init__(self, dialog_id: str = None):
    super(DateResolverDialog, self).__init__(
        dialog_id or DateResolverDialog.__name__
    )

    self.add_dialog(
        DateTimePrompt(
            DateTimePrompt.__name__, DateResolverDialog.datetime_prompt_validator
        )
    )
    self.add_dialog(
        WaterfallDialog(
            WaterfallDialog.__name__ + "2", [self.initial_step, self.final_step]
        )
    )

    self.initial_dialog_id = WaterfallDialog.__name__ + "2"
    self.name = ""

async def initial_step(
    self, step_context: WaterfallStepContext
) -> DialogTurnResult:
    timex= None
    self.name = step_context.options



    prompt_msg_text = key.query_date_text.value if self.name is 'createtask' else key.query_appointment_date_text
    prompt_msg = MessageFactory.text(
    prompt_msg_text, prompt_msg_text, InputHints.expecting_input
    )

    reprompt_msg_text = key.date_format_text.value
    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),
        )
    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))

async def final_step(self, step_context: WaterfallStepContext):
    timex = step_context.result[0].timex
    print(timex)
    if (timex < str(date.today())):
        await step_context.context.send_activity(
            MessageFactory.text(key.date_error_text.value))
        return await step_context.replace_dialog(dialog_id=self.id,options = self.name)
    else:
        return await step_context.end_dialog(timex)

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

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

    return False

另外,似乎不支持德国文化,因为当它试图设定 default_locale = Culture.German

文化的语言有:{中文、荷兰语、英语、法语、意大利语、日语、韩语、葡萄牙语、西班牙语、土耳其语}。

我也试过使用Recognizers-Text中的样本。识别器-文本. 在将文化参数设置为德语时也会出现错误。

错误。

Traceback (most recent call last):
File "recognizer.py", line 7, in <module>
DEFAULT_CULTURE = Culture.German
AttributeError: type object 'Culture' has no attribute 'German'.

我错过了什么吗?

python-3.x botframework
1个回答
2
投票

看来Python还不支持德语。https:/github.commicrosoftRecognizers-Textissues1689。

在此期间,你可以做的事情不多,但这里有一些想法。

  1. 用.NET编写机器人
  2. 使用LUIS识别器
© www.soinside.com 2019 - 2024. All rights reserved.