Created
November 6, 2015 05:52
-
-
Save mikatalk/50a5d17bef128efa8a50 to your computer and use it in GitHub Desktop.
wordnet-magic example - code review
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
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