I am trying to run Stanford Parser in NLTK in Windows. I am doing it in python. My code for the same is
import os
from nltk.parse import stanford
os.environ['JAVAHOME'] = 'C:/Program Files/Java/jdk1.8.0_25/bin'
os.environ['STANFORD_PARSER'] = 'C:/jars'
os.environ['STANFORD_MODELS'] = 'C:/jars'
parser =stanford.StanfordParser(model_path="C:/Users/pc/Desktop/Project/englishPCFG.ser.gz")
sentences = parser.raw_parse_sents(("Hello, My name is Melroy.", "What is your name?"))
for i in sentences:
print i
This is the output it gave
listiterator object at 0x03FB6150
listiterator object at 0x03FB61B0
I am looking for the following output:
Tree('ROOT', [Tree('S', [Tree('INTJ', [Tree('UH', ['Hello'])]), Tree(',', [',']), Tree('NP', [Tree('PRP$', ['My']), Tree('NN', ['name'])]), Tree('VP', [Tree('VBZ', ['is']), Tree('ADJP', [Tree('JJ', ['Melroy'])])]), Tree('.', ['.'])])]), Tree('ROOT', [Tree('SBARQ', [Tree('WHNP', [Tree('WP', ['What'])]), Tree('SQ', [Tree('VBZ', ['is']), Tree('NP', [Tree('PRP$', ['your']), Tree('NN', ['name'])])]), Tree('.', ['?'])])])]
raw_parse_sents
returns a list of listiterators. You can iterate through them like this:If you want the exact output format you quoted, you can do it like this: