How to use the @microsoft/recognizers-text-number.recognizeNumber function in @microsoft/recognizers-text-number

To help you get started, we’ve selected a few @microsoft/recognizers-text-number 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-js / libraries / botbuilder-dialogs / lib / choices / recognizeChoices.js View on Github external
const list = (choices || []).map((choice, index) => typeof choice === 'string' ? { value: choice } : choice).filter((choice) => choice);
    // Try finding choices by text search first
    // - We only want to use a single strategy for returning results to avoid issues where utterances 
    //   like the "the third one" or "the red one" or "the first division book" would miss-recognize as 
    //   a numerical index or ordinal as well.
    const locale = options && options.locale ? options.locale : 'en-us';
    let matched = findChoices_1.findChoices(utterance, list, options);
    if (matched.length === 0) {
        // Next try finding by ordinal
        const ordinals = Recognizers.recognizeOrdinal(utterance, locale);
        if (ordinals.length > 0) {
            ordinals.forEach(matchChoiceByIndex);
        }
        else {
            // Finally try by numerical index
            Recognizers.recognizeNumber(utterance, locale).forEach(matchChoiceByIndex);
        }
        // Sort any found matches by their position within the utterance.
        // - The results from findChoices() are already properly sorted so we just need this
        //   for ordinal & numerical lookups.
        matched = matched.sort((a, b) => a.start - b.start);
    }
    return matched;
}
exports.recognizeChoices = recognizeChoices;
github microsoft / botbuilder-js / libraries / botbuilder-dialogs / src / choices / recognizeChoices.ts View on Github external
);

    // Try finding choices by text search first
    // - We only want to use a single strategy for returning results to avoid issues where utterances
    //   like the "the third one" or "the red one" or "the first division book" would miss-recognize as
    //   a numerical index or ordinal as well.
    const locale: string = options && options.locale ? options.locale : 'en-us';
    let matched: ModelResult[] = findChoices(utterance, list, options);
    if (matched.length === 0) {
        // Next try finding by ordinal
        const ordinals: ModelResult[] = Recognizers.recognizeOrdinal(utterance, locale);
        if (ordinals.length > 0) {
            ordinals.forEach(matchChoiceByIndex);
        } else {
            // Finally try by numerical index
            Recognizers.recognizeNumber(utterance, locale).forEach(matchChoiceByIndex);
        }

        // Sort any found matches by their position within the utterance.
        // - The results from findChoices() are already properly sorted so we just need this
        //   for ordinal & numerical lookups.
        matched = matched.sort((a: ModelResult, b: ModelResult) => a.start - b.start);
    }

    return matched;
}
github microsoft / botbuilder-js / libraries / botbuilder-prompts / lib / numberPrompt.js View on Github external
recognize: function recognize(context) {
            const request = context.activity || {};
            const utterance = request.text || '';
            const locale = request.locale || defaultLocale || 'en-us';
            const results = Recognizers.recognizeNumber(utterance, locale);
            const value = results.length > 0 && results[0].resolution ? parseFloat(results[0].resolution.value) : undefined;
            return Promise.resolve(validator ? validator(context, value) : value);
        }
    };
github microsoft / botbuilder-js / libraries / botbuilder-dialogs / lib / prompts / numberPrompt.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            const result = { succeeded: false };
            const activity = context.activity;
            const utterance = activity.text;
            const locale = activity.locale || this.defaultLocale || 'en-us';
            const results = Recognizers.recognizeNumber(utterance, locale);
            if (results.length > 0 && results[0].resolution) {
                result.succeeded = true;
                result.value = parseFloat(results[0].resolution.value);
            }
            return result;
        });
    }
github microsoft / botbuilder-js / libraries / botbuilder-dialogs-adaptive / src / input / numberSlot.ts View on Github external
protected async onRecognizeUtterance(planning: PlanningContext, utterance: string, locale: string): Promise|undefined> {
        if (utterance && utterance.length > 0) {
            const recognized: any = Recognizers.recognizeNumber(utterance, locale);
            if (recognized.length > 0 && recognized[0].resolution) {
                const value = parseFloat(recognized[0].resolution.value);
                return { succeeded: true, value: value, score: 1.0 };
            }
        }

        return { succeeded: false };
    }
github microsoft / botbuilder-js / libraries / botbuilder-prompts / src / numberPrompt.ts View on Github external
recognize: function recognize(context) {
            const request = context.activity || {};
            const utterance = request.text || '';
            const locale =  request.locale || defaultLocale || 'en-us';
            const results = Recognizers.recognizeNumber(utterance, locale);
            const value = results.length > 0 && results[0].resolution ? parseFloat(results[0].resolution.value) : undefined;
            return Promise.resolve(validator ? validator(context, value) : value as any);
        }
    };
github microsoft / botbuilder-js / libraries / botbuilder-dialogs / src / prompts / numberPrompt.ts View on Github external
protected async onRecognize(context: TurnContext, state: any, options: PromptOptions): Promise> {
        const result: PromptRecognizerResult = { succeeded: false };
        const activity: Activity = context.activity;
        const utterance: string = activity.text;
        const locale: string = activity.locale || this.defaultLocale || 'en-us';
        const results: any = Recognizers.recognizeNumber(utterance, locale);
        if (results.length > 0 && results[0].resolution) {
            result.succeeded = true;

            const culture = this.getCultureFormattedForGlobalize(locale);
            const parser = Globalize(culture).numberParser();
            result.value = parser(results[0].resolution.value);
        }

        return result;
    }

@microsoft/recognizers-text-number

recognizers-text-number provides robust recognition and resolution of numbers expressed in multiple languages.

MIT
Latest version published 1 year ago

Package Health Score

79 / 100
Full package analysis