I am trouble getting the Maltparser to work with Python NLTK.
Here is my code so far:
import nltk
os.environ["MALT_PARSER"] = "C:/Python34/maltparser-1.8.1"
os.environ["MALTPARSERHOME"] = "C:/Python34/maltparser-1.8.1"
parser8 = nltk.parse.malt.MaltParser(
... working_dir="C:/Python34/maltparser-1.8.1", mco="engmalt.poly-1.7",
... additional_java_args=['-Xmx512m'])
txt = "This is a test sentence"
parser8.raw_parse(txt)
I have downloaded and selected to used a pre-trained model.
This is the response I get:
runfile('C:/Anaconda/Lib/site-packages/nltk/malt2.py', wdir='C:/Anaconda/Lib/site-packages/nltk')
Traceback (most recent call last):
File "<ipython-input-38-73069e4ee673>", line 1, in <module>
runfile('C:/Anaconda/Lib/site-packages/nltk/malt2.py', wdir='C:/Anaconda/Lib/site-packages/nltk')
File "C:\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 580, in runfile
execfile(filename, namespace)
File "C:/Anaconda/Lib/site-packages/nltk/malt2.py", line 14, in <module>
parser8.raw_parse(txt)
File "C:\Anaconda\lib\site-packages\nltk\parse\malt.py", line 139, in raw_parse
return self.parse(words, verbose)
File "C:\Anaconda\lib\site-packages\nltk\parse\malt.py", line 126, in parse
return self.parse_sents([sentence], verbose)[0]
File "C:\Anaconda\lib\site-packages\nltk\parse\malt.py", line 114, in parse_sents
return self.tagged_parse_sents(tagged_sentences, verbose)
File "C:\Anaconda\lib\site-packages\nltk\parse\malt.py", line 194, in tagged_parse_sents
"code %d" % (' '.join(cmd), ret))
Exception: MaltParser parsing (java -Xmx512m -jar C:/Python34/maltparser-1.8.1\malt.jar -w C:/Python34/maltparser-1.8.1 -c engmalt.poly-1.7.mco -i C:\Python34\maltparser-1.8.1\malt_input.conllqgpbye -o C:\Python34\maltparser-1.8.1\malt_output.conllib1nx0 -m parse) failed with exit code 2
I have followed all the advice on this post How to use malt parser in python nltk.
Specifically:
-I downloaded the latest version of MaltParser.
-Using Pip, I uninstalled and re installed NLTK to get the latest version, which includes the addition in malt/py that allows 'additional_java_args' to be added as a parameter.
-I renamed the jar file to 'malt.jar'.
-I set an environmental variable pointing both MALT_PARSER and MALTPARSERHOME to the working directory.
-I've tried both the linear and poly pre-trained models.
-The code for malt.py can be found here http://www.nltk.org/_modules/nltk/parse/malt.html
If there isn't an apparent solution, how can I continue to debug this myself?
It seems that there's some slash (/ ) inconsistency with the exception raised. Nothing I do seems to fix it though.