自然语言处理与知识图谱week7 | 篇章分析(neuralcoref)

import spacy
nlp = spacy.load('en')

import neuralcoref
neuralcoref.add_to_pipe(nlp)

def get_coref(s1):
    doc = nlp(s1)
    print(doc._.has_coref)
    if doc._.has_coref:
        print(doc._.coref_clusters)

get_coref('My sister has a dog. She loves him.')
get_coref('Some like to play football, others are fond of basketball.')
get_coref('The more a man knows, the more he feels his ignorance.')

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/cat_xing/article/details/89201301