auto name gen

This commit is contained in:
2026-06-24 16:52:55 -04:00
parent 54b0c5cb8c
commit 144625cb5b
7 changed files with 14595 additions and 10 deletions

View File

@@ -1,6 +1,8 @@
import csv
import random
from collections import defaultdict
from untitled import content
from untitled import content, rules
def generate_trait_sentence(traits):
@@ -26,3 +28,67 @@ 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 len(name) <= 9
and rules.validate_cat_name(name) is None
):
return name.capitalize()
def _load_raw_names():
names = []
with open("untitled/assets/nameset.csv", newline="", encoding="utf-8") as file:
reader = csv.reader(file)
next(reader)
for row in reader:
name = row[5].lower()
if (
name == "name not provided"
or name == "untitled"
or name == "unknown"
or name == "kitten"
or not name
):
continue
if name.isalpha():
names.append(name)
return names
_model = _build_model(_pad_names_for_model(_load_raw_names()))