Monday 15 July 2013

Python, NLTK, can't import "parse_cfg"? -



Python, NLTK, can't import "parse_cfg"? -

so i'm working through tutorial involving python , nltk.

i'm working context free grammars.

i type next command , error...

>>> nltk import parse_cfg traceback (most recent phone call last): file "(stdin)", line 1, in (module) importerror: cannot import name parse_cfg

does have thought causing that? of cfg commands work, not one.

we updated api nltk 3. please read docs

the way access old nltk.parse_cfg() using cfg.fromstring()

example http://www.nltk.org/howto/grammar.html:

>>> nltk import cfg >>> grammar = cfg.fromstring(""" ... s -> np vp ... pp -> p np ... np -> det n | np pp ... vp -> v np | vp pp ... det -> 'a' | 'the' ... n -> 'dog' | 'cat' ... v -> 'chased' | 'sat' ... p -> 'on' | 'in' ... """) >>> grammar <grammar 14 productions> >>> grammar.start() s >>> grammar.productions() [s -> np vp, pp -> p np, np -> det n, np -> np pp, vp -> v np, vp -> vp pp, det -> 'a', det -> 'the', n -> 'dog', n -> 'cat', v -> 'chased', v -> 'sat', p -> 'on', p -> 'in']

python nltk context-free-grammar

No comments:

Post a Comment