-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc_words.py
153 lines (98 loc) · 3.91 KB
/
c_words.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# caemattos word generator
# ae = ash
# THE RULES
# A doubled letter represents a different sound than a single letter
# In a syllable: onset = starting consonants, nucleus = middle vowels, coda = ending consonants
# (C)VC syllable structure
# Onset must be 1 sound (or there can be no onset)
# Coda is most often 1 sound and cannot be more than 2 sounds
# Pretty much every non-inflected word ends in a consonant
# Fricative (as well as LL and R) + stop is allowed in the coda
# Neither H nor Y are allowed in the coda
import random as rd
from numpy.random import choice
# converts weight numbers so that they sum to 1
def convert(list):
newlist = []
for n in list:
new = n/float(sum(list))
newlist.append(new)
return newlist
def gen_syll(prevcn):
# prevcn stands for previous coda number
vowels = ["a", "ae", "e", "i", "o", "u"]
# I don't necessary classify consonants correctly here -- for example, LL is not a fricative and Y is, but I'm classifying them this way to make it all easier for myself
# the numbers in the dict are weights
consonantdict = {"d": ["fric", 5], "dd": ["fric", 4], "c": ["stop", 6], "cc": ["stop", 3], "f": ["fric", 5], "ff": ["fric", 3], "h": ["other", 3], "hh": ["other", 2], "l": ["other", 4], "ll": ["fric", 4], "m": ["other", 5], "n": ["other", 6], "nn": ["other", 2], "p": ["stop", 3], "pp": ["stop", 2], "r": ["fric", 5], "rr": ["other", 2], "s": ["fric", 5], "ss": ["fric", 3], "t": ["stop", 5], "tt": ["stop", 3], "y": ["other", 4], "yy": ["other", 2], "z": ["fric", 4], "zz": ["fric", 3]}
consonants = sorted(consonantdict.keys())
weights = []
fricdict = {}
stopdict = {}
fricweights = []
stopweights = []
# creates separate lists for fricatives and stops
for letter in consonants:
weights.append(consonantdict[letter][1])
if consonantdict[letter][0] == "fric":
fricdict.update({letter: consonantdict[letter][1]})
if consonantdict[letter][0] == "stop":
stopdict.update({letter: consonantdict[letter][1]})
weights = convert(weights)
syll = ""
# is there an onset? 0 = no; 1 = yes. if there were 2 consonants in the previous syllable's coda, there will be no onset in this coda
if prevcn == 2:
is_onset = 0
else:
is_onset = rd.randint(0,1)
if is_onset == 1:
onset = choice(consonants, p=weights)
syll = syll + onset
# nucleus
syll = syll + rd.choice(vowels)
# coda
# are there two consonants in the coda? picking from 6 numbers to make the probability of 2 consonants smaller
coda_num = rd.randint(1,6)
if not coda_num == 2:
coda_num = 1
# the letters in the list "no" cannot be present in the coda
# if there are 2 letters in the coda, there are certain rules (described above) about what they can be
no = ["h", "hh", "y", "yy"]
if coda_num == 2:
for key in sorted(fricdict.keys()):
if key not in no:
fricweights.append(fricdict[key])
fricweights = convert(fricweights)
fric = choice(fricdict.keys(), p=fricweights)
filtered = [letter for letter in stopdict.keys() if (len(letter) == len(fric) or letter == "r")]
for key in filtered:
stopweights.append(stopdict[key])
stopweights = convert(stopweights)
syll = syll + fric + choice(filtered, p=stopweights)
else:
endcons = []
endweights = []
for letter in consonants:
if letter not in no:
endcons.append(letter)
for key in consonants:
if key in endcons:
endweights.append(consonantdict[key][1])
endweights = convert(endweights)
syll = syll + choice(endcons, p=endweights)
return [syll, coda_num]
# generates a word made from syllables
# also tells the syllable it's generating about the coda of the previous syllable
def generate():
coda_num = 1
word = ""
syllnum = rd.randint(1,3)
for x in range(syllnum):
output = gen_syll(coda_num)
syll = output[0]
coda_num = output[1]
word = word + syll
return word
wordlist = []
for y in range(0,11):
wordlist.append(generate())
print wordlist