Book Image

Haskell Data Analysis cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis cookbook

By: Nishant Shukla

Overview of this book

Step-by-step recipes filled with practical code samples and engaging examples demonstrate Haskell in practice, and then the concepts behind the code. This book shows functional developers and analysts how to leverage their existing knowledge of Haskell specifically for high-quality data analysis. A good understanding of data sets and functional programming is assumed.
Table of Contents (14 chapters)
13
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...