使用Stanford coreNLP在python nltk中进行共指解析 [英] Coreference resolution in python nltk using Stanford coreNLP

查看:414
本文介绍了使用Stanford coreNLP在python nltk中进行共指解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Stanford CoreNLP提供了共指解析如此处所述,也 ,提供了一些有关在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的共指解析功能.我已经能够在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包装器:

As mentioned by @Igor You can try the python wrapper implemented in this GitHub repo: https://github.com/dasmith/stanford-corenlp-python

此回购包含两个主要文件: corenlp.py client.py

This repo contains two main files: corenlp.py client.py

执行以下更改以使coreNLP工作:

Perform the following changes to get coreNLP working:

  1. 在corenlp.py中,更改corenlp文件夹的路径.设置本地计算机包含corenlp文件夹的路径,并在corenlp.py的第144行中添加路径.

  1. 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

if not corenlp_path: corenlp_path = <path to the corenlp file>

if not corenlp_path: corenlp_path = <path to the corenlp file>

"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"]

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.

  1. 运行命令:

  1. Run the command:

python corenlp.py

这将启动服务器

  1. 现在运行主客户端程序

  1. 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.

这篇关于使用Stanford coreNLP在python nltk中进行共指解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆