Current File : //lib/node_modules/npm-name-cli/node_modules/thesaurus/lib/thesaurus.js |
// Generated by CoffeeScript 1.6.3
(function() {
var Thesaurus, fs,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
fs = require('fs');
Thesaurus = (function() {
function Thesaurus(database) {
this.database = database != null ? database : {};
}
Thesaurus.prototype.load = function(inputFile) {
var columns, current, input, line, syn, _i, _j, _len, _len1, _ref, _ref1;
input = fs.readFileSync(inputFile, "utf8");
current = {
meanings: 0,
word: void 0
};
_ref = input.split('\n').slice(1);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
columns = line.split('|');
if (current.meanings === 0) {
current.word = columns[0];
current.meanings = Number(columns[1]);
this.database[current.word] = [];
} else {
--current.meanings;
_ref1 = columns.slice(1);
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
syn = _ref1[_j];
if ((syn == null) || syn === "") {
continue;
}
syn = syn.trim();
if (__indexOf.call(this.database[current.word], syn) >= 0) {
continue;
}
this.database[current.word].push(syn);
}
}
}
return this;
};
Thesaurus.prototype.reset = function() {
return this.database = [];
};
Thesaurus.prototype.replace = function(inputFile) {
this.reset();
return this.load(inputFile);
};
Thesaurus.prototype.find = function(key) {
var _ref;
return (_ref = this.database[key]) != null ? _ref : [];
};
Thesaurus.prototype.get = function() {
return this.database;
};
Thesaurus.prototype.toJson = function() {
return JSON.stringify(this.database, void 0, 2);
};
return Thesaurus;
})();
module.exports = new Thesaurus(require('./th_en_US_new'));
}).call(this);