-
Notifications
You must be signed in to change notification settings - Fork 0
/
klingonSyllableGeneratorMARK2.php
64 lines (50 loc) · 2.29 KB
/
klingonSyllableGeneratorMARK2.php
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
<?
//Mad props to Dave Johnson for suggesting that the ow/uw filter be moved up to prevent those illicit syllables
//from even being added to the $syllables array in the first place.
//First, we lay out an array of every possible onset, nucleus(vowel), and coda.
//We'll loop through these arrays to create every logically possible combination.
//Also of note is that I'm using double quotes in PHP where I'd normally
//use single. This is because of the use of the single quote to represent
//the glottal stop.
$onsets = array("p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y");
$vowels = array("a", "e", "I", "o", "u");
$codas = array("p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y", "w'", "y'", "rgh");
//This global counts up to make sure each created syllable is added as it's created.
$syllableTicker = 0;
//This loop will create all our CV syllables.
for ($i = 0; $i < 21; $i++) {
for($j = 0; $j < 5; $j++) {
$syllables[$syllableTicker] = $onsets[$i] . $vowels[$j];
$syllableTicker++;
}
}
//Here we the current length of the array.
$syllablesCount = count($syllables);
//Now, we're going to create every logically possible combination of CV syllable and coda,
//but, we'll prevent any phonologically illicit syllables from being added to the $syllables array.
for ($i = 0; $i < $syllablesCount; $i++) {
for ($j = 0; $j < 24; $j++) {
$provisional = $syllables[$i] . $codas[$j];
$check = substr($provisional, 1, 2);
$checkTwo = substr($provisional, 2, 2);
$checkThree = substr($provisional, 3, 2);
if ($check != "ow" && $check != "uw") {
if ($checkTwo != "ow" && $checkTwo != "uw") {
if ($checkThree != "ow" && $checkThree != "uw") {
$syllables[$syllableTicker] = $provisional;
$syllableTicker++;
}
}
}
}
}
//And now we take the full length of the syllable array.
$syllablesCount = count($syllables);
//Last, we echo out all our generated syllables plus two others that cannot be generated from the arrays above,
//because they are special cases. Therefore, we simply echo them.
for ($i = 0; $i < $syllablesCount; $i++) {
echo $syllables[$i] . "<br>";
}
echo "oy" . "<br>";
echo "sto" . "<br>";
?>