Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...

  1. Import the phonetic code functions as follows:

    import Text.PhoneticCode.Soundex (soundexNARA, soundexSimple)
    import Text.PhoneticCode.Phonix (phonix)
  2. Define a list of similar-sounding words as follows:

    ws = ["haskell", "hackle", "haggle", "hassle"]
  3. 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
  4. The output will be printed as...