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

homophonizer

v1.1.0

Published

Gets homophones.

Downloads

31

Readme

homophonizer

This module finds homophones for words. For example, here is code to homophones for "acorn":

var hph = require('homophonizer');
var homophonizer = hph.metaphone.createHomophonizer();
homophonizer.getHomophones('acorn', function done(error, results) {
  // Error handling goes here.
  console.log(results);
});

Results:

{
  primary: [
    'ACHORN',
    'ACORN',
    'AGOURON',
    'AKRON',
    'EKERN',
    'OGREN',
    'UKRAINE'
  ],
  secondary: [
    'ACHORN',
    'ACORN',
    'AGOURON',
    'AKRON',
    'EICHHORN',
    'EICHORN',
    'EKERN',
    'OGREN',
    'UKRAINE'
  ]
}

Installation

npm install homophonizer

If you need to rebuild the metaphone and phoneme databases:

cd node_modules/homophonizer
make builddbs

That last step is important. There will be nothing in the databases in the it searches without it.

Metaphone and phonemes

homophonizer has two ways of generating homophones. The first is via the Double Metaphone algorithm as implemented by the double-metaphone module. Double Metaphone is a way of phonetically encoding words. homophonizer uses those encodings to find words with the matching phonetic profiles as Double Metaphone sees it.

The other way is via phonemes. homophonizer uses the phonemes from the CMU Pronouncing Dictionary to profile words by their phonemes. Then, it finds phoneme sequences that are similar to each other and maps them back again to words.

The phoneme homophonizer is under the phoneme namespace. You can use it like so:

var hph = require('homophonizer');
var homophonizer = hph.phoneme.createHomophonizer();
homophonizer.getImperfectHomophones({
  word: 'shell',
  varyPhonemesAtPositions
},
function done(error, results) {
  // Error handling goes here.
  console.log(results);
});

Results:

[
  'SCHAAL',
  'SCHOLL',
  'SHOLL',
  'SHALL',
  'SHULL',
  'SCHALL',
  'SHAUL',
  'SHAULL',
  'SHAWL',
  'SHEIL',
  'SHIRL',
  'SHALE',
  'SCHILL',
  'SHILL',
  'SCHEEL',
  'SCHEELE',
  'SCHIEL',
  'SCHIELE',
  'SHE\'LL',
  'SHIEL',
  'SCHAUL',
  'SCHOLLE',
  'SCHUL',
  'SCHULL',
  'SCHUELE'
]

API

homophonizer.metaphone

  • createHomophonizer: Creates an object that'll get you homophones with the following methods:
    • getHomophones(word, done)
      • done is a callback with this signature: (error, results), where results is an object containing two arrays: primary and secondary, which contain the list of words found by searching primary metaphone codes and and the list of words found by searching secondary metaphone codes, respectively.
    • shutdown: This closes the database that the homophonizer searches. You need to close it before creating another metaphone homophonizer. (Now that I write this out, I'm not sure that the phoneme homophonizer shouldn't be a singleton.)
  • navigator
    • classifyPhoneme(phoneme): Tells you how a phoneme is classified. e.g. 'affricate', 'aspirate', etc.
    • getPhonemesInSameClass(phoneme): Tells you what other phonemes are in the same class (or family, if you want to think of it that way) as a phoneme.

homophonizer.phoneme

  • createHomophonizer: Creates an object that'll get you homophones with the following methods:
    • getHomophones(word, done): Gets homophones for a word you give it it. done is a callback with this signature: (error, results), where results is an object containing an array of the homophones. This method uses finds homophones by strictly matching phoneme profiles, so you often will not get that much back.
    • getImperfectHomophones(opts, done):
      • opts should contain:
        • word: The word you want to get homophones for.
        • varyPhonemesAtPositions: An array that tells it what phonemes in the word it's OK to not match exactly when looking for homophones. e.g. [0, 3, 4] tells it that potential homophones whose first, fourth, and fifth phonemes do not match word's first, fourth, and fifth phonemes.
      • done: Will be passed an error and an array of the resulting homophones.
    • shutdown: This closes the database that the homophonizer searches. You need to close it before creating another phoneme homophonizer.

Tests

Run tests with make test. You can run them more granularly with some targets in the Makefile and by running the scripts in tests directly. Just make sure you use the --ui tdd switch with mocha.

Tools

Over in the tools directory, there's various scripts you can use to find homophones, metaphones, and phonemes. The most useful ones (looking up homophones by phoneme and metaphone) can be called by a Makefile target:

make lookup WORD=leafy

License

MIT.