'Pluralizes Spanish nouns.'

def pluralize(self, word):

    rules = [[u'(?i)([aeiou])x$', u'\\1x'], [u'(?i)([\xe1\xe9\xed\xf3\xfa])([ns])$', u'|1\\2es'], [u'(?i)(^[bcdfghjklmn\xf1pqrstvwxyz]*)an$', u'\\1anes'], [u'(?i)([\xe1\xe9\xed\xf3\xfa])s$', u'|1ses'], [u'(?i)(^[bcdfghjklmn\xf1pqrstvwxyz]*)([aeiou])([ns])$', u'\\1\\2\\3es'], [u'(?i)([aeiou\xe1\xe9\xf3])$', u'\\1s'], [u'(?i)([aeiou])s$', u'\\1s'], [u'(?i)([\xe9\xed])(s)$', u'|1\\2es'], [u'(?i)z$', u'ces'], [u'(?i)([\xed\xfa])$', u'\\1es'], [u'(?i)(ng|[wckgtp])$', u'\\1s'], [u'(?i)$', u'es']]
    uncountable_words = [u'tijeras', u'gafas', u'vacaciones', u'v\xedveres', u'd\xe9ficit']
    '    In    fact    these    words    have    no    singular    form:    you    cannot    say    neither\n                                "una    gafa"    nor    "un    v\xc3\xadvere".    So    we    should    change    the    variable    name    to\n                                onlyplural    or    something    alike.'
    irregular_words = {u'pa\xeds': u'pa\xedses', u'champ\xfa': u'champ\xfas', u'jersey': u'jers\xe9is', u'car\xe1cter': u'caracteres', u'esp\xe9cimen': u'espec\xedmenes', u'men\xfa': u'men\xfas', u'r\xe9gimen': u'reg\xedmenes', u'curriculum': u'curr\xedculos', u'ultim\xe1tum': u'ultimatos', u'memor\xe1ndum': u'memorandos', u'refer\xe9ndum': u'referendos'}
    lower_cased_word = word.lower()
    for uncountable_word in uncountable_words:
        if (lower_cased_word[((-1) * len(uncountable_word)):] == uncountable_word):
            return word
    for irregular in irregular_words.keys():
        match = re.search(((u'(?i)(u' + irregular) + u')$'), word, re.IGNORECASE)
        if match:
            return re.sub(((u'(?i)' + irregular) + u'$'), (match.expand(u'\\1')[0] + irregular_words[irregular][1:]), word)
    for rule in range(len(rules)):
        match = re.search(rules[rule][0], word, re.IGNORECASE)
        if match:
            groups = match.groups()
            replacement = rules[rule][1]
            if re.match(u'\\|', replacement):
                for k in range(1, len(groups)):
                    replacement = replacement.replace((u'|' + str(k)), self.string_replace(groups[(k - 1)], u'\xc1\xc9\xcd\xd3\xda\xe1\xe9\xed\xf3\xfa', u'AEIOUaeiou'))
            result = re.sub(rules[rule][0], replacement, word)
            match = re.search(u'(?i)([aeiou]).{1,3}([aeiou])nes$', result)
            if (match and (len(match.groups()) > 1) and (not re.search(u'(?i)[\xe1\xe9\xed\xf3\xfa]', word))):
                result = result.replace(match.group(0), (self.string_replace(match.group(1), u'AEIOUaeiou', u'\xc1\xc9\xcd\xd3\xda\xe1\xe9\xed\xf3\xfa') + match.group(0)[1:]))
            return result
    return word
