If you want to use the Stanford parser, use this:
import os
from nltk.parse import stanford
os.environ['STANFORD_PARSER'] = '/folder/with/standford/jars'
os.environ['STANFORD_MODELS'] = '/folder/with/standford/jars'
parser = stanford.StanfordParser(model_path="/location/of/the/englishPCFG.ser.gz")
print parser.raw_batch_parse(("Hello, My name is Melroy.", "What is your name?"))
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('.', ['?'])])])]
Note 1:
In this example both the parser & model jars are in the same folder.
Note 2:
- File name of stanford parser is: stanford-parser.jar
- File name of stanford models is: stanford-parser-x.x.x-models.jar
Note 3:
The englishPCFG.ser.gz file can be found inside the models.jar file (/edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz). Please use come archive manager to 'unzip' the models.jar file.