Пример #1
0
def write_out_list_and_collect(list, shuffle):
    """
    :param list: The list to iterate over
    :param shuffle: True if the list should be shuffled prior to listing
    :return: a phrase shuch as "two list[0], a list[1], and twenty-eight list[2]." Or [a list[1] and a list[2]
    """
    list_phrase = ""

    collected = {}
    for thing in list:
        if thing in collected.keys():
            collected[thing] += 1
        else:
            collected[thing] = 1

    if len(collected.keys()) == 1:
        for i, (key, value) in enumerate(collected.items()):
            if value > 1:
                number = num_to_words.num_to_words(value)
                name = key.name_plural
            else:
                number = a_or_an.a_or_an(key.name)
                name = key.name
            list_phrase = number + " " + name
    elif len(collected.keys()) == 2:
        for i, (key, value) in enumerate(collected.items()):
            if value > 1:
                number = num_to_words.num_to_words(value)
                name = key.name_plural
            else:
                number = a_or_an.a_or_an(key.name)
                name = key.name
            if i == 0:
                list_phrase = number + " " + name + " and "
            else:
                list_phrase += number + " " + name
    else:
        for i, (key, value) in enumerate(collected.items()):
            if value > 1:
                number = num_to_words.num_to_words(value)
                name = key.name_plural
            else:
                number = a_or_an.a_or_an(key.name)
                name = key.name
            list_phrase += number + " " + name
            if i < len(list) - 2:
                list_phrase += ', '
            elif i == len(list) - 2:
                list_phrase += ', and '
    return list_phrase
Пример #2
0
def write_out_list(list, shuffle):
    """
    :param list: The list to iterate over
    :param shuffle: True if the list should be shuffled prior to listing
    :return: a phrase shuch as "a list[0], and list[1], and twelve list[2]." Or [a list[1] and a list[2]
    """
    list_phrase = ""
    if shuffle:
        random.shuffle(list)
    if len(list) == 2:
        list_phrase += a_or_an.a_or_an(list[0].__str__()) + " " + list[0].__str__() + " and " + a_or_an.a_or_an(list[1].__str__()) + " " + list[1].__str__()
    else:
        for i in range(len(list)):
            list_phrase += a_or_an.a_or_an(list[i].__str__()) + " " + list[i].__str__()
            if i < len(list) - 2:
                list_phrase += ', '
            elif i == len(list) - 2:
                list_phrase += ', and '
    return list_phrase
Пример #3
0
 def render(self, **kwargs):
     new_kwargs = {}
     for key, val in kwargs.items():
         if isinstance(val, (str)):
             parts = val.split('|')
             part_choice = random.choice(parts)
             new_kwargs[key] = part_choice
         else:
             part_choice = random.choice(val)
             new_kwargs[key] = part_choice
     while VAR_TOKEN_START in self.contents:
         self.contents = self.root.render(new_kwargs)
         self.root = Compiler(self.contents).compile()
     tokens = self.contents.split(" ")
     prev_token = None
     return_sentence = ""
     for token in tokens:
         if prev_token == A_OR_AN_TOK:
             prev_token = a_or_an.a_or_an(token)
         if prev_token == A_OR_AN_CAP_TOK:
             prev_token = a_or_an.a_or_an(token).title()
         if prev_token == HE_OR_SHE_TOK:
             prev_token = gender_pronoun.he_or_she(token)
             token = ""
         if prev_token == HE_OR_SHE_CAP_TOK:
             prev_token = gender_pronoun.he_or_she(token).title()
             token = ""
         if prev_token == HIM_OR_HER_TOK:
             prev_token = gender_pronoun.him_or_her(token)
             token = ""
         if prev_token == HIM_OR_HER_CAP_TOK:
             prev_token = gender_pronoun.him_or_her(token).title()
             token = ""
         if prev_token is not None:
             return_sentence += prev_token + " "
         prev_token = token
     return_sentence += token
     return return_sentence
Пример #4
0
 def __str__(self):
     return a_or_an.a_or_an(self.race) + ' ' + self.race + ' ' + self.job
Пример #5
0
 def __init__(self):
     self.description = templates.Template("{{adj}} {{connector}}").render(adj=vocab.get_ruin_connector_adj(),
                                                               connector=vocab.get_ruin_connector())
     self.description = a_or_an.a_or_an(self.description) + " " + self.description