Is there a ready-to-use English grammar that I can just load it and use in NLTK? I've searched around examples of parsing with NLTK, but it seems like that I have to manually specify grammar before parsing a sentence.
Thanks a lot!
A grammar consists of a start state and a set of productions. The set of terminals and nonterminals is implicitly specified by the productions. If you need efficient key-based access to productions, you can use a subclass to implement it.
In order to parse natural language data, researchers must first agree on the grammar to be used. The choice of syntax is affected by both linguistic and computational concerns; for instance some parsing systems use lexical functional grammar, but in general, parsing for grammars of this type is known to be NP-complete.
NLTK Parsers. Classes and interfaces for producing tree structures that represent the internal organization of a text. This task is known as “parsing” the text, and the resulting tree structures are called the text's “parses”.
Parser GeneratorsThey take in a grammar as input and produce Java code to parse input. And they can handle more grammars than a recursive descent parser can. There is much more to building parsers than we can cover in this course.
You can take a look at pyStatParser, a simple python statistical parser that returns NLTK parse Trees. It comes with public treebanks and it generates the grammar model only the first time you instantiate a Parser object (in about 8 seconds). It uses a CKY algorithm and it parses average length sentences (like the one below) in under a second.
>>> from stat_parser import Parser >>> parser = Parser() >>> print parser.parse("How can the net amount of entropy of the universe be massively decreased?") (SBARQ (WHADVP (WRB how)) (SQ (MD can) (NP (NP (DT the) (JJ net) (NN amount)) (PP (IN of) (NP (NP (NNS entropy)) (PP (IN of) (NP (DT the) (NN universe)))))) (VP (VB be) (ADJP (RB massively) (VBN decreased)))) (. ?))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With