Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. tokens=nltk.word_tokenize(corpus)
  2. uni=nltk.ngrams(tokens,1)
  3. bi=nltk.ngrams(tokens,2)
  4.  
  5. countsU={}
  6. u=collections.Counter(uni)
  7. b=collections.Counter(bi)
  8.  
  9. for i,j in u.most_common():
  10. countsU[i[0]]=j # 'TOKEN': <NUM>
  11.  
  12. countsB = {}
  13. for i,j in b.most_common():
  14. countsB[i]=j
  15.  
  16. t='am'
  17. print(countsU[t)
  18.  
  19. Traceback (most recent call last):
  20. File "test.py", line 45, in <module>
  21. print(countsU['am'])
  22. KeyError: 'am'
  23.  
  24. Process finished with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement