title: To find synonyms, definitions and example sentences using WordNet
body: <p>I need to take an input text file with a one word. I then need to find the lemma_names, definition and examples of the synset of the word using wordnet. I have gone through the book : "Python Text Processing with NLTK 2.0 Cookbook" and also "Natural Language Processing using NLTK" to help me in this direction. Though I have understood how this can be done using the terminal, I'm not able to do the same using a text editor.</p>
  
  <p>For example, if the input text has the word "flabbergasted", the output needs to be in this fashion:</p>
  
  <p>flabbergasted
  (verb) flabbergast, boggle, bowl over - overcome with amazement ; "This boggles the mind!"
  (adjective) dumbfounded , dumfounded , flabbergasted , stupefied , thunderstruck , dumbstruck , dumbstricken - as if struck dumb with astonishment and surprise; "a circle of policement stood dumbfounded by her denial of having seen the accident"; "the flabbergasted aldermen were speechless"; "was thunderstruck by the news of his promotion"</p>
  
  <p>The synsets, definitions and example sentences are obtained from WordNet directly!</p>
  
  <p>I have the following piece of code:</p>
  
  <pre><code>
  from __future__ import division
  import nltk
  from nltk.corpus import wordnet as wn
  
  
  tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')
  fp = open("inpsyn.txt")
  data = fp.read()
  
  #to tokenize input text into sentences
  
  print '\n-----\n'.join(tokenizer.tokenize(data))# splits text into sentences
  
  #to tokenize the tokenized sentences into words
  
  tokens = nltk.wordpunct_tokenize(data)
  text = nltk.Text(tokens)
  words = [w.lower() for w in text]  
  print words     #to print the tokens
  
  for a in words:
      print a
  
  syns = wn.synsets(a)
  print "synsets:", syns
  
  for s in syns:
      for l in s.lemmas:
          print l.name
      print s.definition
      print s.examples
  
  </code></pre>
  
  <p>I get the following output:</p>
  
  <pre><code>
  flabbergasted
  
  ['flabbergasted']
  flabbergasted
  synsets: [Synset('flabbergast.v.01'), Synset('dumbfounded.s.01')]
  flabbergast
  boggle
  bowl_over
  overcome with amazement
  ['This boggles the mind!']
  dumbfounded
  dumfounded
  flabbergasted
  stupefied
  thunderstruck
  dumbstruck
  dumbstricken
  as if struck dumb with astonishment and surprise
  ['a circle of policement stood dumbfounded by her denial of having seen the accident', 'the flabbergasted aldermen were speechless', 'was thunderstruck by the news of his promotion']
  </code></pre>
  
  <p>Is there a way to retrieve the part of speech along with the group of lemma names?</p>