<commit_before>import pycorpora
import random
import json
from sys import modules


def _this_module():
    return modules[__name__]


def netflix_categories():
    return json.loads(open("netflix-categories.json").read())


def a_netflix_category():
    return random.choice(netflix_categories()['categories'])['name']


def a_character_type():
    # Returns a json object of a character type with name, qualities, synonyms, etc.
    return random.choice(pycorpora.archetypes['character']['characters'])


def an_animal():
    return a_or_an(random.choice(pycorpora.animals["common"]["animals"]).title())


def a_qualified_character_type():
    rct = a_character_type()
    quality = rct.get("quality", " ")
    ctype = rct['name']
    return a_or_an((quality + " " + ctype).strip().title())


def a_noun():
    return a_or_an(random.choice(pycorpora.words['nouns']['nouns']).title())


def a_resume_action_word():
    return random.choice(pycorpora.words["resume_action_words"]["resume_action_words"]).title()


def a_bread_or_pastry():
    borp = random.choice(["breads", "pastries"])
    return a_or_an(random.choice(pycorpora.foods["breads_and_pastries"][borp]).title())


def an_apple_type():
    return a_or_an(random.choice(pycorpora.foods['apple_cultivars']['cultivars']).title())


def a_food():
    pick = random.choice(["a_bread_or_pastry", "an_apple_type"])
    return getattr(_this_module(), pick)()


def an_action():
    pick = random.choice(["eat", "resume"])
    if pick is "eat":
        action = "Eats " + a_food()
    elif pick is "resume":
        action = a_resume_action_word() + " " + a_noun()
    else:
        action = ""
    return action


def a_character():
    pick = random.choice(["a_qualified_character_type", "an_animal"])
    return getattr(_this_module(), pick)()


def a_or_an(word):
    vowels = ["a", "e", "i", "o" "u"]
    if word.lower()[0] in vowels:
        article = "an "
    else:
        article = "a "
    return article + word


def build_a_sentence():
    return a_netflix_category() + " with " + a_character() + " who " + an_action()


if __name__ == '__main__':
    print build_a_sentence()<commit_msg>Restructure code to be more readbale<commit_after>import pycorpora
import random
import json
from sys import modules


def build_a_sentence():
    return a_netflix_category() + " with " + a_character() + " Who " + an_action()


def a_netflix_category():
    return random.choice(netflix_categories()['categories'])['name']


def netflix_categories():
    return json.loads(open("netflix-categories.json").read())


def a_character():
    # Pick a function to generate the featured charater of this category
    pick = random.choice(["a_qualified_character_type", "an_animal"])
    return getattr(_this_module(), pick)()


def a_qualified_character_type():
    rct = a_character_type()
    quality = rct.get("quality", " ")
    ctype = rct['name']
    return a_or_an((quality + " " + ctype).strip().title())


def a_character_type():
    # Returns a json object of a character type with name, qualities, synonyms, etc.
    return random.choice(pycorpora.archetypes['character']['characters'])


def an_animal():
    return a_or_an(random.choice(pycorpora.animals["common"]["animals"]).title())



def an_action():
    pick = random.choice(["eat", "resume"])
    if pick is "eat":
        action = "Eats " + a_food()
    elif pick is "resume":
        action = a_resume_action_word() + " " + a_noun()
    else:
        action = ""
    return action


def a_food():
    pick = random.choice(["a_bread_or_pastry", "an_apple_type"])
    return getattr(_this_module(), pick)()


def a_bread_or_pastry():
    borp = random.choice(["breads", "pastries"])
    return a_or_an(random.choice(pycorpora.foods["breads_and_pastries"][borp]).title())


def an_apple_type():
    return a_or_an(random.choice(pycorpora.foods['apple_cultivars']['cultivars']).title())


def a_noun():
    return a_or_an(random.choice(pycorpora.words['nouns']['nouns']).title())


def a_resume_action_word():
    return random.choice(pycorpora.words["resume_action_words"]["resume_action_words"]).title()


def a_or_an(word):
    vowels = ["a", "e", "i", "o" "u"]
    if word.lower()[0] in vowels:
        article = "an "
    else:
        article = "a "
    return article + word


def _this_module():
    return modules[__name__]


if __name__ == '__main__':
    print build_a_sentence()
{'fraction_non_alphanumeric': 0.15361924211481734, 'fraction_numerical': 0.0004538234626730202, 'mean_word_length': 4.279041916167665, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1596899', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1487, 'n_words': 305}