def parse_sentence(self, sentence: str) -> object:
"""
Parse a sentence for given sentence and with user-defined properties
:type properties: object
:type sentence: str
The pizza is overpriced
return : Json Object from the NLP server.
"""
return self.get_parser().api_call(sentence)["sentences"][0]
我的方法是绕过NLTK提供的接口,直接查看它们的实现。在
找到源代码
./nltk/parse/corenlp.py
。在在
GenericCoreNLPParser
类中,有一个名为api_call
的方法。当您构造依赖关系分析器对象时。您可以调用此方法来获取原始JSON对象。在您将得到一个带有键的JSON对象:
basic dependencies
,enhancedDependencies
,enhancedPlusPlusDependencies
,tokens
。当得到结果的时候。我们可以编写一个简单的函数将结果解析为与调用它们的接口相同的格式。在以下是一些片段
一旦你得到结果。在
^{pr2}$在源代码中,他们将把JSON对象转换为树结构,在大多数情况下,树结构更通用。在
Here is a demo picture
希望我的帖子能有所帮助。在
相关问题 更多 >
编程相关推荐