NLTK中用于解析的英语语法

| 是否有可以立即使用并可以在NLTK中使用的即用型英语语法?我已经搜索了使用NLTK进行解析的示例,但似乎我必须在解析句子之前手动指定语法。 非常感谢!     
已邀请:
您可以看一下pyStatParser,这是一个简单的python统计解析器,它返回NLTK解析树。它带有公共树库,并且仅在您首次实例化解析器对象时(大约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))))
  (. ?))
    
我的库spaCy提供了高性能的依赖解析器。 安装:
pip install spacy
python -m spacy.en.download all
用法:
from spacy.en import English
nlp = English()
doc = nlp(u\'A whole document.\\nNo preprocessing require.   Robust to arbitrary formating.\')
for sent in doc:
    for token in sent:
        if token.is_alpha:
            print token.orth_, token.tag_, token.head.lemma_
崔等。 (2015)发现spaCy是可用的最快的依赖解析器。它在单个线程上每秒处理超过13,000个句子。在标准WSJ评估中,它的得分为92.7%,比CoreNLP的任何模型都高1%以上。     
有一个名为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\' ... 
    
nltk_data
分布中有一些语法。在您的Python解释器中,发出
nltk.download()
。     
使用MaltParser,您将获得预训练的英语语法,以及一些其他预训练的语言。 Maltparser是一个依赖解析器,而不是一些简单的自下而上或自上而下的解析器。 只需从http://www.maltparser.org/index.html下载MaltParser并使用NLTK,如下所示:
import nltk
parser = nltk.parse.malt.MaltParser()
    
我已经尝试过NLTK,PyStatParser,Pattern。 IMHO模式是以上文章中介绍的最佳英语解析器。因为它支持pip安装,并且网站(http://www.clips.ua.ac.be/pages/pattern-en)上有一个精美的文档。我找不到适合NLTK的合理文档(默认情况下,它给我的结果不准确。而且我找不到如何调整它的方法)。 pyStatParser比我的环境中描述的要慢得多。 (大约一分钟的时间进行初始化,花了几秒钟来解析长句子。也许我没有正确使用它)。     
您是否在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     

要回复问题请先登录注册