chatter-0.5.0.0: A library of simple NLP algorithms.

Safe HaskellNone
LanguageHaskell2010

NLP.Extraction.Examples.ParsecExamples

Description

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"))])])])]))]

Synopsis

Documentation

findClause :: Extractor Tag (ChunkOr Chunk Tag) Source

Find a clause in a larger collection of text.

findClause skips over leading tokens, if needed, to locate a clause.