2012-11-03 73 views
2

我已經嘗試了在陽光下的一切,以使麥芽解析器(1.7.1)與他們的預訓練模型(添加了.mco黑客)工作。我得到的最接近的是一個DependencyGraph,每個單詞的第一個字母作爲標籤。我只有一次到達那裏,不能回來。的99%的時間,我得到的是:一步一步讓NLTK中的麥芽解析器正常工作?

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 

它發生,如果我執行chown它的寫作臨時文件,或在sudo下執行Python的目錄。我已經嘗試過麥芽解析器1.7.1和1.2。什麼?

感謝

回答

2
八月期間在NLTK

MaltParser API被賦予了新的更新2015年

這裏有一個一步一步的方式來獲得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.設置環境變量

例如

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

[email protected]:~$ cd 
[email protected]:~$ wget http://www.maltparser.org/mco/english_parser/engmalt.linear-1.7.mco 
[email protected]:~$ wget http://maltparser.org/dist/maltparser-1.8.1.zip 
[email protected]:~$ unzip maltparser-1.8.1.zip 
[email protected]:~$ export MALT_PARSER=$HOME/maltparser-1.8.1/ 
[email protected]:~$ export MALT_MODEL=$HOME/engmalt.linear-1.7.mco 
[email protected]i:~$ 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(請勿安裝NLTK FIRST)
  • 安裝Git
  • 安裝Java
  • 安裝NLTKpip install -U https://github.com/nltk/nltk.git不要使用conda install nltk,直到他們已經更新了他們的包NLTK V3。 2!)
+1

OSX上,你也可以通過'釀造自來水pepijnkokke /自制-compling &&釀造安裝安裝帶有自制maltparser maltparser' –

相關問題