我已经尝试在阳光下进行所有操作,以使Malt Parser(1.7.1)与他们的预训练模型(添加了.mco hack)一起工作。我得到的最接近的是一个DependencyGraph,每个单词的第一个字母作为标签。我只到过那里一次,无法回去。99%的时间,我得到的是:
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
如果我对正在写入临时文件的目录进行了整理,或者在sudo下执行python,就会发生这种情况。我尝试过使用Malt Parser1.7.1和1.2。有什么事吗
谢谢
NLTK中的MaltParser API在2015年8月进行了全新更新。
这是使MaltParser在Linux上运行的逐步方法:
1.下载提取的麦芽解析器和预先训练的模型
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.设置环境变量
MALT_PARSER
/home/user/maltparser-1.8.1/
MALT_MODEL
.mco
engmalt.linear-1.7.mco
例如。
export MALT_PARSER=$HOME/maltparser-1.8.1/ export MALT_MODEL=$HOME/engmalt.linear-1.7.mco
(参见https://github.com/nltk/nltk/wiki/Installing-Third-Party-Software#malt- parser)
然后在python:
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'])]), '.'])
有关更多信息,请参见演示:
在Windows上,请 仔细 执行打印屏幕步骤:https : //github.com/nltk/nltk/issues/1294#issuecomment-189831647
总结Windows步骤:
Conda
Git
Java
NLTK
pip install -U https://github.com/nltk/nltk.git
conda install nltk