title: Python NLTK named entities
body: <p>I am new to NLTK. I have a text file which contains text about medicines and their side effects. so I need to extract the medicine name and the names of side effects.</p>
  
  <p>towards this I have written this code</p>
  
  <pre><code>import sys, re, nltk, pprint
  x = "Allegra (fexofenadine hydrochloride) is an antihistamine used to 
       treat allergic symptoms of seasonal allergic rhinitis (sneezing, 
       runny nose, itchy or watery eyes), and urticaria (hives). Allegra is 
       available as a generic drug termed fexofenadine hydrochloride. 
       Allegra is used in adults and children (2 years and older for 
       allergies, 6 months and older for hives) for the control and 
       reduction of the above symptoms. Some common side effects of Allegra
       include GI symptoms of nausea or diarrhea, muscle or back discomfort
       or pain, sleepiness, and menstrual cramps."
  data = nltk.word_tokenize(x)
  tagged = nltk.pos_tag(data)
  namedEnt = nltk.ne_chunk(tagged, binary=True)
  </code></pre>
  
  <p>I get a very complex output </p>
  
  <pre><code>Tree('S', [Tree('NE', [('Allegra', 'NNP')]), ('(', ':'), 
      ('fexofenadine', 'NN'), ('hydrochloride', 'NN'), (')', ':'), 
      ('is', 'VBZ'), ('an', 'DT'), ('antihistamine', 'NN'), 
      ('used', 'VBN'), ('to', 'TO'), ('treat', 'VB'), ('allergic', 'JJ'), 
      ('symptoms', 'NNS'), ('of', 'IN'), ('seasonal', 'JJ'), 
      ('allergic', 'NN'), ('rhinitis', 'NNS'), ('(', ':'), 
      ('sneezing', 'VBG'), (',', ','), ('runny', 'JJ'), ('nose', 'NN'), 
      (',', ','), ('itchy', 'JJ'), ('or', 'CC'), ('watery', 'NN'), 
      ('eyes', 'NNS'), (')', ':'), (',', ','), ('and', 'CC'), 
      ('urticaria', 'VB'), ('(', ':'), ('hives', 'NNS'), (')', 'VBP'),
      ('.', '.'), ('Allegra', 'NNP'), ('is', 'VBZ'), ('available', 'JJ'), 
      ('as', 'IN'), ('a', 'DT'), ('generic', 'JJ'), ('drug', 'NN'), 
      ('termed', 'VBD'), ('fexofenadine', 'NN'), ('hydrochloride', 'NN'), 
      ('.', '.'), ('Allegra', 'NNP'), ('is', 'VBZ'), ('used', 'VBN'), 
      ('in', 'IN'), ('adults', 'NNS'), ('and', 'CC'), ('children', 'NNS'), 
      ('(', ':'), ('2', 'CD'), ('years', 'NNS'), ('and', 'CC'), 
      ('older', 'JJR'), ('for', 'IN'), ('allergies', 'NNS'), (',', ','), 
      ('6', 'CD'), ('months', 'NNS'), ('and', 'CC'), ('older', 'JJR'), 
      ('for', 'IN'), ('hives', 'NNS'), (')', ':'), ('for', 'IN'), 
      ('the', 'DT'), ('control', 'NN'), ('and', 'CC'), ('reduction', 'NN'), 
      ('of', 'IN'), ('the', 'DT'), ('above', 'JJ'), ('symptoms', 'NNS'), 
      ('.', '.'), ('Some', 'DT'), ('common', 'JJ'), ('side', 'NN'), 
      ('effects', 'NNS'), ('of', 'IN'), ('Allegra', 'NNP'), 
      ('include', 'VBP'), ('GI', 'NNP'), ('symptoms', 'NNS'), ('of', 'IN'), 
      ('nausea', 'NN'), ('or', 'CC'), ('diarrhea', 'NN'), (',', ','), 
      ('muscle', 'NN'), ('or', 'CC'), ('back', 'RB'), ('discomfort', 'JJ'), 
      ('or', 'CC'), ('pain', 'NN'), (',', ','), ('sleepiness', 'NN'), 
      (',', ','), ('and', 'CC'), ('menstrual', 'JJ'), ('cramps', 'NNS'), 
      ('.', '.')])
  </code></pre>
  
  <p>Now this is really confusing because what I was hoping to get was</p>
  
  <ol>
  <li>Allegra</li>
  <li>nausea</li>
  <li>diarrhea, </li>
  <li>Muscle or back discomfort or pain, </li>
  <li>sleepiness, </li>
  <li>menstrual cramps</li>
  </ol>
  
  <p>So how do I narrow down to the data which I am looking for?</p>