Converting stanford dependencies in numbered format
<p>I am using <code>Stanford dependency parser</code> and the I get the following output of the sentence</p>

<blockquote>
  <p>I shot an elephant in my sleep</p>
</blockquote>

<pre><code>&gt;&gt;&gt;python dep_parsing.py 
[((u'shot', u'VBD'), u'nsubj', (u'I', u'PRP')), ((u'shot', u'VBD'), u'dobj', (u'elephant', u'NN')), ((u'elephant', u'NN'), u'det', (u'an', u'DT')), ((u'shot', u'VBD'), u'nmod', (u'sleep', u'NN')), ((u'sleep', u'NN'), u'case', (u'in', u'IN')), ((u'sleep', u'NN'), u'nmod:poss', (u'my', u'PRP$'))]
</code></pre>

<p><strong>However, I want the numbered tokens as output just as <a href="http://nlp.stanford.edu:8080/parser/" rel="nofollow">it is here</a></strong></p>

<pre><code>nsubj(shot-2, I-1)
  root(ROOT-0, shot-2)
  det(elephant-4, an-3)
  dobj(shot-2, elephant-4)
  case(sleep-7, in-5)
  nmod:poss(sleep-7, my-6)
  nmod(shot-2, sleep-7)
</code></pre>

<p>Here is my code till now.</p>

<pre><code>  from nltk.parse.stanford import StanfordDependencyParser
  stanford_parser_dir = 'stanford-parser/'
  eng_model_path = stanford_parser_dir + "stanford-parser-models/edu/stanford/nlp/models/lexparser/englishRNN.ser.gz"
  my_path_to_models_jar = stanford_parser_dir + "stanford-parser-3.5.2-models.jar"
  my_path_to_jar = stanford_parser_dir + "stanford-parser.jar"

  dependency_parser = StanfordDependencyParser(path_to_jar=my_path_to_jar, path_to_models_jar=my_path_to_models_jar)

  result = dependency_parser.raw_parse('I shot an elephant in my sleep')
  dep = result.next()
  a = list(dep.triples())
  print a
</code></pre>

<p>How can I have such an output?</p>

<p>Write a recursive function that traverses your tree.  As a first pass, just try assigning the numbers to the words.</p>

python nlp nltk stanford-nlp dependency-parsing