How to use @microsoft/recognizers-text-suite - 10 common examples

To help you get started, weā€™ve selected a few @microsoft/recognizers-text-suite 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 / 44.prompt-for-user-input / bots / customPromptBot.js View on Github external
static validateAge(input) {
        // Try to recognize the input as a number. This works for responses such as "twelve" as well as "12".
        try {
            // Attempt to convert the Recognizer result to an integer. This works for "a dozen", "twelve", "12", and so on.
            // The recognizer returns a list of potential recognition results, if any.
            const results = Recognizers.recognizeNumber(input, Recognizers.Culture.English);
            let output;
            results.forEach(result => {
                // result.resolution is a dictionary, where the "value" entry contains the processed string.
                const value = result.resolution.value;
                if (value) {
                    const age = parseInt(value);
                    if (!isNaN(age) && age >= 18 && age <= 120) {
                        output = { success: true, age: age };
                        return;
                    }
                }
            });
            return output || { success: false, message: 'Please enter an age between 18 and 120.' };
        } catch (error) {
            return {
                success: false,
github microsoft / Recognizers-Text / JavaScript / samples / simple-console / index.js View on Github external
function parseAll(input, culture) {
    return [
        // Number recognizer - This function will find any number from the input
        // E.g "I have two apples" will return "2".
        ...Recognizers.recognizeNumber(input, culture),

        // Ordinal number recognizer - This function will find any ordinal number
        // E.g "eleventh" will return "11".
        ...Recognizers.recognizeOrdinal(input, culture),

        // Percentage recognizer - This function will find any number presented as percentage
        // E.g "one hundred percents" will return "100%"
        ...Recognizers.recognizePercentage(input, culture),

        // Age recognizer - This function will find any age number presented
        // E.g "After ninety five years of age, perspectives change" will return "95 Year"
        ...Recognizers.recognizeAge(input, culture),

        // Currency recognizer - This function will find any currency presented
        // E.g "Interest expense in the 1988 third quarter was $ 75.3 million" will return "75300000 Dollar"
        ...Recognizers.recognizeCurrency(input, culture),
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 44.prompt-for-user-input / bots / customPromptBot.js View on Github external
static validateDate(input) {
        // Try to recognize the input as a date-time. This works for responses such as "11/14/2018", "today at 9pm", "tomorrow", "Sunday at 5pm", and so on.
        // The recognizer returns a list of potential recognition results, if any.
        try {
            const results = Recognizers.recognizeDateTime(input, Recognizers.Culture.English);
            const now = new Date();
            const earliest = now.getTime() + (60 * 60 * 1000);
            let output;
            results.forEach(result => {
                // result.resolution is a dictionary, where the "values" entry contains the processed input.
                result.resolution.values.forEach(resolution => {
                    // The processed input contains a "value" entry if it is a date-time value, or "start" and
                    // "end" entries if it is a date-time range.
                    const datevalue = resolution.value || resolution.start;
                    // If only time is given, assume it's for today.
                    const datetime = resolution.type === 'time'
                        ? new Date(`${ now.toLocaleDateString() } ${ datevalue }`)
                        : new Date(datevalue);
                    if (datetime && earliest < datetime.getTime()) {
                        output = { success: true, date: datetime.toLocaleDateString() };
                        return;
github microsoft / Recognizers-Text / JavaScript / samples / simple-console / index.js View on Github external
// Currency recognizer - This function will find any currency presented
        // E.g "Interest expense in the 1988 third quarter was $ 75.3 million" will return "75300000 Dollar"
        ...Recognizers.recognizeCurrency(input, culture),

        // Dimension recognizer - This function will find any dimension presented
        // E.g "The six-mile trip to my airport hotel that had taken 20 minutes earlier in the day took more than three hours." will return "6 Mile"
        ...Recognizers.recognizeDimension(input, culture),

        // Temperature recognizer - This function will find any temperature presented
        // E.g "Set the temperature to 30 degrees celsius" will return "30 C"
        ...Recognizers.recognizeTemperature(input, culture),
        
        // DateTime recognizer - This function will find any Date even if its write in colloquial language -
        // E.g "I'll go back 8pm today" will return "2017-10-04 20:00:00"
        ...Recognizers.recognizeDateTime(input, culture),
        
        // Add PhoneNumber recognizer - This recognizer will find any phone number presented
        // E.g "My phone number is ( 19 ) 38294427."
        ...Recognizers.recognizePhoneNumber(input, culture),

        // Add IP recognizer - This recognizer will find any Ipv4/Ipv6 presented
        // E.g "My Ip is 8.8.8.8"
        ...Recognizers.recognizeIpAddress(input, culture),

        // URL recognizer -This recognizer will find all the urls
        // E.g "bing.com"
        ...Recognizers.recognizeURL(input, culture),

        // GUID recognizer - This recognizer will find all the GUID presented
        // E.g "My GUID number is {123e4567-e89b-12d3-a456-426655440000}"
        ...Recognizers.recognizeGUID(input, culture),
github microsoft / Recognizers-Text / JavaScript / samples / simple-console / index.js View on Github external
var Recognizers = require('@microsoft/recognizers-text-suite');

// Use English for the Recognizers culture
const defaultCulture = Recognizers.Culture.English;

// Start Sample
showIntro();
runRecognition();

// Read from Console and recognize
function runRecognition() {
    var stdin = process.openStdin();

    // Read the text to recognize
    write('Enter the text to recognize: ');

    stdin.addListener('data', function (e) {
        var input = e.toString().trim();
        if (input) {
            // Exit
github microsoft / Recognizers-Text / JavaScript / samples / simple-console / index.js View on Github external
// Add IP recognizer - This recognizer will find any Ipv4/Ipv6 presented
        // E.g "My Ip is 8.8.8.8"
        ...Recognizers.recognizeIpAddress(input, culture),

        // URL recognizer -This recognizer will find all the urls
        // E.g "bing.com"
        ...Recognizers.recognizeURL(input, culture),

        // GUID recognizer - This recognizer will find all the GUID presented
        // E.g "My GUID number is {123e4567-e89b-12d3-a456-426655440000}"
        ...Recognizers.recognizeGUID(input, culture),

        // Boolean recognizer - This function will find yes/no like responses, including emoji -
        // E.g "yup, I need that" will return "True"
        ...Recognizers.recognizeBoolean(input, culture)
    ];
}
github microsoft / Recognizers-Text / JavaScript / samples / simple-console / index.js View on Github external
return [
        // Number recognizer - This function will find any number from the input
        // E.g "I have two apples" will return "2".
        ...Recognizers.recognizeNumber(input, culture),

        // Ordinal number recognizer - This function will find any ordinal number
        // E.g "eleventh" will return "11".
        ...Recognizers.recognizeOrdinal(input, culture),

        // Percentage recognizer - This function will find any number presented as percentage
        // E.g "one hundred percents" will return "100%"
        ...Recognizers.recognizePercentage(input, culture),

        // Age recognizer - This function will find any age number presented
        // E.g "After ninety five years of age, perspectives change" will return "95 Year"
        ...Recognizers.recognizeAge(input, culture),

        // Currency recognizer - This function will find any currency presented
        // E.g "Interest expense in the 1988 third quarter was $ 75.3 million" will return "75300000 Dollar"
        ...Recognizers.recognizeCurrency(input, culture),

        // Dimension recognizer - This function will find any dimension presented
        // E.g "The six-mile trip to my airport hotel that had taken 20 minutes earlier in the day took more than three hours." will return "6 Mile"
        ...Recognizers.recognizeDimension(input, culture),

        // Temperature recognizer - This function will find any temperature presented
        // E.g "Set the temperature to 30 degrees celsius" will return "30 C"
        ...Recognizers.recognizeTemperature(input, culture),
        
        // DateTime recognizer - This function will find any Date even if its write in colloquial language -
        // E.g "I'll go back 8pm today" will return "2017-10-04 20:00:00"
        ...Recognizers.recognizeDateTime(input, culture),
github microsoft / Recognizers-Text / JavaScript / samples / simple-console / index.js View on Github external
// Ordinal number recognizer - This function will find any ordinal number
        // E.g "eleventh" will return "11".
        ...Recognizers.recognizeOrdinal(input, culture),

        // Percentage recognizer - This function will find any number presented as percentage
        // E.g "one hundred percents" will return "100%"
        ...Recognizers.recognizePercentage(input, culture),

        // Age recognizer - This function will find any age number presented
        // E.g "After ninety five years of age, perspectives change" will return "95 Year"
        ...Recognizers.recognizeAge(input, culture),

        // Currency recognizer - This function will find any currency presented
        // E.g "Interest expense in the 1988 third quarter was $ 75.3 million" will return "75300000 Dollar"
        ...Recognizers.recognizeCurrency(input, culture),

        // Dimension recognizer - This function will find any dimension presented
        // E.g "The six-mile trip to my airport hotel that had taken 20 minutes earlier in the day took more than three hours." will return "6 Mile"
        ...Recognizers.recognizeDimension(input, culture),

        // Temperature recognizer - This function will find any temperature presented
        // E.g "Set the temperature to 30 degrees celsius" will return "30 C"
        ...Recognizers.recognizeTemperature(input, culture),
        
        // DateTime recognizer - This function will find any Date even if its write in colloquial language -
        // E.g "I'll go back 8pm today" will return "2017-10-04 20:00:00"
        ...Recognizers.recognizeDateTime(input, culture),
        
        // Add PhoneNumber recognizer - This recognizer will find any phone number presented
        // E.g "My phone number is ( 19 ) 38294427."
        ...Recognizers.recognizePhoneNumber(input, culture),
github microsoft / Recognizers-Text / JavaScript / samples / simple-console / index.js View on Github external
// Percentage recognizer - This function will find any number presented as percentage
        // E.g "one hundred percents" will return "100%"
        ...Recognizers.recognizePercentage(input, culture),

        // Age recognizer - This function will find any age number presented
        // E.g "After ninety five years of age, perspectives change" will return "95 Year"
        ...Recognizers.recognizeAge(input, culture),

        // Currency recognizer - This function will find any currency presented
        // E.g "Interest expense in the 1988 third quarter was $ 75.3 million" will return "75300000 Dollar"
        ...Recognizers.recognizeCurrency(input, culture),

        // Dimension recognizer - This function will find any dimension presented
        // E.g "The six-mile trip to my airport hotel that had taken 20 minutes earlier in the day took more than three hours." will return "6 Mile"
        ...Recognizers.recognizeDimension(input, culture),

        // Temperature recognizer - This function will find any temperature presented
        // E.g "Set the temperature to 30 degrees celsius" will return "30 C"
        ...Recognizers.recognizeTemperature(input, culture),
        
        // DateTime recognizer - This function will find any Date even if its write in colloquial language -
        // E.g "I'll go back 8pm today" will return "2017-10-04 20:00:00"
        ...Recognizers.recognizeDateTime(input, culture),
        
        // Add PhoneNumber recognizer - This recognizer will find any phone number presented
        // E.g "My phone number is ( 19 ) 38294427."
        ...Recognizers.recognizePhoneNumber(input, culture),

        // Add IP recognizer - This recognizer will find any Ipv4/Ipv6 presented
        // E.g "My Ip is 8.8.8.8"
        ...Recognizers.recognizeIpAddress(input, culture),
github microsoft / Recognizers-Text / JavaScript / samples / simple-console / index.js View on Github external
// Add PhoneNumber recognizer - This recognizer will find any phone number presented
        // E.g "My phone number is ( 19 ) 38294427."
        ...Recognizers.recognizePhoneNumber(input, culture),

        // Add IP recognizer - This recognizer will find any Ipv4/Ipv6 presented
        // E.g "My Ip is 8.8.8.8"
        ...Recognizers.recognizeIpAddress(input, culture),

        // URL recognizer -This recognizer will find all the urls
        // E.g "bing.com"
        ...Recognizers.recognizeURL(input, culture),

        // GUID recognizer - This recognizer will find all the GUID presented
        // E.g "My GUID number is {123e4567-e89b-12d3-a456-426655440000}"
        ...Recognizers.recognizeGUID(input, culture),

        // Boolean recognizer - This function will find yes/no like responses, including emoji -
        // E.g "yup, I need that" will return "True"
        ...Recognizers.recognizeBoolean(input, culture)
    ];
}