Parts of Speech Dictionary Trie
About
This is a module that builds a dictionary trie from user input or a file. It matches a word with its part of speech. For example, a dictionary trie is created in this format:
{"k":{"u":{"d":{"o":{"s":["kudos","NNS"]}},"r":{"t":{"a":["kurta","NN"]}}},"v":{"e":{"t":{"c":{"h":["kvetch","NN"]}}}}},"K":{"u":{"r":{"d":["Kurd","NNP"]},"w":{"a":{"i":{"t":{"i":["Kuwaiti","JJ"]}}}}}}}
You can build a trie from a list of 83,000 words in ~10 secs and the lookup is fast. You may want to use the code in order to build your own trie with other associated data, i.e. definitions, word origins, etc.
It uses the pos-js utility written by Percy Wegmann to parse words into their parts of speech.
How to install
$ npm install pos-dict-trie
Usage
const trie = ;const fs = ; // Builds initial trie from user inputlet Trie = a: b: "ab" "NN";console; // => { a: { b: ["ab", "NN"]}} // Builds trie from a filelet anotherTrie = {} fileToRead = path; anotherTrie // File must be in single-lined format ; // => Returns your trie in a JSON string // Writes a built trie into a filelet fileToWriteInto = path; Promise; // Search the trie and returns the part of speechlet t = anotherTrie; anotherTrie; // Multiple searches at oncePromiseall anotherTrie anotherTrie anotherTrie; // The two methods below are intended for small sized tries. // Add word to the trieanotherTrie; // => returns the trie with the word added // Removes word from the trieanotherTrie // => returns the trie with the word removed