Skip to content

Instantly share code, notes, and snippets.

@dainelmawer
Created March 18, 2018 09:54
Show Gist options
  • Save dainelmawer/d4dc972fd2c0db5e58615c13c17ca8aa to your computer and use it in GitHub Desktop.
Save dainelmawer/d4dc972fd2c0db5e58615c13c17ca8aa to your computer and use it in GitHub Desktop.
WDD - NLP Practical
// package.json
{
"name": "dictionary",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"preferGlobal": true,
"bin": "./index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"chalk": "^2.3.2",
"commander": "^2.15.0",
"natural": "^0.5.6",
"wordnet-db": "^3.1.6"
}
}
// index.js
#!/usr/bin/env node
const program = require('commander');
const natural = require('natural');
const wordNet = new natural.WordNet()
let wordNetLookUp = ( val ) => {
wordNet.lookup( val, ( results ) => {
results.forEach( ( result ) => {
console.info('------------------------------------');
console.info(result.synsetOffset);
console.info(result.pos);
console.info(result.lemma);
console.info(result.synonyms);
console.info(result.pos);
console.info(result.gloss);
} );
})
}
program
.version('1.0.0')
.description('Lookup words using the WordNet Database');
program
.command('lookup <word>')
.alias(' l ')
.description('Search for a word in the dictionary')
.action( ( word ) => {
wordNetLookUp( word );
} );
program.parse(process.argv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment