问题描述
Stanford CoreNLP 提供共指解析如这里提到的,还有这个线程,this,提供了有关其在 Java 中实现的一些见解.
Stanford CoreNLP provides coreference resolution as mentioned here, also this thread, this, provides some insights about its implementation in Java.
但是,我使用的是 python 和 NLTK,我不确定如何在我的 python 代码中使用 CoreNLP 的 Coreference 解析功能.我已经能够在 NLTK 中设置 StanfordParser,这是我目前的代码.
However, I am using python and NLTK and I am not sure how can I use Coreference resolution functionality of CoreNLP in my python code. I have been able to set up StanfordParser in NLTK, this is my code so far.
from nltk.parse.stanford import StanfordDependencyParser
stanford_parser_dir = 'stanford-parser/'
eng_model_path = stanford_parser_dir + "stanford-parser-models/edu/stanford/nlp/models/lexparser/englishRNN.ser.gz"
my_path_to_models_jar = stanford_parser_dir + "stanford-parser-3.5.2-models.jar"
my_path_to_jar = stanford_parser_dir + "stanford-parser.jar"
如何在python中使用CoreNLP的共指解析?
How can I use coreference resolution of CoreNLP in python?
推荐答案
正如@Igor 所提到的,您可以尝试在这个 GitHub 存储库中实现的 python 包装器:https://github.com/dasmith/stanford-corenlp-python
As mentioned by @Igor You can try the python wrapper implemented in this GitHub repo: https://github.com/dasmith/stanford-corenlp-python
这个 repo 包含两个主要文件:内核文件客户端.py
This repo contains two main files:corenlp.pyclient.py
执行以下更改以使 coreNLP 正常工作:
Perform the following changes to get coreNLP working:
在 corenlp.py 中,更改 corenlp 文件夹的路径.设置本机包含corenlp文件夹的路径,在corenlp.py第144行添加路径
In the corenlp.py, change the path of the corenlp folder. Set the path where your local machine contains the corenlp folder and add the path in line 144 of corenlp.py
如果不是 corenlp_path:corenlp_path =
corenlp.py"中的jar文件版本号不同.根据您拥有的 corenlp 版本进行设置.在 corenlp.py 的第 135 行更改
The jar file version number in "corenlp.py" is different. Set it according to the corenlp version that you have. Change it at line 135 of corenlp.py
jars = ["stanford-corenlp-3.4.1.jar","stanford-corenlp-3.4.1-models.jar","joda-time.jar","xom.jar","jollyday.jar"]
在此将 3.4.1 替换为您下载的 jar 版本.
In this replace 3.4.1 with the jar version which you have downloaded.
运行命令:
Run the command:
python corenlp.py
这将启动一个服务器
现在运行主客户端程序
Now run the main client program
python client.py
这提供了一个字典,您可以使用'coref'作为键访问coref:
This provides a dictionary and you can access the coref using 'coref' as the key:
例如:John 是一名计算机科学家.他喜欢编码.
For example: John is a Computer Scientist. He likes coding.
{
"coref": [[[["a Computer Scientist", 0, 4, 2, 5], ["John", 0, 0, 0, 1]], [["He", 1, 0, 0, 1], ["John", 0, 0, 0, 1]]]]
}
我已经在 Ubuntu 16.04 上试过了.使用 java 版本 7 或 8.
I have tried this on Ubuntu 16.04. Use java version 7 or 8.
这篇关于使用斯坦福 coreNLP 在 python nltk 中的共指解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!