72 lines
1.5 KiB
Python
72 lines
1.5 KiB
Python
# 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)
|