There exists a python wrapper for the Stanford parser, you can get it here.
It will give you the dependency tree of your sentence.
EDIT:
I assume here that you launched a server as said here. I also assume that you have installed jsonrpclib.
The following code will produce what you want:
import json
import jsonrpclib
class StanfordNLP:
def __init__(self, port_number=8080):
self.server = jsonrpclib.Server("http://localhost:%d" % port_number)
def parse(self, text):
return json.loads(self.server.parse(text))
nlp = StanfordNLP()
sentence = 'I shot an elephant in my sleep'
result = nlp.parse(sentence)
result['sentences'][0]['indexeddependencies']
>>>
['root', 'ROOT-0', 'shot-2']
['nsubj', 'shot-2', 'I-1']
['det', 'elephant-4', 'an-3']
['dobj', 'shot-2', 'elephant-4']
['poss', 'sleep-7', 'my-6']
['prep_in', 'shot-2', 'sleep-7']
EDIT2:
Now, the Stanford parser has an HTTP API. Thus, the python wrapper is not necessary anymore.