Phonetics

Phonetic matching (sounds-like) matching can be done with the SoundEx, Metaphone or DoubleMetaphone algorithms

const natural = require('natural');
const metaphone = new natural.Metaphone();
const soundEx = new natural.SoundEx();

const wordA = 'phonetics';
const wordB = 'fonetix';

To test the two words to see if they sound alike:

if(metaphone.compare(wordA, wordB))
    console.log('they sound alike!');

The raw phonetics are obtained with process():

console.log(metaphone.process('phonetics'));

A maximum code length can be supplied:

console.log(metaphone.process('phonetics', 3));

DoubleMetaphone deals with two encodings returned in an array. This feature is experimental and subject to change:

const natural = require('natural');
const dm = natural.DoubleMetaphone();

const encodings = dm.process('Matrix');
console.log(encodings[0]);
console.log(encodings[1]);

The raw phonetics are obtained with phonetics():

console.log('phonetics'.phonetics());

Full text strings can be tokenized into arrays of phonetics (much like how tokenization-to-arrays works for stemmers):

console.log('phonetics rock'.tokenizeAndPhoneticize());

Same module operations applied with SoundEx:

if(soundEx.compare(wordA, wordB))
    console.log('they sound alike!');