jimkang / homophonizer

Gets homophones.
16 stars 1 forks source link

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

homophonizer.phoneme

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.