node-wordnet
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -19,3 +19,3 @@ var DataFile, IndexFile, Promise, WordNet, async, fs, path, | ||
WordNet = (function() { | ||
var exceptions, forms, tokenDetach, unique, _forms, _validForms; | ||
var exceptions, forms, tokenDetach, unique, _forms, _loadExceptions, _validForms, _validFormsWithExceptions; | ||
@@ -236,11 +236,5 @@ function WordNet(dataDir) { | ||
WordNet.prototype.loadExceptions = function(callback) { | ||
var loadFile, wordnet; | ||
wordnet = this; | ||
wordnet.exceptions = { | ||
n: {}, | ||
v: {}, | ||
a: {}, | ||
r: {} | ||
}; | ||
_loadExceptions = function(wordnet, callback) { | ||
var loadFile; | ||
WordNet.prototype.exceptions = 'pending'; | ||
loadFile = function(exception, callback) { | ||
@@ -254,2 +248,3 @@ var fullPath; | ||
} | ||
temp = {}; | ||
lines = data.toString().split("\n"); | ||
@@ -260,3 +255,2 @@ for (_i = 0, _len = lines.length; _i < _len; _i++) { | ||
_ref = line.split(' '), term1 = _ref[0], term2 = 2 <= _ref.length ? __slice.call(_ref, 1) : []; | ||
temp = wordnet.exceptions[exception.pos]; | ||
if (temp[term1] == null) { | ||
@@ -268,6 +262,18 @@ temp[term1] = []; | ||
} | ||
return callback(); | ||
return callback(null, { | ||
pos: exception.pos, | ||
data: temp | ||
}); | ||
}); | ||
}; | ||
return async.each(exceptions, loadFile, callback); | ||
return async.map(exceptions, loadFile, function(err, results) { | ||
var result, _i, _len; | ||
exceptions = {}; | ||
for (_i = 0, _len = results.length; _i < _len; _i++) { | ||
result = results[_i]; | ||
exceptions[result.pos] = result.data; | ||
} | ||
WordNet.prototype.exceptions = exceptions; | ||
return callback(); | ||
}); | ||
}; | ||
@@ -301,3 +307,3 @@ | ||
_ref = string.split('#'), word = _ref[0], pos = _ref[1], sense = _ref[2]; | ||
detach = []; | ||
detach = [word]; | ||
length = word.length; | ||
@@ -372,5 +378,5 @@ switch (pos) { | ||
_forms = function(wordnet, word, pos) { | ||
var colloc, exception, forms, i, index, lword, rtn, token, _i, _j, _len, _len1, _ref, _ref1; | ||
var colloc, exception, forms, i, index, lword, rtn, token, _i, _j, _len, _len1, _ref; | ||
lword = word.toLowerCase(); | ||
exception = (_ref = wordnet.exceptions) != null ? (_ref1 = _ref[pos]) != null ? _ref1[lword] : void 0 : void 0; | ||
exception = (_ref = wordnet.exceptions[pos]) != null ? _ref[lword] : void 0; | ||
if (exception) { | ||
@@ -450,22 +456,28 @@ return [word].concat(exception); | ||
WordNet.prototype.validForms = function(string, callback) { | ||
var wordnet; | ||
wordnet = this; | ||
if (wordnet.exceptions) { | ||
return _validForms(string, callback); | ||
_validFormsWithExceptions = function(wordnet, string, callback) { | ||
if (wordnet.exceptions === void 0) { | ||
return _loadExceptions(wordnet, function() { | ||
return _validFormsWithExceptions(wordnet, string, callback); | ||
}); | ||
} else if (wordnet.exceptions === 'pending') { | ||
return process.nextTick(function() { | ||
return _validFormsWithExceptions(wordnet, string, callback); | ||
}); | ||
} else { | ||
return wordnet.loadExceptions(function() { | ||
return _validForms(wordnet, string, callback); | ||
}); | ||
return _validForms(wordnet, string, callback); | ||
} | ||
}; | ||
WordNet.prototype.validForms = function(string, callback) { | ||
return _validFormsWithExceptions(this, string, callback); | ||
}; | ||
WordNet.prototype.validFormsAsync = function(string) { | ||
var wordnet; | ||
wordnet = this; | ||
return new Promise(function(resolve, reject) { | ||
return wordnet.validForms(string, function(data) { | ||
return resolve(data); | ||
}); | ||
}); | ||
return new Promise((function(_this) { | ||
return function(resolve, reject) { | ||
return _this.validForms(string, function(data) { | ||
return resolve(data); | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
@@ -472,0 +484,0 @@ |
{ | ||
"name": "node-wordnet", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Node.js interface for Wordnet", | ||
@@ -5,0 +5,0 @@ "main": "lib/wordnet.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18
673
67156