Reputation: 2404
I have tried everything under the sun to make Malt Parser (1.7.1) with their pre-trained model (added with the .mco hack) to work. The closest I've gotten is a DependencyGraph with the first letter of each word as the label. I only got there once and can't get back. 99% of the time, all I get is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/nltk/parse/malt.py", line 98, in parse
return self.tagged_parse(taggedwords, verbose)
File "/Library/Python/2.7/site-packages/nltk/parse/malt.py", line 150, in tagged_parse
"code %d" % (' '.join(cmd), ret))
Exception: MaltParser parsing (java -jar /Users/walrusthecat/maltparser/malt.jar -w /var/folders/2b/0fpc89fd0rqbj8bf4r7xbh640000gp/T -c /Users/walrusthecat/maltparser/model.mco -i /var/folders/2b/0fpc89fd0rqbj8bf4r7xbh640000gp/T/malt_input.conlltApSTj -o /var/folders/2b/0fpc89fd0rqbj8bf4r7xbh640000gp/T/malt_output.conllrkclZz -m parse) failed with exit code 1
It happens if I chown the directories where it's writing the temp files, or execute python under sudo. I've tried with Malt Parser 1.7.1 and 1.2 . Anything?
Thanks
Upvotes: 2
Views: 4452
Reputation: 122300
MaltParser API in NLTK was given a fresh update during August 2015.
Here's a step by step way to get MaltParser to work on Linux:
1. Download the extract the malt parser and pre-trained model
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
2. Setup the environment variables
MALT_PARSER
to point to the MaltParser directory, e.g. /home/user/maltparser-1.8.1/
in Linux.MALT_MODEL
to point to .mco
file, e.g. engmalt.linear-1.7.mco
from http://www.maltparser.org/mco/mco.html.e.g..
export MALT_PARSER=$HOME/maltparser-1.8.1/
export MALT_MODEL=$HOME/engmalt.linear-1.7.mco
(See https://github.com/nltk/nltk/wiki/Installing-Third-Party-Software#malt-parser)
Then in python
:
>>> 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()
Tree('shot', ['I', Tree('elephant', ['an']), Tree('in', [Tree('pajamas', ['my'])]), '.'])
TL;DR
alvas@ubi:~$ cd
alvas@ubi:~$ wget http://www.maltparser.org/mco/english_parser/engmalt.linear-1.7.mco
alvas@ubi:~$ wget http://maltparser.org/dist/maltparser-1.8.1.zip
alvas@ubi:~$ unzip maltparser-1.8.1.zip
alvas@ubi:~$ export MALT_PARSER=$HOME/maltparser-1.8.1/
alvas@ubi:~$ export MALT_MODEL=$HOME/engmalt.linear-1.7.mco
alvas@ubi:~$ python
Python 2.7.11 (default, Dec 15 2015, 16:46:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 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()
Tree('shot', ['I', Tree('elephant', ['an']), Tree('in', [Tree('pajamas', ['my'])]), '.'])
For more info, please see demo on:
On Windows, please follow the print-screen steps CAREFULLY: https://github.com/nltk/nltk/issues/1294#issuecomment-189831647
To summarize the Windows steps:
Conda
(DO NOT INSTALL NLTK FIRST)Git
Java
NLTK
with pip install -U https://github.com/nltk/nltk.git
(DO NOT USE conda install nltk
, until they've updated their package to NLTK v3.2 !!!)Upvotes: 2
Reputation: 1321
You need not provide full path to the .mco file , just the file name will be enough..
how-to-use-malt-parser-in-python-nltk
Upvotes: 0