stuff
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import random
|
||||
from collections import defaultdict
|
||||
|
||||
from untitled import PACKAGE_ROOT, content, rules
|
||||
from untitled import content
|
||||
|
||||
|
||||
def generate_trait_sentence(traits):
|
||||
@@ -27,53 +26,3 @@ def generate_cat_choice(personality=None):
|
||||
def generate_cat_choices(n=5):
|
||||
personalities = random.sample(content.CAT_PERSONALITIES, n)
|
||||
return [generate_cat_choice(p) for p in personalities]
|
||||
|
||||
|
||||
# NAME GEN MODEL
|
||||
|
||||
|
||||
def _pad_names_for_model(names):
|
||||
new_names = []
|
||||
for name in names:
|
||||
new_names.append(f"<<{name}>")
|
||||
return new_names
|
||||
|
||||
|
||||
def _build_model(words):
|
||||
model = defaultdict(list)
|
||||
for word in words:
|
||||
for pos in range(len(word) - 2):
|
||||
model[word[pos] + word[pos + 1]].append(word[pos + 2])
|
||||
return model
|
||||
|
||||
|
||||
def _make_name(model):
|
||||
result = "<<"
|
||||
while True:
|
||||
window = result[-2:]
|
||||
nxt = random.choice(model[window])
|
||||
if nxt == ">":
|
||||
break
|
||||
result += nxt
|
||||
return result.removeprefix("<<")
|
||||
|
||||
|
||||
def generate_name():
|
||||
while True:
|
||||
name = _make_name(_model)
|
||||
if (
|
||||
any(c in "aeiou" for c in name.lower())
|
||||
and rules.validate_cat_name(name, auto_gen=True) is None
|
||||
):
|
||||
return name.capitalize()
|
||||
|
||||
|
||||
def _load_raw_names():
|
||||
names = []
|
||||
with open(PACKAGE_ROOT / "assets" / "cat_names.txt") as f:
|
||||
for name in f.readlines():
|
||||
names.append(name.strip())
|
||||
return names
|
||||
|
||||
|
||||
_model = _build_model(_pad_names_for_model(_load_raw_names()))
|
||||
|
||||
Reference in New Issue
Block a user