python 2.7 - Clarify tag distinction in Python2.7, NLP Chapter5 -




i started learn python know more nlp. using steven bird's online book. in chapter 5,

>>>wsj = nltk.corpus.treebank.tagged_words(tagset='universal') >>>word_tag_fd = nltk.freqdist(wsj) [wt[0] (wt, _) in word_tag_fd.most_common() if wt[1] == 'verb'] ['is', 'said', 'are', 'was', 'be', 'has', 'have', 'will', 'says', 'would',  'were', 'had', 'been', 'could', "'s", 'can', 'do', 'say', 'make', 'may',  'did', 'rose', 'made', 'does', 'expected', 'buy', 'take', 'get', 'might',  'sell', 'added', 'sold', 'help', 'including', 'should', 'reported', ...] >>>cfd1 = nltk.conditionalfreqdist(wsj) >>> cfd1['yield'].most_common() [('verb', 28), ('noun', 20)] >>> cfd1['cut'].most_common() [('verb', 25), ('noun', 3)] 

i had managed follow example given. when started on next example,

>>>[w w in cfd1.conditions() if 'vbd' in cfd1[w] , 'vbn' in cfd1[w]] ['asked', 'accelerated', 'accepted', 'accused', 'acquired', 'added',  'adopted', ...] 

i did empty result instead of example shown. later,

>>>idx1 = wsj.index(('kicked', 'vbd')) 

i did this:

traceback (most recent call last):     file"<stdin>", line 1, in <module>     file "/usr/lib/python2.7/dist-packages/nltk/util.py", line 734, in index     raise valueerror('index(x): x not in list') valueerror: index(x): x no in list 

i had tried find if had faced similar problem. sadly, don't have any. can me later on, using .conditions() , .index() lot.

thanks.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -