Created
May 12, 2015 00:10
-
-
Save NekoTashi/3c48ac533a27d7e2c73d to your computer and use it in GitHub Desktop.
Un correcto culiao penca pal colega y la conchetumare.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from __future__ import print_function | |
| sufix_noun_singular_plural = { | |
| 'a': 'as', 'b': 'bes', 'c': 'cs', 'd': 'des', 'e': 'es', 'f': 'fs', | |
| 'g': 'gs', 'i': 'is', 'j': 'jes', 'k': 'ks', 'l': 'les', 'm': 'ms', | |
| 'n': 'nes', 'o': 'os', 'p': 'ps', 'r': 'res', 's': 'es', 't': 'ts', | |
| 'u': 'us', 'v': 's', 'x': 'xes', 'z': 'ces' | |
| } | |
| article_plural = ['los', 'las', 'unas', 'unos'] | |
| article_singular = ['el', 'la', 'un', 'una'] | |
| articles = list() | |
| articles.extend(article_plural) | |
| articles.extend(article_singular) | |
| female_noun_sufix = ['a', 'as', 'd', 'on', 'z', 'is', 'es', 'umbre'] | |
| male_noun_sufix = ['o', 'u', 'l', 'e', 'r'] | |
| def nv_mb_rule(word): | |
| """ | |
| Corrige word si este contiene nb o mv | |
| """ | |
| if 'nb' in word: | |
| word = word.replace('nb','nv') | |
| if 'mv' in word: | |
| word = word.replace('mv','mb') | |
| return word | |
| def is_article(word): | |
| """ | |
| Verifica si word es un articulo | |
| """ | |
| if word in articles: | |
| return True | |
| else: | |
| return False | |
| def is_plural_article(article): | |
| """ | |
| Verifica si el article es plural | |
| """ | |
| if article in article_plural: | |
| return True | |
| else: | |
| return False | |
| def is_noun_plural(word): | |
| """ | |
| Verifica si word es un sustantivo plural | |
| """ | |
| for sufix in sufix_noun_singular_plural.values(): | |
| if word.endswith(sufix): | |
| return True | |
| else: | |
| return False | |
| def change_noun_to_singular(noun, sufix): | |
| """ | |
| Cambia el noun(sustantivo) a singular | |
| """ | |
| noun = noun[:-len(sufix)] | |
| return noun | |
| def change_article_gender(article, noun, is_plural=False): | |
| """ | |
| Cambia de masculo a femenino o viceversa si es necesario | |
| """ | |
| for sufix in female_noun_sufix: | |
| if noun.endswith(sufix): | |
| if is_plural: | |
| article = article.replace(article, 'las') | |
| else: | |
| article = article.replace(article, 'la') | |
| return article | |
| for sufix in male_noun_sufix: | |
| if noun.endswith(sufix): | |
| if is_plural: | |
| article = article.replace(article, 'los') | |
| else: | |
| article = article.replace(article, 'el') | |
| return article | |
| return article | |
| raw_sentence = raw_input('introduzca una oración\n> ') | |
| splited_sentence = raw_sentence.split() | |
| splited_sentence[2] = nv_mb_rule(splited_sentence[2]) | |
| if is_article(splited_sentence[0]): # Si la primera palabra es articulo. | |
| print('la sentencia comienza con un articulo') | |
| if not is_plural_article(splited_sentence[0]): # Si el articulo es singular. | |
| # Cambiar sustantivo a singular | |
| for sufix in sufix_noun_singular_plural.values(): | |
| if splited_sentence[1].endswith(sufix): # Si es un sustantivo plural | |
| print('el sustantivo sera cambiado a singular') | |
| splited_sentence[1] = change_noun_to_singular(splited_sentence[1], sufix) | |
| splited_sentence[0] = change_article_gender(splited_sentence[0], splited_sentence[1]) | |
| break | |
| else: | |
| continue | |
| else: # Si el articulo es plural | |
| # Verifica si el sustantivo es plural | |
| sufix_endswith = False | |
| for plural_sufix in sufix_noun_singular_plural.values(): | |
| if splited_sentence[1].endswith(plural_sufix): | |
| sufix_endswith = True | |
| break | |
| else: | |
| continue | |
| # Cambia el sustantivo a plural | |
| if not sufix_endswith: | |
| for singular_sufix, plural_sufix in sufix_noun_singular_plural.iteritems(): | |
| if splited_sentence[1].endswith(singular_sufix): | |
| splited_sentence[1] = splited_sentence[1][:-1] + plural_sufix | |
| break | |
| splited_sentence[0] = change_article_gender(splited_sentence[0], splited_sentence[1], is_plural=True) | |
| print(splited_sentence) | |
| else: | |
| print('la sentencia no empieza con un articulo') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment