【发布时间】:2021-01-07 11:34:12
【问题描述】:
所以说,我有以下声明str = What recent discussions she has had with the Secretary of State for Work and Pensions on the effect of that Department’s welfare policies on women
在陈述中,你可以清楚地看到这个问题是用“她”这样的词向女人提出的。如何在给定的文本中找到特定于女性的词(例如,参见上面的文本)以及使用 python 使用它们的次数。 例如
maleWords = '[He, his]'
femaleWords = '[She,her]'
word="What recent discussions she has had with the Secretary of State for Work and Pensions on the effect of that Department’s welfare policies on women"
maleCount = sum(如果是maleWords中的单词则为1,否则对于maleWords中的单词为0) femaleCount = sum(1 if word in femaleWords else 0 for word in femaleWords)
target_gender = 'male' if maleCount >= femaleCount else 'female' print(f"文本的目标性别是{target_gender}")
但是结果显示目标性别是男性,而通过查看句子目标性别是女性。
【问题讨论】:
-
您必须以某种方式定义女性特定词是什么。计算机不知道这一点。要么你有一个女性特定词的列表,要么你从互联网上的某个网站上提取它。