|
| 1 | +// wink-nlp |
| 2 | +// A new way of doing NLP |
| 3 | +// |
| 4 | +// Copyright (C) 2017-20 GRAYPE Systems Private Limited |
| 5 | +// |
| 6 | +// This file is part of “wink-nlp”. |
| 7 | +// |
| 8 | +// Permission is hereby granted, free of charge, to any |
| 9 | +// person obtaining a copy of this software and |
| 10 | +// associated documentation files (the "Software"), to |
| 11 | +// deal in the Software without restriction, including |
| 12 | +// without limitation the rights to use, copy, modify, |
| 13 | +// merge, publish, distribute, sublicense, and/or sell |
| 14 | +// copies of the Software, and to permit persons to |
| 15 | +// whom the Software is furnished to do so, subject to |
| 16 | +// the following conditions: |
| 17 | +// |
| 18 | +// The above copyright notice and this permission notice |
| 19 | +// shall be included in all copies or substantial |
| 20 | +// portions of the Software. |
| 21 | +// |
| 22 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF |
| 23 | +// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 24 | +// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 25 | +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 26 | +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 27 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 28 | +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 30 | +// DEALINGS IN THE SOFTWARE. |
| 31 | + |
| 32 | +// |
| 33 | + |
| 34 | +/* eslint-disable no-console */ |
| 35 | + |
| 36 | +const childProcess = require( 'child_process' ); |
| 37 | +const languageModels = require( './language-models.json' ); |
| 38 | +// Model name with be at [ 1 ], as we are using "node -e" command. |
| 39 | +const modelName = process.argv[ 1 ] || 'wink-eng-lite-model'; |
| 40 | +const modelDetails = languageModels.find( ( lm ) => lm.name === modelName ); |
| 41 | +if ( modelDetails === undefined ) { |
| 42 | + // Display error in red color. |
| 43 | + console.log( `\n\x1b[0m\x1b[31m"${modelName}" is an invalid model name.\x1b[0m` ); |
| 44 | + // Corrective action in green color. |
| 45 | + console.log( '\n\x1b[32mUse one of the following models:\x1b[0m'); |
| 46 | + console.table( languageModels ); |
| 47 | + console.log(); |
| 48 | + throw Error( 'Model installation failed!' ); |
| 49 | +} |
| 50 | +var modelVersion = modelDetails.version; |
| 51 | +var model = `https://github.com/winkjs/${modelName}/releases/download/${modelVersion}/${modelName}-${modelVersion}.tgz`; |
| 52 | +// Display (un)installation commands in yellow color. |
| 53 | +console.log( `\n\x1b[33mnpm uninstall ${model}\x1b[0m` ); |
| 54 | +childProcess.execSync( `npm uninstall ${model}`, { stdio: 'inherit' } ); // eslint-disable-line no-sync |
| 55 | +console.log( `\n\x1b[33mnpm install ${model} --save\x1b[0m` ); |
| 56 | +childProcess.execSync( `npm install ${model} --save`, { stdio: 'inherit' } ); // eslint-disable-line no-sync |
0 commit comments