How to use the @microsoft/recognizers-text-data-types-timex-expression.resolver.evaluate function in @microsoft/recognizers-text-data-types-timex-expression

To help you get started, we’ve selected a few @microsoft/recognizers-text-data-types-timex-expression examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 51.cafe-bot / dialogs / shared / stateProperties / reservationProperty.js View on Github external
let lDate = new Date(`${ parsedTimex.year }-${ parsedTimex.month }-${ parsedTimex.dayOfMonth }`);
                returnResult.newReservation.date = new Date(lDate.getTime() - (lDate.getTimezoneOffset() * 60000))
                    .toISOString()
                    .split('T')[0];
                returnResult.newReservation.dateLGString = new TimexProperty(returnResult.newReservation.date).toNaturalLanguage(today);
                const validDate = resolver.evaluate(dateTimeEntity.entityValue[0].timex, reservationDateConstraints);
                if (!validDate || (validDate.length === 0)) {
                    // Validation failed!
                    returnResult.outcome.push(new ReservationOutcome(`Sorry. ${ returnResult.newReservation.dateLGString } does not work. I can only make reservations for the next 4 weeks.`, DATE_TIME_ENTITY));
                    returnResult.newReservation.date = '';
                    returnResult.status = reservationStatus.INCOMPLETE;
                }
            }
            // see if the time meets our constraints
            if (parsedTimex.hour !== undefined && parsedTimex.minute !== undefined && parsedTimex.second !== undefined) {
                const validtime = resolver.evaluate(dateTimeEntity.entityValue[0].timex, reservationTimeConstraints);

                returnResult.newReservation.time = ((parseInt(parsedTimex.hour) < 10) ? '0' + parsedTimex.hour : parsedTimex.hour);
                returnResult.newReservation.time += ':';
                returnResult.newReservation.time += ((parseInt(parsedTimex.minute) < 10) ? '0' + parsedTimex.minute : parsedTimex.minute);
                returnResult.newReservation.time += ':';
                returnResult.newReservation.time += ((parseInt(parsedTimex.second) < 10) ? '0' + parsedTimex.second : parsedTimex.second);

                if (!validtime || (validtime.length === 0)) {
                    // Validation failed!
                    returnResult.outcome.push(new ReservationOutcome(`Sorry, that time does not work. I can only make reservations that are in the daytime (6AM - 6PM)`, DATE_TIME_ENTITY));
                    returnResult.newReservation.time = '';
                    returnResult.status = reservationStatus.INCOMPLETE;
                }
            }
            // Get date time LG string if we have both date and time
            if (returnResult.newReservation.date !== '' && returnResult.newReservation.time !== '') {
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 40.timex-resolution / constraints.js View on Github external
module.exports.examples = () => {
    // When you give the recognzier the text "Wednesday 4 o'clock" you get these distinct TIMEX values back.
    // But our bot logic knows that whatever the user says it should be evaluated against the constraints of
    // a week from today with respect to the date part and in the evening with respect to the time part.
    const resolutions = resolver.evaluate(
        ['XXXX-WXX-3T04', 'XXXX-WXX-3T16'],
        [creator.weekFromToday(), creator.evening]
    );

    const today = new Date();

    resolutions.forEach(resolution => {
        console.log(resolution.toNaturalLanguage(today));
    });
};
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 51.cafe-bot / dialogs / shared / stateProperties / reservationProperty.js View on Github external
if (dateTimeEntity !== undefined) {
        // Get parsed date time from TIMEX
        // LUIS returns a timex expression and so get and un-wrap that.
        // Take the first date time since book table scenario does not have to deal with multiple date times or date time ranges.
        if (dateTimeEntity.entityValue[0].timex && dateTimeEntity.entityValue[0].timex[0]) {
            let today = new Date();
            let parsedTimex = new TimexProperty(dateTimeEntity.entityValue[0].timex[0]);
            // see if the date meets our constraints
            if (parsedTimex.dayOfMonth !== undefined && parsedTimex.year !== undefined && parsedTimex.month !== undefined) {
                let lDate = new Date(`${ parsedTimex.year }-${ parsedTimex.month }-${ parsedTimex.dayOfMonth }`);
                returnResult.newReservation.date = new Date(lDate.getTime() - (lDate.getTimezoneOffset() * 60000))
                    .toISOString()
                    .split('T')[0];
                returnResult.newReservation.dateLGString = new TimexProperty(returnResult.newReservation.date).toNaturalLanguage(today);
                const validDate = resolver.evaluate(dateTimeEntity.entityValue[0].timex, reservationDateConstraints);
                if (!validDate || (validDate.length === 0)) {
                    // Validation failed!
                    returnResult.outcome.push(new ReservationOutcome(`Sorry. ${ returnResult.newReservation.dateLGString } does not work. I can only make reservations for the next 4 weeks.`, DATE_TIME_ENTITY));
                    returnResult.newReservation.date = '';
                    returnResult.status = reservationStatus.INCOMPLETE;
                }
            }
            // see if the time meets our constraints
            if (parsedTimex.hour !== undefined && parsedTimex.minute !== undefined && parsedTimex.second !== undefined) {
                const validtime = resolver.evaluate(dateTimeEntity.entityValue[0].timex, reservationTimeConstraints);

                returnResult.newReservation.time = ((parseInt(parsedTimex.hour) < 10) ? '0' + parsedTimex.hour : parsedTimex.hour);
                returnResult.newReservation.time += ':';
                returnResult.newReservation.time += ((parseInt(parsedTimex.minute) < 10) ? '0' + parsedTimex.minute : parsedTimex.minute);
                returnResult.newReservation.time += ':';
                returnResult.newReservation.time += ((parseInt(parsedTimex.second) < 10) ? '0' + parsedTimex.second : parsedTimex.second);