无法使用日期时间提示验证器验证德语日期
Unable to validate Dates in german using Datetime prompt validator
我有一个 DateResolverDialog,它接受日期和 returns 一个有效日期,如果日期被 datetime_prompt_validator 识别的话。
它适用于 default_locale,但无法识别以德语输入的日期。例如 23。 2020 年 5 月
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 Recognizers-Text 中的示例。这也会在将 Culture 参数设置为德语时出错。
错误:
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 似乎还不支持德语:https://github.com/microsoft/Recognizers-Text/issues/1689
在此期间您可以做的事情不多,但这里有一些想法:
- 在 .NET 中编写机器人
- 使用 LUIS 识别器
我有一个 DateResolverDialog,它接受日期和 returns 一个有效日期,如果日期被 datetime_prompt_validator 识别的话。
它适用于 default_locale,但无法识别以德语输入的日期。例如 23。 2020 年 5 月
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 Recognizers-Text 中的示例。这也会在将 Culture 参数设置为德语时出错。
错误:
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 似乎还不支持德语:https://github.com/microsoft/Recognizers-Text/issues/1689
在此期间您可以做的事情不多,但这里有一些想法:
- 在 .NET 中编写机器人
- 使用 LUIS 识别器