Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在大量文本中替换性别代词?_Python_Nlp_Nltk - Fatal编程技术网

Python 如何在大量文本中替换性别代词?

Python 如何在大量文本中替换性别代词?,python,nlp,nltk,Python,Nlp,Nltk,我正在写一部小说,在写到一半的时候,我决定把一个重要的主人公从男性变成女性。我编写了一些简单的Python代码,认为我可以轻松地更改该特定字符的代词,但它意外地更改了所有字符的代词。以下是小说中的一些示例文本: example_text = "John walked to the market. He was tired, but decided to leg it anyway, he needed the exercise! He met Joe along the way. Joe was

我正在写一部小说,在写到一半的时候,我决定把一个重要的主人公从男性变成女性。我编写了一些简单的Python代码,认为我可以轻松地更改该特定字符的代词,但它意外地更改了所有字符的代词。以下是小说中的一些示例文本:

example_text = "John walked to the market. He was tired, but decided to leg it anyway, he needed the exercise! He met Joe along the way. Joe was a tall man and walked fast, during his heyday, he was an impressive athlete."
我希望将Joe(男性)更改为Jane(女性),并编写了以下简单代码:

example_text = example_text.replace(" he ", " she ")
example_text = example_text.replace(" He ", " She ")
example_text = example_text.replace(" his ", " her ")
example_text = example_text.replace(" man ", " woman ")
example_text = example_text.replace("Joe", "Jane")

但是上面的代码将乔和约翰的代词都改为女性。我现在意识到,我必须使用NLP来做这件事,但是有没有一个模块或一个算法来实现这一点?

代词解析是NLP最大的问题之一……你可以考虑去做。manually@BrianJoseph真的让我想起了以下漫画:@BrianJoseph说:这是相当棘手的。也许你可以用记号笔代替代词,然后手动检查。但像“他是一个好父亲”或其他提及男性和女性角色(你不可能全部列出)的东西可能会使你不可能不亲自检查至少一次。是的,你不能100%准确地完成这项工作。你可以查看最新的技术,但它不会像它那样精确。manually@BrianJoseph真的让我想起了以下漫画:@BrianJoseph说:这是相当棘手的。也许你可以用记号笔代替代词,然后手动检查。但像“他是一个好父亲”或其他提及男性和女性角色(你不可能全部列出)的东西可能会使你不可能不亲自检查至少一次。是的,你不能100%准确地完成这项工作。你们可以看看最先进的技术,但它不会像手工操作那个样精确