molir.js
function returnRankedIntents(input, intents) {
    return new Promise((resolve, reject) => {
        let lowerCase = input.toLowerCase();
        let totalScore = 0;

        //loop through all loaded intents
        intents.forEach((intent) => {
            intent.score = 0;
            intent.utterences.forEach((utterence) => {

                let words = utterence.toLowerCase().split(" ");
                let utterenceMatch = 0;
                let ppw = 100 / words.length;


                //how many words in input match intent samples
                words.forEach((word) => {
                    if (lowerCase.includes(word)) {
                        utterenceMatch = utterenceMatch + ppw;
                    }
                });

                if (intent.score < utterenceMatch) {
                    intent.score = utterenceMatch
                }

            });

            //each intent keyword in the input multiplies the intent score by 2
            intent.keywords.forEach((keyword) => {
                if (input.includes(keyword.toLowerCase())) {
                    intent.score = intent.score * 2
                }
            });

            //add intent score to totalscore
            totalScore = totalScore + intent.score;
        });


        //work out confident by deviding each intents score by the total
        intents.forEach((intent) => {
            intent.confidence = intent.score / totalScore
        });

        //Sort intents
        let sorted = intents.sort((a, b) => {
            return b.confidence - a.confidence
        });

        //sent back the classified intents
        resolve(sorted);
    }
    )
}
function returnRankedIntents(input, intents) {
    return new Promise((resolve, reject) => {
        let lowerCase = input.toLowerCase();
        let totalScore = 0;

        //loop through all loaded intents
        intents.forEach((intent) => {
            intent.score = 0;
            intent.utterences.forEach((utterence) => {

                let words = utterence.toLowerCase().split(" ");
                let utterenceMatch = 0;
                let ppw = 100 / words.length;


                //how many words in input match intent samples
                words.forEach((word) => {
                    if (lowerCase.includes(word)) {
                        utterenceMatch = utterenceMatch + ppw;
                    }
                });

                if (intent.score < utterenceMatch) {
                    intent.score = utterenceMatch
                }

            });

            //each intent keyword in the input multiplies the intent score by 2
            intent.keywords.forEach((keyword) => {
                if (input.includes(keyword.toLowerCase())) {
                    intent.score = intent.score * 2
                }
            });

            //add intent score to totalscore
            totalScore = totalScore + intent.score;
        });


        //work out confident by deviding each intents score by the total
        intents.forEach((intent) => {
            intent.confidence = intent.score / totalScore
        });

        //Sort intents
        let sorted = intents.sort((a, b) => {
            return b.confidence - a.confidence
        });

        //sent back the classified intents
        resolve(sorted);
    }
    )
}
function returnRankedIntents ( input , intents ) { return new Promise ( ( resolve , reject ) => { let lowerCase = input . toLowerCase ( ) ; let totalScore = 0 ; //loop through all loaded intents intents . forEach ( ( intent ) => { intent . score = 0 ; intent . utterences . forEach ( ( utterence ) => { let words = utterence . toLowerCase ( ) . split ( " " ) ; let utterenceMatch = 0 ; let ppw = 100 / words . length ; //how many words in input match intent samples words . forEach ( ( word ) => { if ( lowerCase . includes ( word ) ) { utterenceMatch = utterenceMatch + ppw ; } } ) ; if ( intent . score < utterenceMatch ) { intent . score = utterenceMatch } } ) ; //each intent keyword in the input multiplies the intent score by 2 intent . keywords . forEach ( ( keyword ) => { if ( input . includes ( keyword . toLowerCase ( ) ) ) { intent . score = intent . score * 2 } } ) ; //add intent score to totalscore totalScore = totalScore + intent . score ; } ) ; //work out confident by deviding each intents score by the total intents . forEach ( ( intent ) => { intent . confidence = intent . score / totalScore } ) ; //Sort intents let sorted = intents . sort ( ( a , b ) => { return b . confidence - a . confidence } ) ; //sent back the classified intents resolve ( sorted ) ; } ) }
Function to classify input based on loaded intents
Function to classify input based on loaded intents