Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is nltk.grammar.CFG supported? #11

Open
loretoparisi opened this issue Nov 21, 2016 · 1 comment
Open

Is nltk.grammar.CFG supported? #11

loretoparisi opened this issue Nov 21, 2016 · 1 comment

Comments

@loretoparisi
Copy link

Supposed to have

from nltk.grammar import CFG
    grammar = CFG.fromstring("""
    # Grammatical productions.
        S -> NP VP
        NP -> Det N PP | Det N
        VP -> V NP PP | V NP | V
        PP -> P NP
    # Lexical productions.
        NP -> 'I'
        Det -> 'the' | 'a'
        N -> 'man' | 'park' | 'dog' | 'telescope'
        V -> 'ate' | 'saw'
        P

will pyStatParser output a CFG string for the grammar?

@loretoparisi
Copy link
Author

loretoparisi commented Nov 22, 2016

Like getting the PCFG grammar

grammar=parser.pcfg

The problem is that I get this error

AttributeError: PCFG instance has no attribute 'productions'

when passing this grammar to the RecursiveDescentApp NLTK example:
http://www.nltk.org/_modules/nltk/app/rdparser_app.html

like

    parser = Parser()
    text="How can the net amount of entropy of the universe be massively decreased?"
    sent=text.split()
    tree = parser.parse(text)
    print tree
    grammar = parser.pcfg

    RecursiveDescentApp(grammar, sent).mainloop()

that fails with

Traceback (most recent call last):
  File "wordstree.py", line 906, in <module>
    app()
  File "wordstree.py", line 903, in app
    RecursiveDescentApp(grammar, sent).mainloop()
  File "wordstree.py", line 120, in __init__
    self._init_grammar(self._top)
  File "wordstree.py", line 166, in _init_grammar
    self._productions = list(self._parser.grammar().productions())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant