Esempio n. 1
0
static void menu_cb_evaluate_zeroNoise (EDITOR_ARGS) {
	EDITOR_IAM (OTGrammarEditor);
	Editor_save (me, U"Evaluate (zero noise)");
	OTGrammar_newDisharmonies ((OTGrammar) my data, 0.0);
	Graphics_updateWs (my g);
	Editor_broadcastDataChanged (me);
}
static void menu_cb_evaluate_tinyNoise (EDITOR_ARGS) {
	EDITOR_IAM (OTGrammarEditor);
	Editor_save (me, L"Evaluate (tiny noise)");
	OTGrammar_newDisharmonies ((OTGrammar) my data, 1e-9);
	Graphics_updateWs (my g);
	my broadcastDataChanged ();
}
Esempio n. 3
0
static void menu_cb_evaluate (EDITOR_ARGS) {
	EDITOR_IAM (OTGrammarEditor);
	EDITOR_FORM (U"Evaluate", 0)
		REAL (U"Noise", U"2.0")
	EDITOR_OK
	EDITOR_DO
		Editor_save (me, U"Evaluate");
		OTGrammar_newDisharmonies ((OTGrammar) my data, GET_REAL (U"Noise"));
		Graphics_updateWs (my g);
		Editor_broadcastDataChanged (me);
	EDITOR_END
}
Esempio n. 4
0
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.");
	}
}
OTGrammar OTGrammar_create_tongueRoot_grammar (int small_large, int equal_random_infant_Wolof) {
	try {
		int ncons = small_large == 1 ? 5 : 9, itab, v1, v2;
		autoOTGrammar me = Thing_new (OTGrammar);
		my constraints = NUMvector <structOTGrammarConstraint> (1, my numberOfConstraints = ncons);
		my constraints [1]. name = Melder_wcsdup (L"*[rtr / hi]");
		my constraints [2]. name = Melder_wcsdup (L"*[atr / lo]");
		my constraints [3]. name = Melder_wcsdup (L"P\\s{ARSE}\n(rtr)");
		my constraints [4]. name = Melder_wcsdup (L"P\\s{ARSE}\n(atr)");
		my constraints [5]. name = Melder_wcsdup (L"*G\\s{ESTURE}\n(contour)");
		if (ncons == 9) {
			my constraints [6]. name = Melder_wcsdup (L"*[rtr / mid]");
			my constraints [7]. name = Melder_wcsdup (L"*[rtr / lo]");
			my constraints [8]. name = Melder_wcsdup (L"*[atr / mid]");
			my constraints [9]. name = Melder_wcsdup (L"*[atr / hi]");
		}
		if (equal_random_infant_Wolof == 1) {   /* equal? */
			for (long icons = 1; icons <= ncons; icons ++)
				my constraints [icons]. ranking = 100.0;
		} else if (equal_random_infant_Wolof == 2) {   /* random? */
			for (long icons = 1; icons <= ncons; icons ++)
				my constraints [icons]. ranking = NUMrandomGauss (100.0, 10.0);
		} else if (equal_random_infant_Wolof == 3) {   /* infant (= cannot speak) ? */
			for (long icons = 1; icons <= ncons; icons ++)
				my constraints [icons]. ranking = 100.0;   /* Structural constraints. */
			my constraints [3]. ranking = 50.0;   /* Faithfulness constraints. */
			my constraints [4]. ranking = 50.0;
		} else {   /* adult Wolof */
			my constraints [1]. ranking = 100.0;
			my constraints [2]. ranking =  10.0;
			my constraints [3]. ranking =  50.0;
			my constraints [4]. ranking =  20.0;
			my constraints [5]. ranking =  30.0;
			if (ncons == 9) {
				my constraints [6]. ranking =   0.0;
				my constraints [7]. ranking = -10.0;
				my constraints [8]. ranking =   0.0;
				my constraints [9]. ranking = -10.0;
			}
		}
		if (ncons == 9) {
			my fixedRankings = NUMvector <structOTGrammarFixedRanking> (1, my numberOfFixedRankings = 4);
			my fixedRankings [1]. higher = 1, my fixedRankings [1]. lower = 6;
			my fixedRankings [2]. higher = 6, my fixedRankings [2]. lower = 7;
			my fixedRankings [3]. higher = 2, my fixedRankings [3]. lower = 8;
			my fixedRankings [4]. higher = 8, my fixedRankings [4]. lower = 9;
		}
		my tableaus = NUMvector <structOTGrammarTableau> (1, my numberOfTableaus = 36);
		itab = 1;
		for (v1 = 0; v1 < 6; v1 ++) for (v2 = 0; v2 < 6; v2 ++) {
			OTGrammarTableau tableau = & my tableaus [itab];
			wchar_t buffer [100];
			swprintf (buffer, 100, L"%lst%ls", vowels [v1], vowels [v2]);
			tableau -> input = Melder_wcsdup (buffer);
			tableau -> candidates = NUMvector <structOTGrammarCandidate> (1, tableau -> numberOfCandidates = 4);
			/*
			 * Generate the four tongue-root variants as output candidates.
			 */
			OTGrammarCandidate_init (& tableau -> candidates [1], ncons, v1, v2);
				/* Faithful: no PARSE constraints violated. */
			OTGrammarCandidate_init (& tableau -> candidates [2], ncons, fliptr (v1), v2);
				/* First vowel flipped: violated one PARSE constraint. */
			OTGrammarCandidate_init (& tableau -> candidates [3], ncons, v1, fliptr (v2));
				/* Second vowel flipped. */
			OTGrammarCandidate_init (& tableau -> candidates [4], ncons, fliptr (v1), fliptr (v2));
				/* Both vowels flipped. */
			/*
			 * Count PARSE violations.
			 */
			if (isatr (v1)) {
				tableau -> candidates [2]. marks [4] ++;
				tableau -> candidates [4]. marks [4] ++;
			} else {
				tableau -> candidates [2]. marks [3] ++;
				tableau -> candidates [4]. marks [3] ++;
			}
			if (isatr (v2)) {
				tableau -> candidates [3]. marks [4] ++;
				tableau -> candidates [4]. marks [4] ++;
			} else {
				tableau -> candidates [3]. marks [3] ++;
				tableau -> candidates [4]. marks [3] ++;
			}
			itab ++;
		}
		OTGrammar_checkIndex (me.peek());
		OTGrammar_newDisharmonies (me.peek(), 0.0);
		for (long icons = 1; icons <= my numberOfConstraints; icons ++)
			my constraints [icons]. plasticity = 1.0;
		return me.transfer();
	} catch (MelderError) {
		Melder_throw ("Tongue root grammar not created.");
	}
}