Skip to content

Instantly share code, notes, and snippets.

@brianseitel
Created August 5, 2012 22:10
Show Gist options
  • Save brianseitel/3267351 to your computer and use it in GitHub Desktop.
Save brianseitel/3267351 to your computer and use it in GitHub Desktop.
Python port of @dancrew32's Ermagherd translator
# To use:
#
# erma = ermagerd("oh my god, a refrigerator1")
import re
class ermagerd:
def __init__(self, arg1):
print self.gherd(arg1)
def translate(self, word):
# Don't translate short words
if len(word) == 1:
return word
# Handle specific words
if word == 'AWESOME':
return 'ERSUM'
elif word == 'BANANA':
return 'BERNERNER'
elif word == 'BAYOU':
return 'BERU'
elif word == 'FAVORITE' or word == 'FAVOURITE':
return 'FRAVRIT'
elif word == 'GOOSEBUMPS':
return 'GERSBERMS'
elif word == 'LONG':
return 'LERNG'
elif word == 'MY':
return 'MAH'
elif word == 'THE':
return 'DA'
elif word == 'THEY':
return 'DEY'
elif word == "WE'RE":
return 'WER'
elif word == 'YOU':
return 'U'
elif word == "YOU'RE":
return 'YER'
# Before translating, keep a reference of the original word
original = word
# Drop vowel from the end of words
if len(original) > 2: # Keep it at the end of short words like WE
word = re.sub('[AEIOUY]$', '', word)
# Reduce duplicate letters
word = re.sub('[^\w\s]|(.)(?=\1)', '', word)
# Reduce adjacent vowels to one
word = re.sub('[AEIOUY]{2,}', 'E', word)
# DOWN => DERN
word = re.sub('OW', 'ER', word)
# Replace vowels with ER
word = re.sub('[AEIOUY]+', 'ER', word)
# OH -> ER
word = re.sub('ERH', 'ER', word)
# MY -> MAH
word = re.sub('MER', 'MAH', word)
# FALLING -> FERLIN
word = re.sub('ERNG', 'IN', word)
# POOPED -> PERPERED -> PERPED
word = re.sub('ERPERD', 'ERPED', word)
# MEME -> MAHM -> MERM
word = re.sub('MAHM', 'MERM', word)
# Keep Y as first character
# YES -> ERS -> YERS
if original[0] == 'Y':
word = 'Y' + word
# reduce duplicate letters
word = re.sub('[^\w\s]|(.)(?=\1)', '', word)
# YELLOW -> YERLER -> YERLO
if original[:3] == 'LOW' and word[:3] == 'LER':
word = word[0:3] + 'LO'
return word
def gherd (self, text):
if len(text) == 0:
return
text = text.upper()
words = text.split(' ')
translated = []
for word in words:
prefix = re.match('/^\W+/', word)
suffix = re.match('/\W+$/', word)
if word:
# Is translateable
new_word = ''
if prefix:
new_word = prefix
new_word += self.translate(word)
if suffix:
new_word += suffix
translated.append(new_word)
else:
# Is punctuation
translated.append(word)
return ' '.join(translated)
@brianseitel
Copy link
Author

Inspired by @dancrew32's Ermagherd translator: https://gist.github.com/3185161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment