static void menu_cb_removeConstraint (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); OTGrammar ot = (OTGrammar) my data; OTGrammarConstraint constraint; if (my selected < 1 || my selected > ot -> numberOfConstraints) Melder_throw (U"Select a constraint first."); constraint = & ot -> constraints [ot -> index [my selected]]; Editor_save (me, U"Remove constraint"); OTGrammar_removeConstraint (ot, constraint -> name); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); }
OTGrammar OTGrammar_create_metrics (int equal_footForm_wsp, int trochaicityConstraint, int includeFootBimoraic, int includeFootBisyllabic, int includePeripheral, int nonfinalityConstraint, int overtFormsHaveSecondaryStress, int includeClashAndLapse, int includeCodas) { try { int underlyingWeightPattern [1+7], maximumUnderlyingWeight = includeCodas ? 3 : 2; long numberOfTableaus = includeCodas ? 9 + 27 + 81 + 243 + 2 : 62; autoOTGrammar me = Thing_new (OTGrammar); my constraints = NUMvector <structOTGrammarConstraint> (1, my numberOfConstraints = NUMBER_OF_CONSTRAINTS); for (long icons = 1; icons <= NUMBER_OF_CONSTRAINTS; icons ++) { OTGrammarConstraint constraint = & my constraints [icons]; constraint -> name = Melder_wcsdup (constraintNames [icons]); constraint -> ranking = 100.0; constraint -> plasticity = 1.0; } if (equal_footForm_wsp >= 2) { /* Foot form constraints high. */ my constraints [FtNonfinal]. ranking = 101.0; my constraints [Iambic]. ranking = 101.0; my constraints [Trochaic]. ranking = -1e9; } if (equal_footForm_wsp == 3) { /* Quantity sensitivity high, foot form constraints in the second stratum. */ my constraints [WSP]. ranking = 102.0; } my tableaus = NUMvector <structOTGrammarTableau> (1, numberOfTableaus); for (int numberOfSyllables = 2; numberOfSyllables <= 7; numberOfSyllables ++) { long numberOfUnderlyingWeightPatterns = numberOfSyllables > 5 ? 1 : (long) floor (pow (maximumUnderlyingWeight, numberOfSyllables) + 0.5); for (long isyll = 1; isyll <= numberOfSyllables; isyll ++) { underlyingWeightPattern [isyll] = 1; /* L or cv */ } for (long iweightPattern = 1; iweightPattern <= numberOfUnderlyingWeightPatterns; iweightPattern ++) { fillTableau (& my tableaus [++ my numberOfTableaus], numberOfSyllables, underlyingWeightPattern, overtFormsHaveSecondaryStress, includeCodas); /* * Cycle to next underlying weight pattern. */ underlyingWeightPattern [numberOfSyllables] += 1; for (long isyll = numberOfSyllables; isyll >= 2; isyll --) { if (underlyingWeightPattern [isyll] > maximumUnderlyingWeight) { underlyingWeightPattern [isyll] = 1; underlyingWeightPattern [isyll - 1] += 1; } } } } /* Compute violation marks. */ for (long itab = 1; itab <= my numberOfTableaus; itab ++) { OTGrammarTableau tableau = & my tableaus [itab]; for (long icand = 1; icand <= tableau -> numberOfCandidates; icand ++) { computeViolationMarks (& tableau -> candidates [icand]); } } OTGrammar_checkIndex (me.peek()); OTGrammar_newDisharmonies (me.peek(), 0.0); if (trochaicityConstraint == 1) { OTGrammar_removeConstraint (me.peek(), L"Trochaic"); } else { OTGrammar_removeConstraint (me.peek(), L"FtNonfinal"); } if (! includeFootBimoraic) OTGrammar_removeConstraint (me.peek(), L"FtBimor"); if (! includeFootBisyllabic) OTGrammar_removeConstraint (me.peek(), L"FtBisyl"); if (! includePeripheral) OTGrammar_removeConstraint (me.peek(), L"Peripheral"); if (nonfinalityConstraint == 1) { OTGrammar_removeConstraint (me.peek(), L"MainNonfinal"); OTGrammar_removeConstraint (me.peek(), L"HeadNonfinal"); } else if (nonfinalityConstraint == 2) { OTGrammar_removeConstraint (me.peek(), L"HeadNonfinal"); OTGrammar_removeConstraint (me.peek(), L"Nonfinal"); } else { OTGrammar_removeConstraint (me.peek(), L"MainNonfinal"); OTGrammar_removeConstraint (me.peek(), L"Nonfinal"); } if (! includeClashAndLapse) { OTGrammar_removeConstraint (me.peek(), L"*Clash"); OTGrammar_removeConstraint (me.peek(), L"*Lapse"); } if (! includeCodas) { OTGrammar_removeConstraint (me.peek(), L"WeightByPosition"); OTGrammar_removeConstraint (me.peek(), L"*C\\mu"); } if (includeCodas) { for (long itab = 1; itab <= my numberOfTableaus; itab ++) { OTGrammarTableau tableau = & my tableaus [itab]; for (long icand = 1; icand <= tableau -> numberOfCandidates; icand ++) { replaceOutput (& tableau -> candidates [icand]); } } } return me.transfer(); } catch (MelderError) { Melder_throw ("Metrics grammar not created."); } }