in docs-samples/V4/JS/contosocafebot-luis-dialogs/lib/luisbot.js [170:221]
function SaveEntities(dc, typedresult) {
return __awaiter(this, void 0, void 0, function* () {
// Resolve entities returned from LUIS, and save these to state
if (typedresult.entities) {
let datetime = typedresult.entities.datetime;
if (datetime) {
console.log(`datetime entity found of type ${datetime[0].type}.`);
// Use the first date or time found in the utterance
if (datetime[0].timex) {
var timexValues = datetime[0].timex;
// timexValues is the array of all resolutions of datetime[0]
// a datetime entity detected by LUIS is resolved to timex format.
// More information on timex can be found here:
// http://www.timeml.org/publications/timeMLdocs/timeml_1.2.1.html#timex3
// More information on the library which does the recognition can be found here:
// https://github.com/Microsoft/Recognizers-Text
if (datetime[0].type === "datetime") {
var resolution = Resolver.evaluate(
// array of timex values to evaluate. There may be more than one: "today at 6" can be 6AM or 6PM.
timexValues,
// Creator.evening constrains this to times between 4pm and 8pm
[Creator.evening]);
if (resolution[0]) {
// toNaturalLanguage takes the current date into account to create a friendly string
dc.activeDialog.state.dateTime = resolution[0].toNaturalLanguage(new Date());
// You can also use resolution.toString() to format the date/time.
}
else {
// time didn't satisfy constraint.
dc.activeDialog.state.dateTime = null;
}
}
else {
console.log(`Type ${datetime[0].type} is not yet supported. Provide both the date and the time.`);
}
}
}
let partysize = typedresult.entities.partySize;
if (partysize) {
console.log(`partysize entity detected: ${partysize}`);
// use first partySize entity that was found in utterance
dc.activeDialog.state.partySize = partysize[0];
}
let cafelocation = typedresult.entities.cafeLocation;
if (cafelocation) {
console.log(`location entity detected: ${cafelocation}`);
// use first cafeLocation entity that was found in utterance
dc.activeDialog.state.cafeLocation = cafelocation[0][0];
}
}
});
}