Reputation: 41
I've looked all over for an answer to this question, but haven't found an answer that suits my needs.
I'm trying to use the nltk wrapper for the MaltParser. It seems that there have been lots of people who have had problems with the nltk wrapper for MaltParser in t the past, but none I've found with the same error or the same fixes. Here is the code and here is the error:
import nltk
maltParser = nltk.parse.malt.MaltParser(parser_dirname="/home/owen/maltparser-1.7.2",
model_filename="engmalt.linear-1.7",
additional_java_args=['-Xmx512m'])
result = maltParser.parse_one('This is a test sentence'.split())
print result.tree()
Here is the error:
Exception: MaltParser parsing (java -Xmx512m -cp /home/owen/maltparser-1.7.2/lib/libsvm.jar:/home/owen/maltparser-1.7.2/malt.jar:/home/owen/maltparser-1.7.2/lib/log4j.jar:/home/owen/maltparser-1.7.2/maltparser-1.7.2.jar:/home/owen/maltparser-1.7.2/lib/liblinear-1.8.jar org.maltparser.Malt -c engmalt.linear-1.7 -i /tmp/malt_input.conll.ej6hqf -o /tmp/malt_output.conll.TZXpc2 -m parse) failed with exit code 1
Here are the things I've already tried all together and in different combinations:
FYI: I have already followed the steps on the following post:
Step by step to getting malt parser in NLTK to work?
There might be some other I've tried. I can't remember. What I really want to know is what the error means and what might be causing it. I can't make head or tail of it.
Here is the information that has been requested:
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.5 LTS
Release: 12.04
Codename: precise
owen@termedev:~/malttesting$ python -c "import nltk; print nltk.__version__"
3.2.1
owen@termedev:~/malttesting$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
owen@termedev:~/malttesting$ python -c "import os; print os.environ['MALT_PARSER']; print os.environ['MALT_MODEL']"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'MALT_PARSER'
Thanks for any help
Upvotes: 3
Views: 337
Reputation: 122300
There are several things that might have gone wrong:
First check that you have installed and updated your NLTK:
$ pip install -U nltk
And to update your Java on Ubuntu, see http://tecadmin.net/install-oracle-java-8-jdk-8-ubuntu-via-ppa/#
Try to work with MaltParser version > 1.8 with the appropriate .mco
files (e.g. engmalt.linear-1.7
)
Then go through the steps in TL;DR
instructions from Step by step to getting malt parser in NLTK to work?
In short, you should see NO error when you run this on the terminal:
cd && wget http://www.maltparser.org/mco/english_parser/engmalt.linear-1.7.mco && wget http://maltparser.org/dist/maltparser-1.8.1.zip && unzip maltparser-1.8.1.zip && export MALT_PARSER=$HOME/maltparser-1.8.1/ && export MALT_MODEL=$HOME/engmalt.linear-1.7.mco
python -c "from nltk.parse.malt import MaltParser; mp = MaltParser('maltparser-1.8.1', 'engmalt.linear-1.7.mco'); mp.parse_one('I shot an elephant in my pajamas .'.split()).tree()"
You have to change to the directory where you are running your script and then set the environment variable on the terminal before running your script:
cd /home/username/directory_where_you_are_going_to_run_your_script
export MALT_PARSER=$HOME/maltparser-1.8.1/
export MALT_MODEL=$HOME/engmalt.linear-1.7.mco
python yourscript.py
If the solutions to the problems listed above didn't resolve your problem with MaltParser API in NLTK, then it's best that you
pip
[on terminal]:
cd && wget http://www.maltparser.org/mco/english_parser/engmalt.linear-1.7.mco && wget http://maltparser.org/dist/maltparser-1.8.1.zip && unzip maltparser-1.8.1.zip && export MALT_PARSER=$HOME/maltparser-1.8.1/ && export MALT_MODEL=$HOME/engmalt.linear-1.7.mco
python -c "from nltk.parse.malt import MaltParser; mp = MaltParser('maltparser-1.8.1', 'engmalt.linear-1.7.mco'); mp.parse_one('I shot an elephant in my pajamas .'.split()).tree()"
Then afterwards re-run your script after setting up the environmental variables, e.g. with:
cd /home/username/directory_where_you_are_going_to_run_your_script
export MALT_PARSER=$HOME/maltparser-1.8.1/
export MALT_MODEL=$HOME/engmalt.linear-1.7.mco
python yourscript.py
Upvotes: 1