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

Classifying the parts of speech of words


This recipe will demonstrate how to identify the parts of speech of each word in a sentence. We will be using a handy library called chatter, which contains very useful Natural Language Processing (NLP) tools. It can be obtained from Hackage at http://hackage.haskell.org/package/chatter.

NLP is the study of human language embedded in a machine. Our naturally spoken or written language may seem obvious to us in our day-to-day lives, but producing meaning out of words is still a difficult task for computers.

Getting ready

Install the NLP library using cabal:

cabal install chatter

How to do it…

In a new file, which we name Main.hs, enter the following source code:

  1. Import the parts of speech library and the pack function:

    import NLP.POS
    import Data.Text (pack)
  2. Obtain the default tagger provided by the library:

    main = do
    tagger <- defaultTagger
  3. Feed the tag function a tagger and a text to see the corresponding parts of speech per each word:

    let text = pack "The...