Reputation: 1265
I need to convert US English sentences from one gender to another, make gender neutral, or take a gender neutral sentence and make it gender specific.
Currently I am using something like "He opened the door".Replace("He","She")
, but this does not work for all as something like "she has a sheep".Replace("he","she")
will return something like "sshe has a ssheep", and adding spaces to the front or back of the words does not work either.
What is a good way of doing this, and can anyone point me to a good list of gender specific words that include gender neutral words like:
Husband, Wife, Spouse
Husbands, Wives, Spouses
I am thinking that I can split the sentence apart by spaces into an array, check and convert each word in the array, then rebuild the sentence from the array, but it just seems like it should be easier than that.
If anyone has any ideas, I prefer c# code.
Upvotes: 0
Views: 180
Reputation: 14422
You should consider an NLP library such as https://sergey-tihon.github.io/Stanford.NLP.NET/StanfordCoreNLP.html or https://www.nrecosite.com/nlp_ner_net.aspx
In that way you can break down the sentence into tokens and then identify and replace the subject of that sentence.
var tokens = new Tokenizer().Parse("John closed tasks");
var searchQuery = new TokenSequence(tokens.ToArray());
recognizer.Recognize(searchQuery, matchesCombinationHandler);
Upvotes: 1
Reputation: 2803
I would do a replacement of ".She ", " She ", ".she ", " she ", " she,", " She,", " she;", " She;". As english speaking human we use spaces and punctuation in writing to determine if the letters are their own word or part of another word. So this is really the only way to do it. Of course you could probably make a regular expression but with the same approach.
Upvotes: 0