是否有即时可用的英语语法,我可以加载它并在NLTK中使用?我搜索了使用NLTK解析的示例,但似乎我必须在解析句子之前手动指定语法。
非常感谢!
答案 0 :(得分:31)
你可以看看pyStatParser,这是一个返回NLTK解析树的简单python统计解析器。它带有公共树库,它仅在您第一次实例化Parser对象时生成语法模型(大约8秒钟)。它使用CKY算法,并在一秒钟内解析平均长度的句子(如下所示)。
>>> from stat_parser import Parser
>>> parser = Parser()
>>> print parser.parse("How can the net amount of entropy of the universe be massively decreased?")
(SBARQ
(WHADVP (WRB how))
(SQ
(MD can)
(NP
(NP (DT the) (JJ net) (NN amount))
(PP
(IN of)
(NP
(NP (NNS entropy))
(PP (IN of) (NP (DT the) (NN universe))))))
(VP (VB be) (ADJP (RB massively) (VBN decreased))))
(. ?))
答案 1 :(得分:7)
有一个名为Pattern的图书馆。它非常快速且易于使用。
>>> from pattern.en import parse
>>>
>>> s = 'The mobile web is more important than mobile apps.'
>>> s = parse(s, relations=True, lemmata=True)
>>> print s
'The/DT/B-NP/O/NP-SBJ-1/the mobile/JJ/I-NP/O/NP-SBJ-1/mobile' ...
答案 2 :(得分:5)
nltk_data
发行版中有一些语法。在Python解释器中,发出nltk.download()
。
答案 3 :(得分:4)
使用MaltParser,你有一个预训练的英语语法,还有其他一些预训练的语言。 Maltparser是一个依赖解析器,而不是一些简单的自下而上或自上而下的解析器。
只需从http://www.maltparser.org/index.html下载MaltParser并使用这样的NLTK:
import nltk
parser = nltk.parse.malt.MaltParser()
答案 4 :(得分:4)
我尝试过NLTK,PyStatParser,Pattern。恕我直言模式是上面文章中介绍的最好的英语解析器。因为它支持pip安装,网站上有一个奇特的文档(http://www.clips.ua.ac.be/pages/pattern-en)。我找不到NLTK的合理文件(并且它默认为我提供了不准确的结果。我找不到如何调整它)。 pyStatParser比我在环境中描述的要慢得多。 (初始化约一分钟,解析长句需要几秒钟。也许我没有正确使用它)。
答案 5 :(得分:3)
您是否尝试过使用NLTK进行POS标记?
text = word_tokenize("And now for something completely different")
nltk.pos_tag(text)
答案是这样的
[('And', 'CC'), ('now', 'RB'), ('for', 'IN'), ('something', 'NN'),('completely', 'RB'), ('different', 'JJ')]
从这里获得此示例NLTK_chapter03
答案 6 :(得分:0)
我发现nltk与斯坦福大学开发的解析器语法配合得很好。
Syntax Parsing with Stanford CoreNLP and NLTK
开始使用Stanford CoreNLP和NLTK非常容易。您需要做的只是准备工作,此后,您可以使用以下代码解析句子:
Array.prototype.filter()
准备工作:
您可以使用以下代码运行CoreNLPServer:
from nltk.parse.corenlp import CoreNLPParser
parser = CoreNLPParser()
parse = next(parser.raw_parse("I put the book in the box on the table."))
不要忘记通过执行server.stop()来停止服务器