Safe Haskell | None |
---|---|
Language | Haskell2010 |
Example parsing with Parsec.
This example shows how the following grammar, from NLTK, can be implemented in Chatter, using Parsec-based Information Extraction patterns:
grammar = r""" NP: {<DT|JJ|NN.*>+} # Chunk sequences of DT, JJ, NN PP: {<IN><NP>} # Chunk prepositions followed by NP VP: {<VB.*><NP|PP|CLAUSE>+$} # Chunk verbs and their arguments CLAUSE: {<NP><VP>} # Chunk NP, VP """
> import NLP.Extraction.Examples.ParsecExamples > import Text.Parsec.Prim > tgr <- defaultTagger > map (parse findClause "interactive") $ tag tgr "Mary saw the cat sit on the mat." [Right (Chunk_CN (Chunk C_CL [Chunk_CN (Chunk C_NP [POS_CN (POS AT (Token "the")),POS_CN (POS NN (Token "cat"))]),Chunk_CN (Chunk C_VP [POS_CN (POS VB (Token "sit")),Chunk_CN (Chunk C_PP [POS_CN (POS IN (Token "on")),Chunk_CN (Chunk C_NP [POS_CN (POS AT (Token "the")),POS_CN (POS NN (Token "mat"))])])])]))]