tui-usinghelloworld
Version:
54 lines (42 loc) • 2.1 kB
JavaScript
/*
@author Ilya Shubentsov
MIT License
Copyright (c) 2017 Ilya Shubentsov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// Load the vui-ad-hoc-alexa-recognizer so that we can use it
let vui = require('vui-ad-hoc-alexa-recognizer');
// Call this function to display instructions on the console on how to call index.js
// This isn't necessary, but a nice touch to have in case you come back to it and forget
// how to use it.
let usage = function(){
console.log('Usage: node ' + process.argv[1] + ' "string to match"');
}
// Simple error checking - make sure we got all the arguments on the command line.
if (process.argv.length < 3) {
usage();
process.exit(1);
}
// Get the actual string that we should be matching
let stringToMatch = process.argv[2];
// Now load and parse the recognizer.json file
let recognizer = require('./recognizer.json');
// Now make the actual call to match the text to intent
let result = vui.Recognizer.matchText(stringToMatch, undefined, undefined, recognizer);
// Finally, print the result out to console and exit
console.log(JSON.stringify(result, null, 2));