How to use @microsoft/recognizers-text-number-with-unit - 6 common examples

To help you get started, we’ve selected a few @microsoft/recognizers-text-number-with-unit 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 BotBuilderCommunity / botbuilder-community-js / libraries / botbuilder-dialog-prompts / src / numberWithUnit.ts View on Github external
const utterance: string = activity.text;
        const locale: string = activity.locale || this.defaultLocale || 'en-us';
        
        switch(this.promptType)
        {
            case NumberWithUnitPromptType.Currency:
                results = recognizers.recognizeCurrency(utterance, locale);
                break;
            case NumberWithUnitPromptType.Dimension:
                results = recognizers.recognizeDimension(utterance, locale);
                break;
            case NumberWithUnitPromptType.Age:
                results = recognizers.recognizeAge(utterance, locale);
                break;
            case NumberWithUnitPromptType.Temperature:
                results = recognizers.recognizeTemperature(utterance, locale);
                break;
        }
        if (results.length > 0 && results[0].resolution != null) {
            const resolvedUnit = results[0].resolution.unit;
            const resolvedValue = results[0].resolution.value;
            try {
                result.succeeded = true;
                const numberWithUnitResult = {
                    unit: resolvedUnit
                    , value: resolvedValue
                };
                result.value = numberWithUnitResult;
            }
            catch(e) {
                console.log(e);
            }
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / chinese / durationConfiguration.ts View on Github external
constructor() {
        super(null);
        this.extractor = new NumberWithUnitExtractor(new DurationExtractorConfiguration());
        this.yearRegex = RegExpUtility.getSafeRegExp(ChineseDateTime.DurationYearRegex);
        this.halfSuffixRegex = RegExpUtility.getSafeRegExp(ChineseDateTime.DurationHalfSuffixRegex);
    }
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / chinese / durationConfiguration.ts View on Github external
constructor() {
        let config = new ChineseDurationParserConfiguration();
        super(config);
        this.internalParser = new NumberWithUnitParser(new DurationParserConfiguration());
    }
github BotBuilderCommunity / botbuilder-community-js / libraries / botbuilder-dialog-prompts / src / numberWithUnit.ts View on Github external
const result: PromptRecognizerResult = { succeeded: false };
        let results: any;
        const activity: Activity = context.activity;
        const utterance: string = activity.text;
        const locale: string = activity.locale || this.defaultLocale || 'en-us';
        
        switch(this.promptType)
        {
            case NumberWithUnitPromptType.Currency:
                results = recognizers.recognizeCurrency(utterance, locale);
                break;
            case NumberWithUnitPromptType.Dimension:
                results = recognizers.recognizeDimension(utterance, locale);
                break;
            case NumberWithUnitPromptType.Age:
                results = recognizers.recognizeAge(utterance, locale);
                break;
            case NumberWithUnitPromptType.Temperature:
                results = recognizers.recognizeTemperature(utterance, locale);
                break;
        }
        if (results.length > 0 && results[0].resolution != null) {
            const resolvedUnit = results[0].resolution.unit;
            const resolvedValue = results[0].resolution.value;
            try {
                result.succeeded = true;
                const numberWithUnitResult = {
                    unit: resolvedUnit
                    , value: resolvedValue
                };
                result.value = numberWithUnitResult;
            }
github BotBuilderCommunity / botbuilder-community-js / libraries / botbuilder-dialog-prompts / src / numberWithUnit.ts View on Github external
protected async onRecognize(context: TurnContext, state: any, options: PromptOptions): Promise> {
        const result: PromptRecognizerResult = { succeeded: false };
        let results: any;
        const activity: Activity = context.activity;
        const utterance: string = activity.text;
        const locale: string = activity.locale || this.defaultLocale || 'en-us';
        
        switch(this.promptType)
        {
            case NumberWithUnitPromptType.Currency:
                results = recognizers.recognizeCurrency(utterance, locale);
                break;
            case NumberWithUnitPromptType.Dimension:
                results = recognizers.recognizeDimension(utterance, locale);
                break;
            case NumberWithUnitPromptType.Age:
                results = recognizers.recognizeAge(utterance, locale);
                break;
            case NumberWithUnitPromptType.Temperature:
                results = recognizers.recognizeTemperature(utterance, locale);
                break;
        }
        if (results.length > 0 && results[0].resolution != null) {
            const resolvedUnit = results[0].resolution.unit;
            const resolvedValue = results[0].resolution.value;
            try {
                result.succeeded = true;
github BotBuilderCommunity / botbuilder-community-js / libraries / botbuilder-dialog-prompts / src / numberWithUnit.ts View on Github external
protected async onRecognize(context: TurnContext, state: any, options: PromptOptions): Promise> {
        const result: PromptRecognizerResult = { succeeded: false };
        let results: any;
        const activity: Activity = context.activity;
        const utterance: string = activity.text;
        const locale: string = activity.locale || this.defaultLocale || 'en-us';
        
        switch(this.promptType)
        {
            case NumberWithUnitPromptType.Currency:
                results = recognizers.recognizeCurrency(utterance, locale);
                break;
            case NumberWithUnitPromptType.Dimension:
                results = recognizers.recognizeDimension(utterance, locale);
                break;
            case NumberWithUnitPromptType.Age:
                results = recognizers.recognizeAge(utterance, locale);
                break;
            case NumberWithUnitPromptType.Temperature:
                results = recognizers.recognizeTemperature(utterance, locale);
                break;
        }
        if (results.length > 0 && results[0].resolution != null) {
            const resolvedUnit = results[0].resolution.unit;
            const resolvedValue = results[0].resolution.value;
            try {
                result.succeeded = true;
                const numberWithUnitResult = {
                    unit: resolvedUnit
                    , value: resolvedValue