逐步使NLTK中的麦芽解析器起作用? [英] Step by step to getting malt parser in NLTK to work?

查看:99
本文介绍了逐步使NLTK中的麦芽解析器起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试在阳光下进行所有操作,以使Malt Parser(1.7.1)及其经过预先训练的模型(添加了.mco hack)能够正常工作.我得到的最接近的是一个DependencyGraph,每个单词的第一个字母作为标签.我只到过那里一次,无法回去. 99%的时间里,我得到的是:

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

如果我将要写入临时文件的目录全部销毁,或者在sudo下执行python,就会发生这种情况.我已经尝试过使用Malt Parser 1.7.1和1.2.有什么吗?

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?

谢谢

推荐答案

NLTK中的MaltParser API在2015年8月进行了全新更新.

MaltParser API in NLTK was given a fresh update during August 2015.

这是逐步使MaltParser在Linux上运行的方法:

Here's a step by step way to get MaltParser to work on 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.设置环境变量

  • Make sure java is installed
  • Download & extract the Malt Parser: http://www.maltparser.org/download.html
  • Set the environment variable MALT_PARSER to point to the MaltParser directory, e.g. /home/user/maltparser-1.8.1/ in Linux.
  • When using a pre-trained model, set the environment variable MALT_MODEL to point to .mco file, e.g. engmalt.linear-1.7.mco from http://www.maltparser.org/mco/mco.html.

例如.

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中:

>>> 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

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:

  • https://github.com/nltk/nltk/blob/develop/nltk/parse/malt.py#L288
  • https://github.com/nltk/nltk/blob/f4c16c2f9c46cc42c9b68ae746832b622581c6b5/nltk/parse/malt.py#L435

在Windows上,请按照屏幕显示步骤仔细:

On Windows, please follow the print-screen steps CAREFULLY: https://github.com/nltk/nltk/issues/1294#issuecomment-189831647

总结Windows步骤:

To summarize the Windows steps:

  • Install Conda (DO NOT INSTALL NLTK FIRST)
  • Install Git
  • Install Java
  • Install 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 !!!)

这篇关于逐步使NLTK中的麦芽解析器起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆