2017-06-04 115 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時纔看到它。這就像一個魅力! –