Debian Codegraph @

gram/OTGrammar_ex_metrics.cpp

raw
1 /* OTGrammar_ex_metrics.cpp
2 *
3 * Copyright (C) 2001-2007,2009,2011,2012,2014-2022 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 /*
20 * pb 2001/11/25
21 * pb 2002/07/16 GPL
22 * pb 2003/03/31 removeConstraint
23 * pb 2003/05/09 added Peripheral and MainNonfinal
24 * pb 2004/01/14 added HeadNonfinal
25 * pb 2004/01/25 added overtFormsHaveSecondaryStress
26 * pb 2004/07/27 added Clash and Lapse
27 * pb 2004/08/11 complete rewrite in order to include WeightByPosition and *MoraicConsonant
28 * pb 2004/12/03 corrected *Lapse
29 * pb 2007/07/23 constraint plasticity
30 * pb 2007/08/12 wchar
31 * pb 2011/03/29 C++
32 * pb 2011/06/29 C++
33 */
34
35 #include "OTGrammar.h"
36
37 #define WSP 1
38 #define FtNonfinal 2
39 #define Iambic 3
40 #define Parse 4
41 #define FootBin 5
42 #define WFL 6
43 #define WFR 7
44 #define Main_L 8
45 #define Main_R 9
46 #define AFL 10
47 #define AFR 11
48 #define Nonfinal 12
49
50 #define Trochaic 13
51 #define FootBimoraic 14
52 #define FootBisyllabic 15
53 #define Peripheral 16
54 #define MainNonfinal 17
55 #define HeadNonfinal 18
56 #define Clash 19
57 #define Lapse 20
58
59 #define WeightByPosition 21
60 #define MoraicConsonant 22
61
62 #define NUMBER_OF_CONSTRAINTS 22
63
64 static const conststring32 constraintNames [1+NUMBER_OF_CONSTRAINTS] = { 0,
65 U"WSP", U"FtNonfinal", U"Iambic", U"Parse", U"FootBin", U"WFL", U"WFR", U"Main-L", U"Main-R", U"AFL", U"AFR", U"Nonfinal",
66 U"Trochaic", U"FtBimor", U"FtBisyl", U"Peripheral", U"MainNonfinal", U"HeadNonfinal", U"*Clash", U"*Lapse", U"WeightByPosition", U"*C\\mu" };
67
68 static void addCandidate (OTGrammarTableau me, integer numberOfSyllables, int stress [],
69 bool footedToTheLeft [], bool footedToTheRight [], int surfaceWeightPattern [],
70 bool overtFormsHaveSecondaryStress)
71 {
72 static const conststring32 syllable [] =
73 { U"L", U"L1", U"L2", U"H", U"H1", U"H2", U"K", U"K1", U"K2", U"J", U"J1", U"J2" };
74 static const conststring32 syllableWithoutSecondaryStress [] =
75 { U"L", U"L1", U"L", U"H", U"H1", U"H", U"K", U"K1", U"K", U"J", U"J1", U"J" };
76 char32 output [100];
77 str32cpy (output, U"[");
78 for (integer isyll = 1; isyll <= numberOfSyllables; isyll ++) {
79 if (isyll > 1)
80 str32cat (output, U" ");
81 str32cat (output, ( overtFormsHaveSecondaryStress ? syllable : syllableWithoutSecondaryStress )
82 [stress [isyll] + 3 * (surfaceWeightPattern [isyll] - 1)]);
83 }
84 str32cat (output, U"] \\-> /");
85 for (integer isyll = 1; isyll <= numberOfSyllables; isyll ++) {
86 if (isyll > 1)
87 str32cat (output, U" ");
88 if (footedToTheRight [isyll] || (! footedToTheLeft [isyll] && stress [isyll] != 0))
89 str32cat (output, U"(");
90 str32cat (output, syllable [stress [isyll] + 3 * (surfaceWeightPattern [isyll] - 1)]);
91 if (footedToTheLeft [isyll] || (! footedToTheRight [isyll] && stress [isyll] != 0))
92 str32cat (output, U")");
93 }
94 str32cat (output, U"/");
95 my candidates [++ my numberOfCandidates]. output = Melder_dup (output);
96 }
97
98 static void fillSurfaceWeightPattern (OTGrammarTableau me, integer numberOfSyllables, int stress [],
99 bool footedToTheLeft [], bool footedToTheRight [], int underlyingWeightPattern [],
100 bool overtFormsHaveSecondaryStress)
101 {
102 int surfaceWeightPattern [1+7], minSurfaceWeight [1+7], maxSurfaceWeight [1+7];
103 for (integer isyll = 1; isyll <= numberOfSyllables; isyll ++) {
104 if (underlyingWeightPattern [isyll] < 3) {
105 minSurfaceWeight [isyll] = maxSurfaceWeight [isyll] = underlyingWeightPattern [isyll]; // L -> L; H -> H
106 } else {
107 minSurfaceWeight [isyll] = 3;
108 maxSurfaceWeight [isyll] = 4; // C -> { J, K }
109 }
110 }
111 surfaceWeightPattern [6] = surfaceWeightPattern [7] = 1; // constant L
112 for (int weight1 = minSurfaceWeight [1]; weight1 <= maxSurfaceWeight [1]; weight1 ++) {
113 surfaceWeightPattern [1] = weight1;
114 for (int weight2 = minSurfaceWeight [2]; weight2 <= maxSurfaceWeight [2]; weight2 ++) {
115 surfaceWeightPattern [2] = weight2;
116 if (numberOfSyllables == 2) {
117 addCandidate (me, 2, stress, footedToTheLeft, footedToTheRight, surfaceWeightPattern, overtFormsHaveSecondaryStress);
118 } else for (int weight3 = minSurfaceWeight [3]; weight3 <= maxSurfaceWeight [3]; weight3 ++) {
119 surfaceWeightPattern [3] = weight3;
120 if (numberOfSyllables == 3) {
121 addCandidate (me, 3, stress, footedToTheLeft, footedToTheRight, surfaceWeightPattern, overtFormsHaveSecondaryStress);
122 } else for (int weight4 = minSurfaceWeight [4]; weight4 <= maxSurfaceWeight [4]; weight4 ++) {
123 surfaceWeightPattern [4] = weight4;
124 if (numberOfSyllables == 4) {
125 addCandidate (me, 4, stress, footedToTheLeft, footedToTheRight, surfaceWeightPattern, overtFormsHaveSecondaryStress);
126 } else for (int weight5 = minSurfaceWeight [5]; weight5 <= maxSurfaceWeight [5]; weight5 ++) {
127 surfaceWeightPattern [5] = weight5;
128 addCandidate (me, numberOfSyllables, stress, footedToTheLeft, footedToTheRight, surfaceWeightPattern, overtFormsHaveSecondaryStress);
129 }
130 }
131 }
132 }
133 }
134 }
135
136 static void path (OTGrammarTableau me, integer numberOfSyllables, int stress [],
137 int startingSyllable, bool footedToTheLeft_in [], bool footedToTheRight_in [], int underlyingWeightPattern [],
138 bool overtFormsHaveSecondaryStress)
139 {
140 bool footedToTheLeft [10], footedToTheRight [10];
141 /* Localize all arguments. */
142 for (integer isyll = 1; isyll <= startingSyllable; isyll ++) {
143 footedToTheLeft [isyll] = footedToTheLeft_in [isyll];
144 footedToTheRight [isyll] = footedToTheRight_in [isyll];
145 }
146 for (integer isyll = startingSyllable + 1; isyll <= numberOfSyllables; isyll ++)
147 footedToTheLeft [isyll] = footedToTheRight [isyll] = 0;
148 if (startingSyllable > numberOfSyllables) {
149 fillSurfaceWeightPattern (me, numberOfSyllables, stress, footedToTheLeft, footedToTheRight, underlyingWeightPattern, overtFormsHaveSecondaryStress);
150 } else {
151 path (me, numberOfSyllables, stress, startingSyllable + 1,
152 footedToTheLeft, footedToTheRight, underlyingWeightPattern, overtFormsHaveSecondaryStress);
153 if (stress [startingSyllable] == 0 && startingSyllable < numberOfSyllables && stress [startingSyllable + 1] != 0) {
154 footedToTheLeft [startingSyllable + 1] = true;
155 footedToTheRight [startingSyllable] = true;
156 path (me, numberOfSyllables, stress, startingSyllable + 1,
157 footedToTheLeft, footedToTheRight, underlyingWeightPattern, overtFormsHaveSecondaryStress);
158 footedToTheLeft [startingSyllable + 1] = false;
159 footedToTheRight [startingSyllable] = false;
160 }
161 if (stress [startingSyllable] == 0 && startingSyllable > 1 && stress [startingSyllable - 1] != 0
162 && ! footedToTheLeft [startingSyllable - 1])
163 {
164 footedToTheRight [startingSyllable - 1] = true;
165 footedToTheLeft [startingSyllable] = true;
166 path (me, numberOfSyllables, stress, startingSyllable + 1,
167 footedToTheLeft, footedToTheRight, underlyingWeightPattern, overtFormsHaveSecondaryStress);
168 }
169 }
170 }
171
172 static void fillOvertStressPattern (OTGrammarTableau me, integer numberOfSyllables, int stress [], int underlyingWeightPattern [],
173 bool overtFormsHaveSecondaryStress)
174 {
175 bool footedToTheLeft [10], footedToTheRight [10];
176 for (int isyll = 1; isyll <= numberOfSyllables; isyll ++)
177 footedToTheLeft [isyll] = footedToTheRight [isyll] = 0;
178 path (me, numberOfSyllables, stress, 1, footedToTheLeft, footedToTheRight, underlyingWeightPattern, overtFormsHaveSecondaryStress);
179 }
180
181 static void fillTableau (OTGrammarTableau me, integer numberOfSyllables, int underlyingWeightPattern [], bool overtFormsHaveSecondaryStress, bool includeCodas) {
182 char32 input [100];
183 static int numberOfCandidates_noCodas [1+7] =
184 { 0, 1, 6, 24, 88, 300, 984, 3136 };
185 static int numberOfCandidates_codas [1+7] =
186 { 0, 1, 24, 192, 1408, 9600, 984, 3136 };
187 str32cpy (input, U"|");
188 for (integer isyll = 1; isyll <= numberOfSyllables; isyll ++) {
189 static const conststring32 syllable_noCodas [] = { U"", U"L", U"H" };
190 static const conststring32 syllable_codas [] = { U"", U"cv", U"cv:", U"cvc" };
191 if (isyll > 1)
192 str32cat (input, includeCodas ? U"." : U" ");
193 str32cat (input, ( includeCodas ? syllable_codas : syllable_noCodas ) [underlyingWeightPattern [isyll]]);
194 }
195 str32cat (input, U"|");
196 my input = Melder_dup (input);
197 my candidates = newvectorzero <structOTGrammarCandidate> (( includeCodas ? numberOfCandidates_codas : numberOfCandidates_noCodas ) [numberOfSyllables]);
198 for (integer mainStressed = 1; mainStressed <= numberOfSyllables; mainStressed ++) {
199 int stress [10];
200 stress [mainStressed] = 1;
201 for (int secondary1 = false; secondary1 <= true; secondary1 ++) {
202 stress [mainStressed <= 1 ? 2 : 1] = secondary1 ? 2 : 0;
203 if (numberOfSyllables == 2) {
204 fillOvertStressPattern (me, 2, stress, underlyingWeightPattern, overtFormsHaveSecondaryStress);
205 } else for (int secondary2 = false; secondary2 <= true; secondary2 ++) {
206 stress [mainStressed <= 2 ? 3 : 2] = secondary2 ? 2 : 0;
207 if (numberOfSyllables == 3) {
208 fillOvertStressPattern (me, 3, stress, underlyingWeightPattern, overtFormsHaveSecondaryStress);
209 } else for (int secondary3 = false; secondary3 <= true; secondary3 ++) {
210 stress [mainStressed <= 3 ? 4 : 3] = secondary3 ? 2 : 0;
211 if (numberOfSyllables == 4) {
212 fillOvertStressPattern (me, 4, stress, underlyingWeightPattern, overtFormsHaveSecondaryStress);
213 } else for (int secondary4 = false; secondary4 <= true; secondary4 ++) {
214 stress [mainStressed <= 4 ? 5 : 4] = secondary4 ? 2 : 0;
215 if (numberOfSyllables == 5) {
216 fillOvertStressPattern (me, 5, stress, underlyingWeightPattern, overtFormsHaveSecondaryStress);
217 } else for (int secondary5 = false; secondary5 <= true; secondary5 ++) {
218 stress [mainStressed <= 5 ? 6 : 5] = secondary5 ? 2 : 0;
219 if (numberOfSyllables == 6) {
220 fillOvertStressPattern (me, 6, stress, underlyingWeightPattern, overtFormsHaveSecondaryStress);
221 } else for (int secondary6 = false; secondary6 <= true; secondary6 ++) {
222 stress [mainStressed <= 6 ? 7 : 6] = secondary6 ? 2 : 0;
223 fillOvertStressPattern (me, 7, stress, underlyingWeightPattern, overtFormsHaveSecondaryStress);
224 }
225 }
226 }
227 }
228 }
229 }
230 }
231 }
232
233 static void computeViolationMarks (OTGrammarCandidate me) {
234 #define isHeavy(s) ((s) == 'H' || (s) == 'J')
235 #define isLight(s) ((s) == 'L' || (s) == 'K')
236 #define isSyllable(s) (isHeavy (s) || isLight (s))
237 #define isStress(s) ((s) == '1' || (s) == '2')
238 const char32 *firstSlash = str32chr (my output.get(), U'/');
239 const char32 *lastSlash = & my output [Melder_length (my output.get()) - 1];
240 my marks = zero_INTVEC (my numberOfConstraints = NUMBER_OF_CONSTRAINTS);
241 /* Violations of WSP: count all H not followed by 1 or 2. */
242 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++)
243 if (isHeavy (p [0]) && ! isStress (p [1]))
244 my marks [WSP] ++;
245 /* Violations of FtNonfinal: count all heads followed by ). */
246 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++)
247 if (isStress (p [0]) && p [1] == U')')
248 my marks [FtNonfinal] ++;
249 /* Violations of Iambic: count all heads not followed by ). */
250 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++)
251 if (isStress (p [0]) && p [1] != U')')
252 my marks [Iambic] ++;
253 /* Violations of Parse and Peripheral: count all syllables not between (). */
254 int depth = 0;
255 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++) {
256 if (p [0] == U'(')
257 depth ++;
258 else if (p [0] == U')')
259 depth --;
260 else if (isSyllable (p [0]) && depth != 1) {
261 my marks [Parse] ++;
262 if (p != firstSlash + 1 && p != lastSlash - 1)
263 my marks [Peripheral] ++;
264 }
265 }
266 /* Violations of FootBin: count all (L1) and (L2). */
267 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++)
268 if (isLight (p [0]) && p [-1] == U'(' && isStress (p [1]) && p [2] == ')')
269 my marks [FootBin] ++;
270 /* Violations of WFL: count all initial / not followed by (. */
271 if (firstSlash [1] != '(')
272 my marks [WFL] = 1;
273 /* Violations of WFR: count all final / not preceded by ). */
274 if (lastSlash [-1] != ')')
275 my marks [WFR] = 1;
276 /* Violations of Main_L: count syllables from foot containing X1 to left edge. */
277 {
278 char32 *p = str32chr (firstSlash, U'1');
279 for (; *p != U'('; p --) { }
280 for (; p != firstSlash; p --)
281 if (isSyllable (p [0]))
282 my marks [Main_L] ++;
283 }
284 /* Violations of Main_R: count syllables from foot containing X1 to right edge. */
285 {
286 char32 *p = str32chr (firstSlash, U'1');
287 for (; *p != U')'; p ++) { }
288 for (; p != lastSlash; p ++)
289 if (isSyllable (p [0]))
290 my marks [Main_R] ++;
291 }
292 /* Violations of AFL: count syllables from every foot to left edge. */
293 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++)
294 if (p [0] == U'(')
295 for (const char32 *q = p; q != firstSlash; q --)
296 if (isSyllable (q [0]))
297 my marks [AFL] ++;
298 /* Violations of AFR: count syllables from every foot to right edge. */
299 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++)
300 if (p [0] == U')')
301 for (const char32 *q = p; q != lastSlash; q ++)
302 if (isSyllable (q [0]))
303 my marks [AFR] ++;
304 /* Violations of Nonfinal: count all final / preceded by ). */
305 if (lastSlash [-1] == U')')
306 my marks [Nonfinal] = 1;
307 /* Violations of Trochaic: count all heads not preceded by (. */
308 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++)
309 if (isStress (p [0]) && p [-2] != U'(')
310 my marks [Trochaic] ++;
311 /* Violations of FootBimoraic: count weight between (). */
312 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++) {
313 if (p [0] == U'(') {
314 int weight = 0;
315 for (p ++; p [0] != U')'; p ++) {
316 if (isHeavy (p [0]))
317 weight += 2;
318 else if (isLight (p [0]))
319 weight += 1;
320 }
321 if (weight != 2)
322 my marks [FootBimoraic] ++;
323 }
324 }
325 /* Violations of FootBisyllabic: count all (X1) and (X2). */
326 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++) {
327 if (isSyllable (p [0]) && p [-1] == U'(' && isStress (p [1]) && p [2] == U')')
328 my marks [FootBisyllabic] ++;
329 }
330 /* Violations of MainNonfinal: count all final / preceded by ) preceded by 1 in the same foot. */
331 if (lastSlash [-1] == U')') {
332 for (const char32 *p = lastSlash - 2; ; p --) {
333 if (p [0] == U'2')
334 break;
335 if (p [0] == U'1') {
336 my marks [MainNonfinal] = 1;
337 break;
338 }
339 }
340 }
341 /* Violations of HeadNonfinal: count all final / preceded by ) directly preceded by 1, plus MainNonfinal. */
342 if (lastSlash [-1] == U')') {
343 if (lastSlash [-2] == U'1') {
344 my marks [HeadNonfinal] = 2;
345 } else {
346 for (const char32 *p = lastSlash - 2; ; p --) {
347 if (p [0] == U'2')
348 break;
349 if (p [0] == U'1') {
350 my marks [HeadNonfinal] = 1;
351 break;
352 }
353 }
354 }
355 }
356 /* Violations of *Clash: count all 1 and 2 followed by an 1 or 2 after the next L or H. */
357 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++) {
358 if (isStress (p [0])) {
359 for (const char32 *q = p + 1; q != lastSlash; q ++) {
360 if (isSyllable (q [0])) {
361 if (isStress (q [1]))
362 my marks [Clash] ++;
363 break;
364 }
365 }
366 }
367 }
368 /* Violations of *Lapse: count all sequences of three unstressed syllables. */
369 depth = 0;
370 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++) {
371 if (isSyllable (p [0])) {
372 if (isStress (p [1])) {
373 depth = 0;
374 } else {
375 if (++ depth > 2)
376 my marks [Lapse] ++;
377 }
378 }
379 }
380 /* Violations of WeightByPosition: count all K. */
381 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++)
382 if (p [0] == U'K')
383 my marks [WeightByPosition] ++;
384 /* Violations of *MoraicConsonant: count all J. */
385 for (const char32 *p = firstSlash + 1; p != lastSlash; p ++)
386 if (p [0] == U'J')
387 my marks [MoraicConsonant] ++;
388 }
389
390 static void replaceOutput (OTGrammarCandidate me) {
391 bool abstract = false;
392 Melder_assert (my output);
393 char32 newOutput [100], *q = & newOutput [0];
394 for (const char32 *p = & my output [0]; *p != U'\0'; p ++) {
395 if (p [0] == U' ') {
396 *q ++ = ( p [-1] == U']' || p [1] == U'/' ? U' ' : U'.' );
397 } else if (isSyllable (p [0])) {
398 *q ++ = U'c';
399 if (abstract) {
400 *q ++ = U'V';
401 if (isStress (p [1]))
402 *q ++ = p [1];
403 if (p [0] == U'L') {
404 ;
405 } else if (p [0] == U'H') {
406 *q ++ = U'V';
407 } else if (p [0] == U'K') {
408 *q ++ = U'c';
409 } else {
410 *q ++ = U'C';
411 }
412 } else {
413 *q ++ = U'v';
414 if (p [0] == U'L') {
415 ;
416 } else if (p [0] == U'H') {
417 *q ++ = U':';
418 } else {
419 *q ++ = U'c';
420 }
421 }
422 } else if (isStress (p [0]) && abstract) {
423 ;
424 } else {
425 if (p [0] == U'/')
426 abstract = true;
427 *q ++ = p [0];
428 }
429 }
430 *q = U'\0';
431 my output = Melder_dup (newOutput);
432 }
433
434 autoOTGrammar OTGrammar_create_metrics (
435 kOTGrammar_createMetricsGrammar_initialRanking equal_footForm_wsp,
436 int trochaicityConstraint, bool includeFootBimoraic, bool includeFootBisyllabic,
437 bool includePeripheral, int nonfinalityConstraint, bool overtFormsHaveSecondaryStress,
438 bool includeClashAndLapse, bool includeCodas)
439 {
440 try {
441 int underlyingWeightPattern [1+7], maximumUnderlyingWeight = ( includeCodas ? 3 : 2 );
442 const integer numberOfTableaus = ( includeCodas ? 9 + 27 + 81 + 243 + 2 : 62 );
443 autoOTGrammar me = Thing_new (OTGrammar);
444 my constraints = newvectorzero <structOTGrammarConstraint> (my numberOfConstraints = NUMBER_OF_CONSTRAINTS);
445 for (integer icons = 1; icons <= NUMBER_OF_CONSTRAINTS; icons ++) {
446 OTGrammarConstraint constraint = & my constraints [icons];
447 constraint -> name = Melder_dup (constraintNames [icons]);
448 constraint -> ranking = 100.0;
449 constraint -> plasticity = 1.0;
450 }
451 if (equal_footForm_wsp >= kOTGrammar_createMetricsGrammar_initialRanking::FOOT_FORM_HIGH) {
452 /*
453 Foot form constraints high.
454 */
455 my constraints [FtNonfinal]. ranking = 101.0;
456 my constraints [Iambic]. ranking = 101.0;
457 my constraints [Trochaic]. ranking = -1e9;
458 }
459 if (equal_footForm_wsp == kOTGrammar_createMetricsGrammar_initialRanking::WSP_HIGH) {
460 /*
461 Quantity sensitivity high, foot form constraints in the second stratum.
462 */
463 my constraints [WSP]. ranking = 102.0;
464 }
465 my tableaus = newvectorzero <structOTGrammarTableau> (numberOfTableaus);
466 for (int numberOfSyllables = 2; numberOfSyllables <= 7; numberOfSyllables ++) {
467 const integer numberOfUnderlyingWeightPatterns =
468 ( numberOfSyllables > 5 ? 1 : Melder_iround (pow (maximumUnderlyingWeight, numberOfSyllables)) );
469 for (integer isyll = 1; isyll <= numberOfSyllables; isyll ++)
470 underlyingWeightPattern [isyll] = 1; // L or cv
471 for (integer iweightPattern = 1; iweightPattern <= numberOfUnderlyingWeightPatterns; iweightPattern ++) {
472 fillTableau (& my tableaus [++ my numberOfTableaus], numberOfSyllables, underlyingWeightPattern, overtFormsHaveSecondaryStress, includeCodas);
473 /*
474 Cycle to next underlying weight pattern.
475 */
476 underlyingWeightPattern [numberOfSyllables] += 1;
477 for (integer isyll = numberOfSyllables; isyll >= 2; isyll --) {
478 if (underlyingWeightPattern [isyll] > maximumUnderlyingWeight) {
479 underlyingWeightPattern [isyll] = 1;
480 underlyingWeightPattern [isyll - 1] += 1;
481 }
482 }
483 }
484 }
485 /* Compute violation marks. */
486 for (integer itab = 1; itab <= my numberOfTableaus; itab ++) {
487 OTGrammarTableau tableau = & my tableaus [itab];
488 for (integer icand = 1; icand <= tableau -> numberOfCandidates; icand ++)
489 computeViolationMarks (& tableau -> candidates [icand]);
490 }
491 OTGrammar_checkIndex (me.get());
492 OTGrammar_newDisharmonies (me.get(), 0.0);
493 if (trochaicityConstraint == 1)
494 OTGrammar_removeConstraint (me.get(), U"Trochaic");
495 else
496 OTGrammar_removeConstraint (me.get(), U"FtNonfinal");
497 if (! includeFootBimoraic)
498 OTGrammar_removeConstraint (me.get(), U"FtBimor");
499 if (! includeFootBisyllabic)
500 OTGrammar_removeConstraint (me.get(), U"FtBisyl");
501 if (! includePeripheral)
502 OTGrammar_removeConstraint (me.get(), U"Peripheral");
503 if (nonfinalityConstraint == 1) {
504 OTGrammar_removeConstraint (me.get(), U"MainNonfinal");
505 OTGrammar_removeConstraint (me.get(), U"HeadNonfinal");
506 } else if (nonfinalityConstraint == 2) {
507 OTGrammar_removeConstraint (me.get(), U"HeadNonfinal");
508 OTGrammar_removeConstraint (me.get(), U"Nonfinal");
509 } else {
510 OTGrammar_removeConstraint (me.get(), U"MainNonfinal");
511 OTGrammar_removeConstraint (me.get(), U"Nonfinal");
512 }
513 if (! includeClashAndLapse) {
514 OTGrammar_removeConstraint (me.get(), U"*Clash");
515 OTGrammar_removeConstraint (me.get(), U"*Lapse");
516 }
517 if (! includeCodas) {
518 OTGrammar_removeConstraint (me.get(), U"WeightByPosition");
519 OTGrammar_removeConstraint (me.get(), U"*C\\mu");
520 }
521 if (includeCodas) {
522 for (integer itab = 1; itab <= my numberOfTableaus; itab ++) {
523 OTGrammarTableau tableau = & my tableaus [itab];
524 for (integer icand = 1; icand <= tableau -> numberOfCandidates; icand ++)
525 replaceOutput (& tableau -> candidates [icand]);
526 }
527 }
528 return me;
529 } catch (MelderError) {
530 Melder_throw (U"Metrics grammar not created.");
531 }
532 }
533
534 /* End of file OTGrammar_ex_metrics.cpp */