Skip to content

Instantly share code, notes, and snippets.

@mikatalk
Created November 6, 2015 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikatalk/50a5d17bef128efa8a50 to your computer and use it in GitHub Desktop.
Save mikatalk/50a5d17bef128efa8a50 to your computer and use it in GitHub Desktop.
wordnet-magic example - code review
var inspect = require('util-inspect');
var wordNet = require('util')
var wordNet = require('wordnet-magic')
var wn = wordNet(__dirname + '/sqlite-31.db', false)
var input = 'the cat is patiently waiting at some of the best hospitals in Los Angeles'
var words = input.split(' ')
var sort = { nouns:[], verbs:[], adjectives:[], adverbs:[] }
processWord(0)
function processWord(index){
if ( index >= words.length ) return sentenceProcessed()
console.log('processing word:', words[index])
var count = 0;
// nouns
wn.isNoun(words[index], function(err, data){
if ( data ) {
console.log(' - isNoun:', data)
sort.nouns.push(words[index])
}
checkWordProcessComplete()
})
// verbs
wn.isVerb(words[index], function(err, data){
if ( data ) {
console.log(' - isVerb:', data)
sort.verbs.push(words[index])
}
checkWordProcessComplete()
})
// adjective
wn.isAdjective(words[index], function(err, data){
if ( data ) {
console.log(' - isAdjective:', data)
sort.adjectives.push(words[index])
}
checkWordProcessComplete()
})
// adverb
wn.isAdverb(words[index], function(err, data){
if ( data ) {
console.log(' - isAdverb:', data)
sort.adverbs.push(words[index])
}
checkWordProcessComplete()
});
function checkWordProcessComplete(){
if ( ++count == 4 ) processWord(index+1)
}
}
function sentenceProcessed(){
console.log('### complete ###', inspect(sort))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment