NLTK中的MaltParser API在2015年8月进行了全新更新。
这是使MaltParser在Linux上运行的逐步方法:
1.下载提取的麦芽解析器和预先训练的模型
cd wget http://www.maltparser.org/mco/english_parser/engmalt.linear-1.7.mcowget http://maltparser.org/dist/maltparser-1.8.1.zipunzip maltparser-1.8.1.zip
2.设置环境变量
- 确保已安装Java
- 下载并解压缩麦芽解析器:http : //www.maltparser.org/download.html
- 将环境变量设置
MALT_PARSER
为指向MaltParser目录,例如/home/user/maltparser-1.8.1/
在Linux中。 - 使用预先训练的模型时,将环境变量设置
MALT_MODEL
为指向.mco
文件,例如engmalt.linear-1.7.mco
从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
alvas@ubi:~$ cd alvas@ubi:~$ wget http://www.maltparser.org/mco/english_parser/engmalt.linear-1.7.mcoalvas@ubi:~$ wget http://maltparser.org/dist/maltparser-1.8.1.zipalvas@ubi:~$ unzip maltparser-1.8.1.zipalvas@ubi:~$ export MALT_PARSER=$HOME/maltparser-1.8.1/alvas@ubi:~$ export MALT_MODEL=$HOME/engmalt.linear-1.7.mcoalvas@ubi:~$ pythonPython 2.7.11 (default, Dec 15 2015, 16:46:19) [GCC 4.8.4] on linux2Type "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'])]), '.'])有关更多信息,请参见演示:
- 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上,请 仔细
执行打印屏幕步骤:https
:
//github.com/nltk/nltk/issues/1294#issuecomment-189831647
总结Windows步骤:
- 安装
Conda
(请勿先安装NLTK) - 安装
Git
- 安装
Java
- 安装
NLTK
使用pip install -U https://github.com/nltk/nltk.git
( 不使用conda install nltk
,直到他们已经更新了他们的包NLTK V3.2!)



