Created
February 28, 2018 18:25
-
-
Save Ravenstine/1094de787f1459dd7a0f52f3a93ee6d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const assistants = { | |
alexa: [ | |
'session', | |
'request', | |
'version' | |
], | |
google: [ | |
'user', | |
'device', | |
'conversation', | |
'inputs' | |
], | |
cortana: [ | |
'type', | |
'id', | |
'timestamp', | |
'serviceUrl', | |
'channelId', | |
'from', | |
'conversation', | |
'recipient', | |
'text', | |
'textFormat' | |
] | |
}; | |
module.exports = requestBody => { | |
let scores = {}, | |
trainingCount = Object.keys(assistants).length; | |
Object.keys(assistants).forEach(assistant => { | |
scores[assistant] = 0; | |
let assistantWords = assistants[assistant]; | |
Object.keys(requestBody).forEach(key => { | |
let s = (assistantWords.indexOf(key) > -1) ? 1 : 0.1; | |
scores[assistant] += Math.log(s / parseFloat(assistantWords.length)); | |
}); | |
scores[assistant] += Math.log((1 || 0.1) / trainingCount); | |
}); | |
return Object.entries(scores).sort((a,b) => b[1] - a[1])[0].shift(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment