Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

English grammar for parsing in NLTK

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!

like image 825
roboren Avatar asked May 24 '11 19:05

roboren


People also ask

How do you define grammar in NLTK?

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.

Which grammar is used for parsing?

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.

What is parsing in NLTK?

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”.

Do we use grammar in parser?

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.


1 Answers

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))))   (. ?)) 
like image 135
emilmont Avatar answered Oct 13 '22 01:10

emilmont