我们已弃用StanfordTokenizer
/ StanfordSegmenter
, StanfordPOSTagger
和StanfordNERTagger
。
最好也淘汰旧的StanfordParser
, StanfordDependencyParser
和StanfordNeuralDependencyParser
2a。 用CoreNLPParser
封装鸭子类型,
2b。 撰写有关如何使用CoreNLPParser
来使用依赖项和神经依赖项解析的文档
两个(2a)和(2b)的方法应只影响properties
所述的参数api_call
CoreNLPParser
的当前界面:
>>> from nltk.parse.corenlp import CoreNLPParser
>>> sent = 'The quick brown fox jumps over the lazy dog.'
>>> next(parser.raw_parse(sent)).pretty_print() # doctest: +NORMALIZE_WHITESPACE
ROOT
|
S
_______________|__________________________
| VP |
| _________|___ |
| | PP |
| | ________|___ |
NP | | NP |
____|__________ | | _______|____ |
DT JJ JJ NN VBZ IN DT JJ NN .
| | | | | | | | | |
The quick brown fox jumps over the lazy dog .
所需的界面可能如下所示:
# Using Duck-types
>>> from nltk.parse.stanford import CoreNLPParser
>>> depparser = CoreNLPDependencyParser('http://localhost:9000')
>>> depparser.parse(sent)
>>> ndepparser = CoreNLPNeuralDependencyParser('http://localhost:9000')
>>> ndepparser.parse(sent)
# Using arguments to control `properties` for `api_call()`
>>> from nltk.parse.stanford import CoreNLPParser
>>> depparser = CoreNLPParser('http://localhost:9000', parser_type="dependency")
>>> depparser.parse(sent)
>>> ndepparser = CoreNLPNeuralDependencyParser('http://localhost:9000', parser_type="neural_dependency")
>>> ndepparser.parse(sent)
这将是一个很好的课堂项目或一个很好的第一个挑战; P
@artiemq感谢您对此问题的关注!
在单元测试中使用了Mock,因为它是记录API的python流程以及用户应如何使用它的一种快速方法,但实际上并未调用CoreNLP。
关于单元测试,也许使用unittest.mock
并不是测试CoreNLP功能的最佳方法。 请随时重写/编辑它并创建PR =)
我可以在这里看到有关如何在端口9000上连接POStagger'服务器'的信息,但是我找不到有关如何运行Stanford postagger服务器以在端口9000上侦听的信息...有人知道吗?
那么这是决定还是没有?
我现在正在尝试运行nltk.tag.StanfordNERTagger()
。 我想解决一个小问题。 我该做还是不做?
我希望解析器在没有API调用的情况下在本地运行。 CoreNLPParser
吗?
最有用的评论
@artiemq感谢您对此问题的关注!
在单元测试中使用了Mock,因为它是记录API的python流程以及用户应如何使用它的一种快速方法,但实际上并未调用CoreNLP。
关于单元测试,也许使用
unittest.mock
并不是测试CoreNLP功能的最佳方法。 请随时重写/编辑它并创建PR =)