npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pos-dict-trie

v1.1.0

Published

Parts of speech of dictionary words organized into a trie for fast uplook.

Downloads

7

Readme

Parts of Speech Dictionary Trie

Build Status

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 = require('pos-dict-trie');
const fs = require('fs');

// Builds initial trie from user input
let Trie = new trie.DictionaryTrie({ a: { b: ["ab", "NN"]}});
console.log(newTrie.getTrie()); // => { a: { b: ["ab", "NN"]}}

// Builds trie from a file
let anotherTrie = new trie.DictionaryTrie({}),
	fileToRead = path.join(__dirname, './yourFileToRead.txt');

anotherTrie.buildTrieFromFile(fileToRead) // File must be in single-lined format
	.then(result => console.log(result)); // => Returns your trie in a JSON string

// Writes a built trie into a file
let fileToWriteInto = path.join(__dirname, './yourFileToWriteInto.json');

Promise.resolve(
	anotherTrie.buildTrieFromFile(fileToRead)
).then(() => {
	anotherTrie.writeTrieToFile(fileToWriteInto).then(
		(result) => console.log(result), // => success message 
		(error) => console.log(error) // => error message
	);
});

// Search the trie and returns the part of speech
let t = anotherTrie.getTrie();

anotherTrie.searchTrie(t, 'word').then( 
	(result) => console.log(result), // => part of speech of the word
	(error) => console.log(error) // => Will return "word not found" if not
);

// Multiple searches at once
Promise.all([
	anotherTrie.searchTrie(t, 'walk'),
	anotherTrie.searchTrie(t, 'shoes'),
	anotherTrie.searchTrie(t, 'readily'),
]).then(result => {
	console.log(result) // => returns all three in an array ['VB', 'NN', 'RB']
});

// The two methods below are intended for small sized tries.

// Add word to the trie
anotherTrie.addToTrie('aWordToAdd'); // => returns the trie with the word added

// Removes word from the trie
anotherTrie.removeFromTrie('aWordToRemove') // => returns the trie with the word removed