penntreebank-megaparsec: Parser combinators for trees in the Penn Treebank format

[ bsd3, library, natural-language-processing, parsing ] [ Propose Tags ] [ Report a vulnerability ]

This Haskell package provides parsers for syntactic trees annotated in the Penn Treebank format, powered by Megaparsec.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.2.0
Dependencies base (>=4.11 && <5), containers (>=0.5 && <0.7), megaparsec (>=8.0 && <9), mtl (>=2.2.2 && <3), template-haskell (>=2.13 && <3), transformers (>=0.4 && <0.6) [details]
Tested with ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.1
License BSD-3-Clause
Copyright 2020 Nori Hayashi
Author Nori Hayashi
Maintainer Nori Hayashi <net@hayashi-lin.net>
Category Parsing, Natural Language Processing
Home page https://github.com/aslemen/penntreebank-megaparsec#readme
Bug tracker https://github.com/aslemen/penntreebank-megaparsec/issues
Source repo head: git clone https://github.com/aslemen/penntreebank-megaparsec
Uploaded by twotrees12 at 2020-05-14T10:17:53Z
Distributions
Downloads 341 total (9 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-05-14 [all 1 reports]

Readme for penntreebank-megaparsec-0.2.0

[back to package description]

penntreebank-megaparsec :: Megaparsec parsers for trees in the Penn Treebank format

Travis CI build :: master

This Haskell package provides parsers for syntactic trees annotated in the Penn Treebank format, powered by Megaparsec.

It supports vertical composition of custom label parsers with tree parsers, which means you can customize your label parsers and use these parsers to perform parsing of labels at the same time as that of trees. For the following example of categorial grammar trees,

(A/B (B He)
     (B\<A/B> thinks))

the result of tree parsing is:

Node "A/B" [
    Node "B" [
        Node "He" []
    ], 
    Node "B\<A/B>" [
        Node "thinks" []
    ]
] 

which you can make followed by a secondary parsing of labels (= categories):

Node (CatRight (Atom B) (Atom A)) [
    Node (Atom B) [
        Node (Lex "He") []
    ], 
    Node (CatLeft (Atom B) (CatRight (Atom B) (Atom A))) [
        Node (Lex "thinks") []
    ]
] 

Usage

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultiParamTypeClasses #-}

import Data.Tree.Parser.Penn.Megaparsec.Char as TC
import Data.Text (Text)
import Text.Megaparsec as MegaP

-- define the node type
data PennNode = NonTerm Text | Term Text deriving (Show)

-- define the node parsers
instance {-# OVERLAPS #-} TC.ParsableAsTerm Text PennNode where
    pNonTerm = NonTerm <$> MegaP.takeRest
    pTerm = Term <$> MegaP.takeRest

-- specify and disambiguate the type of the input stream 
parser :: (Monad m) => TC.PennTreeParserT Text m PennNode
parser = TC.pTree

main :: IO ()
main = MegaP.parseTest parser "(A (B C (D E)))"