1

I am trying to set several options for the StanfordDependencyParser that I am using with NLTK:

from nltk.parse.stanford import StanfordDependencyParser
os.environ['CLASSPATH'] = "path/to/stanford-parser-3.9.1-models.jar"
sdp = StanfordDependencyParser('path/to/stanford-parser-3.9.1-models.jar', corenlp_options=['-retainTmpSubcategories', '-originalDependencies'])

However, I get

raise OSError('Java command failed : ' + str(cmd))
OSError: Java command failed : ['C:\\Program Files\\Java\\jdk-11\\bin\\java.exe', '-mx1000m', '-cp', '\\stanford-parser.jar', 'edu.stanford.nlp.parser.lexparser.LexicalizedParser', '-model', 'edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz', '-sentences', 'newline', '-outputFormat', 'conll2007', '-encoding', 'utf8', ['-retainTmpSubcategories', '-originalDependencies'], 'C:\\Users\\...']

(I removed some of the paths to make it clearer.)

If I only use

sdp = StanfordDependencyParser('path/to/stanford-parser-3.9.1-models.jar', corenlp_options=['-retainTmpSubcategories'])

or

sdp = StanfordDependencyParser('path/to/stanford-parser-3.9.1-models.jar', corenlp_options=['-originalDependencies'])

it works well...

I also looked at the nltk code, the _execute function which is used to compute the commande line

def _execute(self, cmd, input_, verbose=False):
    encoding = self._encoding
    cmd.extend(['-encoding', encoding])
    if self.corenlp_options:
        cmd.append(self.corenlp_options)

Does this mean that I can only put 1 single option in the corenlp_options argument??

Thank you for your help!!

Wendy
  • 791
  • 1
  • 5
  • 8
  • Avoid that, use this instead https://stackoverflow.com/questions/13883277/stanford-parser-and-nltk/51981566#51981566 – alvas Oct 11 '18 at 11:19

1 Answers1

0

I kept on looking for a solution but it seems that there is no 'simple' one. The solution I have found and that worked for me, is to directly modify stanford.py file in the nltk\parse\ folder. I replaced

cmd.append(self.corenlp_options)

with

cmd.extend(self.corenlp_options)

and no more exception raised although I doubt this is the best thing to do...

Wendy
  • 791
  • 1
  • 5
  • 8