将 LUIS Datetime V2 转换为 JS 日期

Convert LUIS Datetime V2 to JS Date

LUIS Sdk 或 Bot Sdk 中是否有内置辅助方法将 LUIS DatetimeV2 实体转换为 JS Date 对象?我看到有些人一直在使用 C# 的 Chronic Parser,但我找不到任何适用于 Nodejs 的东西。

const dt = builder.EntityRecognizer.findEntity(args.intent.entities, 'datetimeV2');
if (dt) {
    // this is just the matching intent, I believe.
    // example intents; today, yesterday, 2/28, 31/5, ...
    // How do I convert this to a valid Date is where I am stuck.
}

要在 NodeJS 中提取 datetimeV2 个实体,更具体的是您需要 运行:

const dt = builder.EntityRecognizer.findEntity(args.intent.entities,
    'builtin.datetimeV2.date'); 

const dt_daterange = builder.EntityRecognizer.findEntity(args.intent.entities, 
    'builtin.datetimeV2.daterange');

要创建 Date 对象,您可以在 MDN 上查找。

这是 datetimeV2 上的 blogpost,它显示了 LUIS 响应对象中实体的结构。

要创建 Date 对象,您可以将 dt.resolution.values[i]['value'] 放入构造函数中,如下所示:

const dt_obj = new Date(dt.resolution.values[i]['value']);