我想做一个嘈杂的解决方案,这样给定一个人称代词,该代词被前一个(最近的)人替换。
例如:
Alex is looking at buying a U.K. startup for $1 billion. He is very confident that this is going to happen. Sussan is also in the same situation. However, she has lost hope.
输出是:
Alex is looking at buying a U.K. startup for $1 billion. Alex is very confident that this is going to happen. Sussan is also in the same situation. However, Susan has lost hope.
另一个例子,
Peter is a friend of Gates. But Gates does not like him.
在这种情况下,输出将是:
Peter is a friend of Gates. But Gates does not like Gates.
是的!这是超级吵。
使用 spacy:我已经提取了Person
using NER,但是如何适当地替换代词?
代码:
import spacy
nlp = spacy.load("en_core_web_sm")
for ent in doc.ents:
if ent.label_ == 'PERSON':
print(ent.text, ent.label_)