T4: Use the State_union anticipate library to access the State of the Union address text. Statistical women,men,people changes over time
# # from Nltk.corpus import Brown as Bn # # from Nltk.corpus import state_union as Su # # CFD=NLTK. Conditionalfreqdist ((Target,fileid[:4]) for Fileid in Su.fileids () for W-Su.words (Fileid) # # for Target in [' Men ', ' wom En ', ' people '] if W.lower (). StartsWith (target)) # # Cfd.plot ()
T13. What is the percentage of a noun that has no inferior word in the synonym set? You can use Wn.all_synsets (' n ') to get synonyms for all names.
Import nltkfrom Nltk.corpus import WordNet as Wnalln=wn.all_synsets (' n ') total=0;sum1=0for i in Alln: total+=1 Hp=i.hyponyms () # # #下位词 if Len (HP) ==0: sum1+=1print (Sum1/total)
Results: 0.7967119283931072
T15
Python natural language processing Part two exercises