如何使用StanfordNLP Python包做依赖解析?
How to use StanfordNLP Python package to do dependency parsing?
我正在尝试使用 here 上新的基于 NN 的解析器来查找句子中的所有形容词短语(例如,The weather is extremely good
中的 good
和 extremely good
), 但是,它非常缺乏文档,我无法让它工作。我当前的代码是
import stanfordnlp
nlp = stanfordnlp.Pipeline()
doc = nlp("The weather is extremely good")
doc.sentences[0].print_dependencies()
这给了我
('The', '2', 'det')
('weather', '5', 'nsubj')
('is', '5', 'cop')
('extremely', '5', 'advmod')
('good', '0', 'root')
但不清楚如何提取我需要的信息,因为这似乎不是树结构。有人有想法吗?
目前 Python 不支持您想要的选区分析。这只是返回依赖项解析(一种不同类型的解析)。
您可以使用 stanfordnlp
与 Java 服务器通信并以这种方式获取选区解析。
此处有用于访问选区解析的示例代码:
https://stanfordnlp.github.io/stanfordnlp/corenlp_client.html
输出中指定的每个词的数字索引表示总督词(该词的头部)的索引。
例如,单词"Whether"
是单词"Good"
的子单词(索引为5,因为"Good"
是实际句子中的第五个单词),所以它采用其州长(负责人)索引,此处为 5 ("Good"
).
你可以从<http://corenlp.run/>
中获取依赖结构表示,并将其与基于我的描述的表示进行比较,以便更好地说明。
我正在尝试使用 here 上新的基于 NN 的解析器来查找句子中的所有形容词短语(例如,The weather is extremely good
中的 good
和 extremely good
), 但是,它非常缺乏文档,我无法让它工作。我当前的代码是
import stanfordnlp
nlp = stanfordnlp.Pipeline()
doc = nlp("The weather is extremely good")
doc.sentences[0].print_dependencies()
这给了我
('The', '2', 'det')
('weather', '5', 'nsubj')
('is', '5', 'cop')
('extremely', '5', 'advmod')
('good', '0', 'root')
但不清楚如何提取我需要的信息,因为这似乎不是树结构。有人有想法吗?
目前 Python 不支持您想要的选区分析。这只是返回依赖项解析(一种不同类型的解析)。
您可以使用 stanfordnlp
与 Java 服务器通信并以这种方式获取选区解析。
此处有用于访问选区解析的示例代码:
https://stanfordnlp.github.io/stanfordnlp/corenlp_client.html
输出中指定的每个词的数字索引表示总督词(该词的头部)的索引。
例如,单词"Whether"
是单词"Good"
的子单词(索引为5,因为"Good"
是实际句子中的第五个单词),所以它采用其州长(负责人)索引,此处为 5 ("Good"
).
你可以从<http://corenlp.run/>
中获取依赖结构表示,并将其与基于我的描述的表示进行比较,以便更好地说明。