Created
June 27, 2011 10:10
-
-
Save nbqx/1048619 to your computer and use it in GitHub Desktop.
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 util = require('util'); | |
var events = require('events'); | |
var request = require('request'); //https://github.com/mikeal/request | |
var Wordnet = function(words){ | |
this.ret = []; | |
this.words = words; | |
this.url = "http://nymnym.heroku.com/word/"; | |
events.EventEmitter.call(this); | |
}; | |
util.inherits(Wordnet,events.EventEmitter); | |
Wordnet.prototype.start = function(){ | |
var self = this; | |
self.words.forEach(function(w,i){ | |
request({uri:self.url+encodeURI(w)},function(err,res,dt){ | |
if(err&&res.statuCode!=200) throw err; | |
var obj = JSON.parse(dt); | |
self.ret.push(obj); | |
if(self.ret.length==self.words.length){ | |
self.emit('complete', self.ret); | |
} | |
}); | |
}); | |
} | |
var wds = ["苺","豆乳","アイアンメイデン","FTP","道具","コンパイラ"]; | |
var wn = new Wordnet(wds); | |
wn.on('complete',function(data){ | |
console.log(data); | |
}); | |
wn.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment