问题描述
我正在写一个脚本来反转一段文本中的所有性别,所以所有性别化的词都被交换——男人"与女人"交换,她"与他"交换,等等.但是有关于她"应该用他"还是他的"代替的含糊不清.
I am writing a script to reverse all genders in a piece of text, so all gendered words are swapped - "man" is swapped with "woman", "she" is swapped with "he", etc. But there is an ambiguity as to whether "her" should be replaced with "him" or "his".
推荐答案
好的.让我们像语言学家一样看待这个问题.我在这里大声思考.
Okay. Lets look at this like a linguist might. I am thinking aloud here.
"她" 是一个代词.它可以是:
"Her" is a pronoun. It can either be a:
1.
物主代词
这是她的书.
2.
人称代词
给她.(介词后)
他给她写了一封信.(间接宾语)
He wrote her a letter. (indirect object)
他为她治疗感冒.(直接宾语)
He treated her for a cold. (direct object)
那么让我们看看情况 (1),所有格代词.也就是说,它是一个在所有格"情况下的代词(意思是,它是一个具有所有格"的名词.好吧,这个细节没有下一个那么重要.)
So lets look at case (1), possessive pronoun. That is it is a pronoun which is in the "genitive" case (meaning, it is a noun which is being "possessive." Okay, that detail isn't quite as important as the next one.)
在这种情况下,她"充当决定者".限定词可能出现在句子中的两个地方(这是一种简化):
In this case, "her" is acting as a "determiner". Determiners may occur in two places in a sentence (this is a simplification):
Det + 名词(她的书")
Det + Adj + 名词(她的好书")
Det + Adj + Noun ("her nice book")
所以要弄清楚她是否是一个决定者,你可以有这个逻辑:
So to figure out if her is a determiner, you could have this logic:
一个.如果her"后面的词是名词,那么her"就是限定词.
b.如果她"后面的两个词是形容词,那么是名词,那么她"是限定词"
如果你确定她"是一个限定词,那么你知道你必须用他的"代替它,这也是一个限定词(又名属格名词,又名所有格代词).
如果它不符合上面的条件 (a) 和 (b),那么您可能会得出结论,它不是一个限定词,这意味着它必须是人称代词.在这种情况下,您可以将她"替换为他".
If it doesn't match criteria (a) and (b) above, then you could possibly conclude that it is not a determiner, which means it must be a personal pronoun. In that case, you would replace "her" with "him".
您甚至不必进行下面的测试,但无论如何我都会尝试描述它们.
You wouldn't even have to do the tests below, but I'll try to describe them anyway.
从上面看(2):人称代词,而不是所有格.这变得更加棘手.
Looking at (2) from above: personal pronoun, rather than possessive. This gets trickier.
上面的例子显示了她"以三种方式出现:
The examples above show "her" occurring in 3 ways:
(1) 把它交给她.(在介词之后.我们称之为介词对象".)
(1) Give it to her. (after preposition. we call this the "object of a preposition".)
所以你可以设计一个规则:如果'her'紧跟在介词之后,那么它应该被当作名词处理,所以我们用'him'代替它".
So you could maybe devise a rule: "If 'her' occurs immediately after a preposition, then it should be treated as a noun, so we would replace it with 'him'".
接下来的两个是棘手的.她"可以是直接对象或间接对象.
The next two are tricky. "her" can either be a direct object or an indirect object.
(2) 他给她写了一封信.(间接宾语)
(2) He wrote her a letter. (indirect object)
(3) 他为她治疗感冒.(直接宾语)
(3) He treated her for a cold. (direct object)
在语法上,我们如何区分?
Syntactically, how can we tell the difference?
直接宾语紧跟在动词之后.
A direct object occurs immediately after a verb.
如果你有一个动词,后面跟着一个名词,那么这个名词就是一个直接宾语.例如:
If you have a verb, followed by a noun, then that noun is a direct object. eg:
他对待 她.*
如果你有一个动词,后面跟着一个名词,后面跟着一个介词短语,那么这个名词就是一个直接宾语.
If you have a verb, followed by a noun, followed by a prepositional phrase, then the noun is a direct object.
他为感冒治疗了她.(她"是一个名词,它紧跟在动词治疗"之后.为感冒"是一个介词短语.)
He treated her for a cold. ("her" is a noun, and it comes immediately after the verb "treated". "for a cold" is a prepositional phrase.)
这意味着您可以说If you have Verb + Noun + Prep",那么名词就是直接宾语.既然名词是直接宾语,那么它就是人称代词,所以用他".(注意,您只需要检查介词,而不是整个准备短语,因为该短语总是以介词开头.)
Which means that you could say "If you have Verb + Noun + Prep" then the noun is a direct object. Since the noun is a direct object, then it is a personal pronoun, so use "him". (note, you only have to check for a preposition, not the entire prep phrase, since the phrase will always begin with a preposition.)
如果它是一个间接宾语,那么你的形式就是动词+名词+名词".
If it is an indirect object, then you'll have the form "verb + noun + noun".
他给她写了一封信.(她"是名词,信"是名词.嗯,信"是名词短语",因此您还必须考虑限定词.)
He wrote her a letter. ("her" is a noun, "letter" is a noun. well, "a letter" is a "noun phrase", so you'd have to account for determiners as well.)
所以...如果她"是直接宾语、间接宾语或准备对象,您可以将其更改为他",否则,将其更改为他的".
So... if "her" is a direct object, indirect object, or obj of prep, you could change it to "him", otherwise, change it to "his".
这个方法看起来要复杂得多——所以我首先要检查她"是否是一个限定词(见上文),如果是一个限定词,则使用他的",否则,只需使用他"".
This method seems a lot more complicated - so I'd just start by checking to see if "her" is a determiner (see above), and if it is a determiner, use "his" otherwise, just use "him".
所以,上面有很多简化.它不包括打断短语"、子句结构、选区测试、嵌入的子句、标点符号或任何类似的东西.
So, the above has a lot of simplifications. It doesn't cover "interrupting phrases", or clause structures, or constituency tests, or embedded clauses, or punctuation, or anything like that.
此外,这个解决方案需要一本字典——名词"、动词"和介词"的列表,以便您可以确定句子中每个单词的词汇类别.
Also, this solution requires a dictionary - a list of "nouns" and "verbs" and "prepositions" so that you can determine the lexical category of each word in the sentence.
即使在那里,伙计,自然语言处理也很难.您可能希望对模型进行某种训练"以获得好的解决方案.但是对于非常简单的事情,请尝试上面描述的一些内容.
And even there, man, natural language processing is hard. You'd want to do some sort of "training" for your model to have a good solution. BUT for very simple things, try some of the stuff described above.
抱歉说得这么啰嗦!(现有的答案都没有给出任何硬数据或精确的语言定义,所以这里是.)
Sorry for being so verbose! (None of the existing answers gave any hard data, or precise linguistic definitions, so here goes.)
这篇关于脚本是否有一种相当简单的方法来(从上下文)判断“她"是否是“她的"?是物主代词吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!