You have been hired by the American embassy in the UK to act as a translator. Being a programmer, you decide to write a program to do a bit of the work for you.
You've found out that often just doing the following things can satisfy Word's spellcheck, which has been set to "English (United States)", somewhat, so you don't have to do as much work later when translating written documents:
- All occurrences of "our" can be replaced with "or", e.g. "favourite" -> "favorite", "our" -> "or".
- All occurrences of "ise" and "yse" can be replaced with "ize" and "yze", respectively.
- All occurrences of "ae" and "oe" can be replaced with "e".
- All occurrences of "ll" that have a vowel before them can be replaced with "l".
- The ending "re" can re replaced with "er", as long as it is not preceded by a vowel, e.g. "ore" will not be replaced, but "centre" becomes "center".
- The ending "xion" can be replaced with "ction", e.g. "connexion" -> "connection" (this is archaic, but whatever).
Write a program or function that takes a string or list of characters as input, performs the replacements mentioned above, and outputs the modified string or list of characters using the standard IO methods.
Rules
- A sequence of alphabetical characters is considered a word (
[A-Za-z]
). Words may be delimited by spaces, hyphens, commas, periods, or other punctuation characters ([^A-Za-z]
). - A vowel is one of a, e, i, o, or u.
- This is code-golf, so shortest code wins.
- Inputs with conflicts are undefined behavior, e.g. if a word ends with "oure", your program can make it "ouer" or "ore".
- Your program need only take one pass over the input - it's fine if you replaced something like "rae" and end up with "re" instead of further turning that into "er".
- Substitutions may be done on uppercase and/or lowercase letters (you can choose). You may also output the letters in any case you want.
Test cases
Note that not all words have been translated correctly, since the rules described above are not always right. Also note that the text here has mixed case to try to look like normal English, but you can use all lowercase for your input and all uppercase for your output or whatever you want.
Substitutions are bolded or italicized if they are side by side. Input --- Output ______ We would like you to analyse something our agencies have discovered. --- We would like you to analyze something or agencies have discovered. ______ There have been reports of American tourists travelling here in knight's armour. --- There have been reports of American torists traveling here in knight's armor. ______ An aerosol may be the cause of their transfixion. Their oesophagi must be studied. --- An erosol may be the cause of their transfiction. Their esophagi must be studied. ______ OURoullisaeisere --- ORouliseizere ______ Pardon me, I just fell on my keyboard while dodging a knight with a metre-long sword. --- Pardon me, I just fel on my keyboard while dodging a knight with a meter-long sword. ______ My keysere n'twourkingnowneithre r myhands hellllpme --- My keyzere n'tworkingnowneither r myhands helllpme ______ Haha, I'm just messing with you. No knights here with 3.28-foot-long swords. That's totally ridiculous. --- Haha, I'm just messing with you. No knights here with 3.28-foot-long swords. That's totaly ridiculous.
metres
? No change? \$\endgroup\$re
. \$\endgroup\$