Skip to content

Commit

Permalink
a somewhat working wordnet binding
Browse files Browse the repository at this point in the history
  • Loading branch information
silentrob committed Jul 22, 2011
1 parent b15c8c9 commit 2bf3a1d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Download, fork or clone the code, setup the 2 dependancies below.
Util.trigram(['The','fox','ran','fast']); // [ [ 'The', 'fox', 'ran' ], [ 'fox', 'ran', 'fast' ] ]`


### Wordnet Bindings
- Wordnet bindings have been started, you must download the wordnet database before you can play with it.


## What's Not yet Included aka TODO

### Sentence Boundary Detection
Expand All @@ -73,7 +77,7 @@ Download, fork or clone the code, setup the 2 dependancies below.
#### Implement YAGO
This is started and well underway - http://www.mpi-inf.mpg.de/yago-naga/yago/

#### Wordnet Bindings

#### DBPedia Bindings

## Other NODE Projects of Interest
Expand Down
31 changes: 17 additions & 14 deletions lib/wordnet/wordReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var WordNetCorpusReader = module.exports = Class.extend({
}
}

console.log("Loading lexnames");
// console.log("Loading lexnames");
_this._loadLemmaPosOffsetMap();
});

Expand Down Expand Up @@ -192,10 +192,10 @@ var WordNetCorpusReader = module.exports = Class.extend({
throw new Error("Wordnet not found at location "+ p)
}

console.log("Reading File", p)
//console.log("Reading File", p)
fs.readFile(p, function (err, data) {
if (err) throw err;
console.log("Closing File", p)
//console.log("Closing File", p)
callback(data);
});
});
Expand All @@ -212,7 +212,7 @@ var WordNetCorpusReader = module.exports = Class.extend({
throw new Error("Wordnet not found at location "+ p)
}

console.log("Opening file", p);
//console.log("Opening file", p);

var str = fs.open(p,"r",function(err,fd){
if (err) {
Expand All @@ -235,8 +235,8 @@ var WordNetCorpusReader = module.exports = Class.extend({
}

this._dataFile(pos, function(fd){
var buff = new Buffer(1024);
fs.read(fd,buff,0,1024,offset,function(err,br,buff){
var buff = new Buffer(4096);
fs.read(fd,buff,0,4096,offset,function(err,br,buff){
if (err) { console.log("ERROR Reading File") }

var data_line = buff.toString().split('\n')[0];
Expand Down Expand Up @@ -276,6 +276,7 @@ var WordNetCorpusReader = module.exports = Class.extend({

var synset = new Synset(_this);

console.log(line);
var m = line.split('|');
var columns_str = m[0], gloss = m[1];

Expand Down Expand Up @@ -449,16 +450,16 @@ var Synset = _WordNetObject.extend({
this._lemma_pointers = {};
},

hypernyms: function() {
return this._related('@');
hypernyms: function(callback) {
this._related('@', callback);
},

instance_hypernyms: function() {
return this._related('@i');
instance_hypernyms: function(callback) {
this._related('@i', callback);
},

hyponyms:function() {
return this._related('~');
hyponyms:function(callback) {
this._related('~', callback);
},

verbGroups : function(callback) {
Expand All @@ -469,13 +470,15 @@ var Synset = _WordNetObject.extend({

var pointerTuples = this._pointers[relation_symbol];

// TODO: construct an array
// TODO: construct an array fire callback after collection
for (var i = 0; i < pointerTuples.length; i++) {
var pos = pointerTuples[i][0];
var offset = pointerTuples[i][1];

this.wordnetCorpusReader._synsetFromPosAndOffset(pos, offset, function(s){
callback(s);
if (pointerTuples.length == i) {
callback(s);
}
});
}
},
Expand Down
10 changes: 7 additions & 3 deletions test/test-wordnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ new WordNetCorpusReader({root:'./wordnet'},function(wn){
})
});

// var fn = function(nav){
// console.log(nav.name);
// }
//
// console.log("Navigations:");
// wn.synset('travel.v.01',function(S){
// console.log(S.hypernyms())
// S.hypernyms(fn)
// });

// wn.synset('travel.v.02',function(S){
// console.log(S.hypernyms())
// S.hypernyms(fn)
// });
//
// wn.synset('travel.v.03',function(S){
// console.log(S.hypernyms())
// S.hypernyms(fn)
// });

});

0 comments on commit 2bf3a1d

Please sign in to comment.