Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. for sentence in tokenized:
  2.  
  3. pos_sentences = st.tag(sentence)
  4.  
  5. #print pos_sentences
  6.  
  7. tmp = []
  8.  
  9. # mapping nltk pos tags to wordnet pos tags
  10.  
  11. for tok, pos in pos_sentences:
  12.  
  13. lower_pos = pos[0].lower()
  14.  
  15. if lower_pos in ['a', 'n', 'v', 'r', 's']:
  16.  
  17. res = wordnet.synsets(tok, lower_pos)
  18.  
  19. if len(res) > 0:
  20.  
  21. a = res[0]
  22.  
  23. else:
  24.  
  25. a = "[{0}, {1}]".format(tok, pos)
  26.  
  27.  
  28. tmp.append(a)
  29. #print a
  30.  
  31. wordnet_sense.append(tmp)
  32.  
  33.  
  34. print wordnet_sense
  35.  
  36. >>> [['[angry, JJ]'], [Synset('anger.n.01')], [Synset('happiness.n.01')], ['[sad, JJ]']]
  37.  
  38. for i in wordnet_sense:
  39. for v in i:
  40.  
  41. wna = WNAffect('wordnet-1.6/', 'wn-domains-3.2/')
  42. emo = wna.get_emotion(v[0], v[1])
  43.  
  44. print emo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement