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:
- Import the parts of speech library and the pack function:
import NLP.POS import Data.Text (pack)
- Obtain the default tagger provided by the library:
main = do tagger <- defaultTagger
- Feed the
tag
function a tagger and a text to see the corresponding parts of speech per each word:let text =...