我的COde是
RIGHT JOIN
错误是
from nltk.parse import malt
mp = malt.MaltParser(working_dir="/other/apps/maltparser-1.8.1",mco="engmalt.poly-1.7.mco",additional_java_args=['-Xmx1024m'])
print mp.raw_parse("Hello World")
答案 0 :(得分:2)
NLTK中的MaltParser API只有a patch,可以修复和稳定以前遇到的问题:
以下是如何在NLTK中使用MaltParser API的示例:
# Upgrade your NLTK.
alvas@ubi:~$ cd ~
alvas@ubi:~$ pip install -U nltk
# Get the latest MaltParser and model
alvas@ubi:~$ wget http://maltparser.org/dist/maltparser-1.8.1.zip
alvas@ubi:~$ unzip maltparser-1.8.1.zip
alvas@ubi:~$ wget http://www.maltparser.org/mco/english_parser/engmalt.poly-1.7.mco
# In python, now you can do this:
alvas@ubi:~$ python
>>> from nltk.parse.malt import MaltParser
>>> mp = MaltParser('/home/alvas/maltparser-1.8.1', '/home/alvas/engmalt.poly-1.7.mco')
>>> sent1 = 'I shot an elephant in my pajamas .'.split()
>>> print(mp.parse_one(sent1).tree())
(shot I (elephant an (in (pajamas my))) .)
(有关更多演示代码,请参阅here;有关更详细的演示代码,请参阅here)
请注意,您还可以使用导出功能,并且可以在初始化MaltParser
对象时转义完整路径的使用。但是你必须告诉对象要查找的解析器目录和模型文件名的名称是什么,例如。
alvas@ubi:~$ export MALT_PARSER='/home/$UID/maltparser-1.8.1/'
alvas@ubi:~$ export MALT_MODEL='/home/$UID/engmalt.poly-1.7.mco'
alvas@ubi:~$ python
>>> from nltk.parse.malt import MaltParser
>>> mp = MaltParser('maltparser-1.8.1', 'engmalt.poly-1.7.mco')
>>> sent1 = 'I shot an elephant in my pajamas .'.split()
>>> print(mp.parse_one(sent1).tree())
(shot I (elephant an (in (pajamas my))) .)