2017-06-04 111 views
1

在LUIS Sdk或Bot Sdk中是否有内置的帮助方法将LUIS DatetimeV2实体转换为JS Date对象?我已经看到一些已经使用C#的慢速解析器,但我找不到任何适用于Nodejs的东西。将LUIS Datetime V2转换为JS日期

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. 
} 

回答

1

要提取datetimeV2实体的NodeJS,它是在更具体的你需要运行:

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']); 
+1

感谢。我不知道'IEntity'类型中有'resolution'属性。只是在对整个dt对象进行stringify时才看到它。这就像一个魅力! –