thesaurus
Version:
a thesaurus of words, it contains english by default but it can be used with your own data file
34 lines (30 loc) • 918 B
text/coffeescript
fs = require 'fs'
class Thesaurus
constructor: (={}) ->
load: (inputFile) ->
input = fs.readFileSync inputFile, "utf8"
current =
meanings: 0
word: undefined
for line in input.split('\n')[1...]
columns = line.split '|'
if current.meanings is 0
current.word = columns[0]
current.meanings = (Number) columns[1]
[current.word] = []
else
--current.meanings
for syn in columns[1...]
continue if !syn? or syn is ""
syn = syn.trim()
continue if syn in [current.word]
[current.word].push syn
@
reset: -> = []
replace: (inputFile) ->
this.reset()
this.load(inputFile)
find: (key) -> [key] ? []
get: ->
toJson: -> JSON.stringify , undefined, 2
module.exports = new Thesaurus require './th_en_US_new'