auto name gen
This commit is contained in:
71
testing/namegen.py
Normal file
71
testing/namegen.py
Normal file
@@ -0,0 +1,71 @@
|
||||
# THIS WAS ADDED TO MAIN PROGRAM
|
||||
|
||||
import csv
|
||||
import random
|
||||
from collections import defaultdict
|
||||
|
||||
from untitled import rules
|
||||
|
||||
NAME_CORPUS = []
|
||||
|
||||
with open("nameset.csv", newline="", encoding="utf-8") as file:
|
||||
reader = csv.reader(file)
|
||||
|
||||
header = 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():
|
||||
NAME_CORPUS.append(name)
|
||||
|
||||
|
||||
def pad(names):
|
||||
new_names = []
|
||||
for name in names:
|
||||
new_names.append(f"<<{name}>")
|
||||
return new_names
|
||||
|
||||
|
||||
def build(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(model):
|
||||
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
|
||||
|
||||
|
||||
names = pad(NAME_CORPUS)
|
||||
model = dict(build(names))
|
||||
while True:
|
||||
name = generate_name(model)
|
||||
if name not in NAME_CORPUS:
|
||||
print(name)
|
||||
@@ -1,4 +1,4 @@
|
||||
from untitled import generation
|
||||
from untitled import generation, rules
|
||||
|
||||
|
||||
def test_cat_description_gen():
|
||||
@@ -18,3 +18,11 @@ def test_cat_description_gen():
|
||||
an = "An average sized tuxedo kitten with blue eyes who judges you silently"
|
||||
assert generation.generate_trait_sentence(traits_a) == a
|
||||
assert generation.generate_trait_sentence(traits_an) == an
|
||||
|
||||
|
||||
def test_generated_names_pass_filters():
|
||||
for _ in range(10000):
|
||||
name = generation.generate_name()
|
||||
assert rules.validate_cat_name(name) is None
|
||||
assert any(c in "aeiouy" for c in name.lower())
|
||||
assert len(name) <= 9
|
||||
|
||||
14394
untitled/assets/nameset.csv
Normal file
14394
untitled/assets/nameset.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -32,3 +32,41 @@ CAT_PERSONALITIES = [ # TODO: start at different happiness levels based on pers
|
||||
"just wants to be somewhere else",
|
||||
]
|
||||
CAT_EYE_COLORS = ["green", "yellow", "blue", "orange"]
|
||||
|
||||
|
||||
NAME_ONSETS = [
|
||||
"b",
|
||||
"br",
|
||||
"tr",
|
||||
"m",
|
||||
"p",
|
||||
"k",
|
||||
"s",
|
||||
"sk",
|
||||
"wh",
|
||||
"fl",
|
||||
"n",
|
||||
"j",
|
||||
"d",
|
||||
"g",
|
||||
"ch",
|
||||
"th",
|
||||
]
|
||||
NAME_VOWELS = ["a", "e", "i", "o", "u", "oo", "ee", "ai"]
|
||||
NAME_CODAS = [
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"n",
|
||||
"x",
|
||||
"ff",
|
||||
"sk",
|
||||
"t",
|
||||
"p",
|
||||
"ll",
|
||||
] # empty entries = "often no coda"
|
||||
|
||||
@@ -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()))
|
||||
|
||||
@@ -3,8 +3,8 @@ from untitled import generation, model, rules, ui
|
||||
|
||||
def adoption():
|
||||
print("Welcome to the shelter!")
|
||||
|
||||
while True:
|
||||
auto_name = ""
|
||||
choice = "Reroll"
|
||||
while choice == "Reroll":
|
||||
choices = generation.generate_cat_choices()
|
||||
@@ -14,11 +14,19 @@ def adoption():
|
||||
)
|
||||
|
||||
while True:
|
||||
name = ui.text("Please choose a name for your cat:")
|
||||
name = ui.text(
|
||||
'Please choose a name for your cat or type "idk" to autofill a generated one:',
|
||||
auto_name,
|
||||
)
|
||||
if name.lower() != "idk":
|
||||
auto_name = ""
|
||||
error = rules.validate_cat_name(name)
|
||||
if not error:
|
||||
break
|
||||
print(error)
|
||||
else:
|
||||
auto_name = generation.generate_name()
|
||||
|
||||
if ui.confirm(
|
||||
f"Do you want to adopt {name}, {generation.generate_trait_sentence(choice).lower()}?"
|
||||
):
|
||||
|
||||
@@ -40,8 +40,8 @@ def select(title, options):
|
||||
return questionary.select(title, options).ask()
|
||||
|
||||
|
||||
def text(title):
|
||||
return questionary.text(title).ask()
|
||||
def text(title, default):
|
||||
return questionary.text(title, default=default).ask()
|
||||
|
||||
|
||||
def confirm(title):
|
||||
|
||||
Reference in New Issue
Block a user