British author Sarah Caudwell wrote four mystery novels without revealing the gender of main character Hilary Tamar.
Like Caudwell herself, sleuth Hilary Tamar taught law at Oxford and was witty, erudite, and incisive. In the four novels — Thus Was Adonis Murdered, The Shortest Way to Hades, The Sirens Sang of Murder, and The Sybil in Her Grave — Tamar acts as mentor to four barristers in "legal whodunits" that revolve around the intricacies of the British legal system. Tamar, who serves as both storyteller and detective, writes in the first person, often communicates with the other characters by letter, and is addressed directly when present:
"So you see, Hilary," said Selena, "no one's on holiday. Except Julia, of course. She should be in Venice by now."
"Julia?" I said, much astonished. "You haven't let Julia go off on her own to Venice, surely?"
"Am I," asked Selena, "Julia's keeper?"
"Yes," I said, rather severely, for her attitude seemed to me irresponsible.
"Others speak to Hilary or use the name — one never knows for sure whether Hilary is woman or man," notes Sally McConnell-Ginet in Greville G. Corbett's The Expression of Gender. "Caudwell manages this so skillfully that people reading the novels do not always notice the absence of definitive gendering of Hilary: they sometimes mentally provide she or he on the basis of whichever familiar gender assumptions happen to attract their attention."
"Very few people seemed to notice that there was any doubt," Caudwell said. "Usually they referred to Hilary as certainly female or certainly male. It's now mentioned in the jacket copy and, having been tipped off, readers become very angry at me for not resolving it at the end of the book." But she had determined never to reveal Tamar's gender. "I think Hilary is sort of a quintessential Oxford don," she said. "I don't really regard Oxford dons as being determined by gender."
This never bothered her fans, who love the books for their brilliance and humor. Writing in The New York Times Book Review, Newgate Callendar praised Caudwell's "polished, stylized prose," "a kind of English that has not been around since the days of Oscar Wilde." Robert Bork once said, "In my opinion, there can't be too many Sarah Caudwell novels." Alas, there are only four — she passed away in 2000.
Your task is to change gender of the words in a given sentence, where words are defined as the longest sequence of consecutive letters. To do this, you proceed as follows:
Write a function translate that takes two arguments: a word and a dictionary that maps words onto words. In case the given word does not occur in the given dictionary, the given word should be returned unmodified. In case the given word does occur in the given dictionary, the function must return the word onto which the given word is mapped by the dictionary. If the given word contains uppercase letters only, so should the word returned by the function. If the given word starts with an uppercase letter followed by lowercase letters only, so should the word returned by the function. In all other cases, the word returned by the function should contain lowercase letters only.
Write a function sexChange that takes two arguments: a sentence and a dictionary that maps words onto words. The function must return the given sentence, where each word that occurs in the given dictionary is translated as defined by the function translate, based on the given dictionary.
Write a function undoSexChange that takes two arguments: a sentence and a dictionary that maps words onto words. We assume that the given sentence was translated as defined by the function sexChange, based on the given dictionary. The function undoSexChange must undo this translation, and return the original sentence.
All three function must assume that all words that occur in the given dictionary (both the keys and their associated values) only contain lowercase letters. In addition, they may also assume that, as is the case for the keys, also all values in the given dictionary differ from each other. When looking up words in a dictionary, the function should not make any distinction between uppercase and lowercase letters.
>>> translations = {'he':'she', 'brother':'sister'}
>>> translate('he', translations)
'she'
>>> translate('HE', translations)
'SHE'
>>> translate('He', translations)
'She'
>>> translate('brother', translations)
'sister'
>>> translate('my', translations)
'my'
>>> sexChange('He is my brother.', translations)
'She is my sister.'
>>> undoSexChange('She is my sister.', translations)
'He is my brother.'