Computing a phonetic code
If we're dealing with a corpus of English words, then we can categorize them into phonetic codes to see how similar they sound. Phonetic codes work for any alphabetical strings, not just actual words. We will use the Text.PhoneticCode
package to compute the Soundex and Phoneix phonetic codes. The package documentation can be found on Hackage at http://hackage.haskell.org/package/phonetic-code.
Getting ready
Install the phonetic code library from Cabal as follows:
$ cabal install phonetic-code
How to do it...
Import the phonetic code functions as follows:
import Text.PhoneticCode.Soundex (soundexNARA, soundexSimple) import Text.PhoneticCode.Phonix (phonix)
Define a list of similar-sounding words as follows:
ws = ["haskell", "hackle", "haggle", "hassle"]
Test out the phonetic codes on these words, as shown in the following code snippet:
main :: IO () main = do print $ map soundexNARA ws print $ map soundexSimple ws print $ map phonix ws
The output will be printed as...