| 1 |
/* OTGrammar_ex_tongueRoot.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1997-2005,2007,2009,2011-2013,2015-2021 Paul Boersma |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
* See the GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "OTGrammar.h" |
| 20 |
|
| 21 |
static const conststring32 vowels [] = { U"i", U"e", U"\\sw", U"\\ic", U"\\ef", U"a" }; |
| 22 |
#define i 0 |
| 23 |
#define e 1 |
| 24 |
#define schwa 2 |
| 25 |
#define I 3 |
| 26 |
#define E 4 |
| 27 |
#define a 5 |
| 28 |
#define isatr(v) ((v) <= schwa) |
| 29 |
#define isrtr(v) ((v) >= I) |
| 30 |
#define fliptr(v) (((v) + 3) % 6) |
| 31 |
|
| 32 |
static void countVowelViolations (const INTVEC marks, const integer numberOfConstraints, const integer v) { |
| 33 |
if (v == I) |
| 34 |
marks [1] ++; |
| 35 |
if (v == schwa) |
| 36 |
marks [2] ++; |
| 37 |
if (numberOfConstraints == 9) { |
| 38 |
if (v == E) |
| 39 |
marks [6] ++; |
| 40 |
if (v == a) |
| 41 |
marks [7] ++; |
| 42 |
if (v == e) |
| 43 |
marks [8] ++; |
| 44 |
if (v == i) |
| 45 |
marks [9] ++; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
static void OTGrammarCandidate_init (OTGrammarCandidate me, integer ncons, integer v1, integer v2) { |
| 50 |
my output = Melder_dup (Melder_cat (vowels [v1], U"t", vowels [v2])); |
| 51 |
my marks = zero_INTVEC (my numberOfConstraints = ncons); |
| 52 |
/* |
| 53 |
Count vowel-gesture violations. |
| 54 |
*/ |
| 55 |
countVowelViolations (my marks.get(), ncons, v1); |
| 56 |
countVowelViolations (my marks.get(), ncons, v2); |
| 57 |
/* |
| 58 |
Count contour-gesture violations. |
| 59 |
*/ |
| 60 |
if (isatr (v1) != isatr (v2)) |
| 61 |
my marks [5] ++; |
| 62 |
} |
| 63 |
|
| 64 |
autoOTGrammar OTGrammar_create_tongueRoot_grammar ( |
| 65 |
kOTGrammar_createTongueRootGrammar_constraintSet small_large, |
| 66 |
kOTGrammar_createTongueRootGrammar_ranking equal_random_infant_Wolof) |
| 67 |
{ |
| 68 |
try { |
| 69 |
const integer numberOfConstraints = ( small_large == kOTGrammar_createTongueRootGrammar_constraintSet::FIVE ? 5 : 9 ); |
| 70 |
autoOTGrammar me = Thing_new (OTGrammar); |
| 71 |
my constraints = newvectorzero <structOTGrammarConstraint> (my numberOfConstraints = numberOfConstraints); |
| 72 |
my constraints [1]. name = Melder_dup (U"*[rtr / hi]"); |
| 73 |
my constraints [2]. name = Melder_dup (U"*[atr / lo]"); |
| 74 |
my constraints [3]. name = Melder_dup (U"P\\s{ARSE}\n(rtr)"); |
| 75 |
my constraints [4]. name = Melder_dup (U"P\\s{ARSE}\n(atr)"); |
| 76 |
my constraints [5]. name = Melder_dup (U"*G\\s{ESTURE}\n(contour)"); |
| 77 |
if (numberOfConstraints == 9) { |
| 78 |
my constraints [6]. name = Melder_dup (U"*[rtr / mid]"); |
| 79 |
my constraints [7]. name = Melder_dup (U"*[rtr / lo]"); |
| 80 |
my constraints [8]. name = Melder_dup (U"*[atr / mid]"); |
| 81 |
my constraints [9]. name = Melder_dup (U"*[atr / hi]"); |
| 82 |
} |
| 83 |
if (equal_random_infant_Wolof == kOTGrammar_createTongueRootGrammar_ranking::EQUAL) { |
| 84 |
for (integer icons = 1; icons <= numberOfConstraints; icons ++) |
| 85 |
my constraints [icons]. ranking = 100.0; |
| 86 |
} else if (equal_random_infant_Wolof == kOTGrammar_createTongueRootGrammar_ranking::RANDOM) { |
| 87 |
for (integer icons = 1; icons <= numberOfConstraints; icons ++) |
| 88 |
my constraints [icons]. ranking = NUMrandomGauss (100.0, 10.0); |
| 89 |
} else if (equal_random_infant_Wolof == kOTGrammar_createTongueRootGrammar_ranking::INFANT) { |
| 90 |
for (integer icons = 1; icons <= numberOfConstraints; icons ++) |
| 91 |
my constraints [icons]. ranking = 100.0; // structural constraints |
| 92 |
my constraints [3]. ranking = 50.0; // faithfulness constraints |
| 93 |
my constraints [4]. ranking = 50.0; |
| 94 |
} else { |
| 95 |
Melder_assert (equal_random_infant_Wolof == kOTGrammar_createTongueRootGrammar_ranking::WOLOF); |
| 96 |
my constraints [1]. ranking = 100.0; |
| 97 |
my constraints [2]. ranking = 10.0; |
| 98 |
my constraints [3]. ranking = 50.0; |
| 99 |
my constraints [4]. ranking = 20.0; |
| 100 |
my constraints [5]. ranking = 30.0; |
| 101 |
if (numberOfConstraints == 9) { |
| 102 |
my constraints [6]. ranking = 0.0; |
| 103 |
my constraints [7]. ranking = -10.0; |
| 104 |
my constraints [8]. ranking = 0.0; |
| 105 |
my constraints [9]. ranking = -10.0; |
| 106 |
} |
| 107 |
} |
| 108 |
if (numberOfConstraints == 9) { |
| 109 |
my fixedRankings = newvectorzero <structOTGrammarFixedRanking> (my numberOfFixedRankings = 4); |
| 110 |
my fixedRankings [1] = { 1, 6 }; |
| 111 |
my fixedRankings [2] = { 6, 7 }; |
| 112 |
my fixedRankings [3] = { 2, 8 }; |
| 113 |
my fixedRankings [4] = { 8, 9 }; |
| 114 |
} |
| 115 |
my tableaus = newvectorzero <structOTGrammarTableau> (my numberOfTableaus = 36); |
| 116 |
integer itab = 1; |
| 117 |
for (integer v1 = 0; v1 < 6; v1 ++) { |
| 118 |
for (integer v2 = 0; v2 < 6; v2 ++) { |
| 119 |
OTGrammarTableau tableau = & my tableaus [itab]; |
| 120 |
tableau -> input = Melder_dup (Melder_cat (vowels [v1], U"t", vowels [v2])); |
| 121 |
tableau -> candidates = newvectorzero <structOTGrammarCandidate> (tableau -> numberOfCandidates = 4); |
| 122 |
/* |
| 123 |
Generate the four tongue-root variants as output candidates. |
| 124 |
*/ |
| 125 |
OTGrammarCandidate_init (& tableau -> candidates [1], numberOfConstraints, v1, v2); |
| 126 |
/* Faithful: no PARSE constraints violated. */ |
| 127 |
OTGrammarCandidate_init (& tableau -> candidates [2], numberOfConstraints, fliptr (v1), v2); |
| 128 |
/* First vowel flipped: violated one PARSE constraint. */ |
| 129 |
OTGrammarCandidate_init (& tableau -> candidates [3], numberOfConstraints, v1, fliptr (v2)); |
| 130 |
/* Second vowel flipped. */ |
| 131 |
OTGrammarCandidate_init (& tableau -> candidates [4], numberOfConstraints, fliptr (v1), fliptr (v2)); |
| 132 |
/* Both vowels flipped. */ |
| 133 |
/* |
| 134 |
Count PARSE violations. |
| 135 |
*/ |
| 136 |
if (isatr (v1)) { |
| 137 |
tableau -> candidates [2]. marks [4] ++; |
| 138 |
tableau -> candidates [4]. marks [4] ++; |
| 139 |
} else { |
| 140 |
tableau -> candidates [2]. marks [3] ++; |
| 141 |
tableau -> candidates [4]. marks [3] ++; |
| 142 |
} |
| 143 |
if (isatr (v2)) { |
| 144 |
tableau -> candidates [3]. marks [4] ++; |
| 145 |
tableau -> candidates [4]. marks [4] ++; |
| 146 |
} else { |
| 147 |
tableau -> candidates [3]. marks [3] ++; |
| 148 |
tableau -> candidates [4]. marks [3] ++; |
| 149 |
} |
| 150 |
itab ++; |
| 151 |
} |
| 152 |
} |
| 153 |
OTGrammar_checkIndex (me.get()); |
| 154 |
OTGrammar_newDisharmonies (me.get(), 0.0); |
| 155 |
for (integer icons = 1; icons <= my numberOfConstraints; icons ++) |
| 156 |
my constraints [icons]. plasticity = 1.0; |
| 157 |
return me; |
| 158 |
} catch (MelderError) { |
| 159 |
Melder_throw (U"Tongue root grammar not created."); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
/* End of file OTGrammar_ex_tongueRoot.cpp */ |