заменить ключевые слова в предложении с помощью stanford corenlp - PullRequest
2 голосов
/ 02 марта 2020

Я использую Stanford Corenlp, чтобы получить разрешение Coreference. Это код, который я использую сейчас.

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))

Я получаю вывод, подобный этому,

Deepika <-> She <-> her
he <-> a dog <-> him <-> He

Я хочу заменить предложение. Кто-нибудь расскажет, как изменить этот код, чтобы получить замененное предложение. Я использую последнюю версию Stanford Corenlp, а не старую.

...