Phonetics

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

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

var wordA = 'phonetics';
var 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:

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

var 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!');