I am using stanford corenlp to get the coreference resolution. This is the code iam using now.
from stanfordnlp.server import CoreNLPClient
# set up the client
client = CoreNLPClient(properties={'annotators': 'coref', 'coref.algorithm' : 'statistical'},max_char_length=10000000, timeout=600000000, memory='16G')
# submit the request to the server
ann = client.annotate(text)
mychains = list()
chains = ann.corefChain
for chain in chains:
mychain = list()
# Loop through every mention of this chain
for mention in chain.mention:
# Get the sentence in which this mention is located, and get the words which are part of this mention
# (we can have more than one word, for example, a mention can be a pronoun like "he", but also a compound noun like "His wife Michelle")
words_list = ann.sentence[mention.sentenceIndex].token[mention.beginIndex:mention.endIndex]
#print(words_list)
#build a string out of the words of this mention
ment_word = ' '.join([x.word for x in words_list])
print(ment_word)
mychain.append(ment_word)
mychains.append(mychain)
for chain in mychains:
print(' <-> '.join(chain))
Iam getting outputs like this,
Deepika <-> She <-> her
he <-> a dog <-> him <-> He
I want the replaced sentence. Anyone tell how to modify this code to get the replaced sentence. I am using latest Stanford Corenlp not the old one.