alvations

How to access Senseval data from NLTK?

Nov 28th, 2012
943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import nltk
  2. #from nltk.corpus import senseval as ss
  3.  
  4. # This shows what files from senseval are in NLTK. sadly there's only 4.
  5. print nltk.corpus.senseval.fileids()
  6.  
  7. # This yields the line by line xml version of the senseval data.
  8. # note the "\n" are also in each line.
  9. print nltk.corpus.senseval.raw()
  10.  
  11. # Most probably the individual instances are what you wanted to get.
  12. for id in nltk.corpus.senseval.fileids():
  13.   # This access all instances from each file.
  14.   insts = nltk.corpus.senseval.instances(id)
  15.   # Looping through the instances.
  16.   for i in insts:
  17.     print i
  18.     # SensevalInstance returns (word, position, context, senses),
  19.     # so you can each variable as such:
  20.     print i.word, i.position, i.senses
  21.     print i.context
Advertisement
Add Comment
Please, Sign In to add comment