| 1 | /* OTGrammar_ex_NPA.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2005,2007,2009,2011,2012,2015-2020 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 2002/07/16 GPL |
| 21 | * pb 2007/07/23 constraint plasticity |
| 22 | * pb 2007/08/12 wchar |
| 23 | * pb 2011/03/29 C++ |
| 24 | * pb 2011/07/12 C++ |
| 25 | * pb 2015/06/03 char32 |
| 26 | */ |
| 27 | |
| 28 | #include "OTGrammar.h" |
| 29 | |
| 30 | autoOTGrammar OTGrammar_create_NPA_grammar () { |
| 31 | try { |
| 32 | OTGrammarCandidate candidate; |
| 33 | OTGrammarTableau tableau; |
| 34 | OTGrammarConstraint constraint; |
| 35 | autoOTGrammar me = Thing_new (OTGrammar); |
| 36 | my constraints = newvectorzero <structOTGrammarConstraint> (my numberOfConstraints = 3); |
| 37 | constraint = & my constraints [1]; |
| 38 | constraint -> name = Melder_dup (U"*G\\s{ESTURE}"); |
| 39 | constraint -> ranking = 102.7; |
| 40 | constraint -> plasticity = 1.0; |
| 41 | constraint = & my constraints [2]; |
| 42 | constraint -> name = Melder_dup (U"*R\\s{EPLACE} (n, m)"); |
| 43 | constraint -> ranking = 100.0; |
| 44 | constraint -> plasticity = 1.0; |
| 45 | constraint = & my constraints [3]; |
| 46 | constraint -> name = Melder_dup (U"*R\\s{EPLACE} (t, p)"); |
| 47 | constraint -> ranking = 112.0; |
| 48 | constraint -> plasticity = 1.0; |
| 49 | my tableaus = newvectorzero <structOTGrammarTableau> (my numberOfTableaus = 2); |
| 50 | tableau = & my tableaus [1]; |
| 51 | tableau -> input = Melder_dup (U"an+pa"); |
| 52 | tableau -> candidates = newvectorzero <structOTGrammarCandidate> (tableau -> numberOfCandidates = 2); |
| 53 | candidate = & tableau -> candidates [1]; |
| 54 | candidate -> output = Melder_dup (U"anpa"); |
| 55 | candidate -> marks = zero_INTVEC (candidate -> numberOfConstraints = 3); |
| 56 | candidate -> marks [1] = 1; |
| 57 | candidate = & tableau -> candidates [2]; |
| 58 | candidate -> output = Melder_dup (U"ampa"); |
| 59 | candidate -> marks = zero_INTVEC (candidate -> numberOfConstraints = 3); |
| 60 | candidate -> marks [2] = 1; |
| 61 | tableau = & my tableaus [2]; |
| 62 | tableau -> input = Melder_dup (U"at+ma"); |
| 63 | tableau -> candidates = newvectorzero <structOTGrammarCandidate> (tableau -> numberOfCandidates = 2); |
| 64 | candidate = & tableau -> candidates [1]; |
| 65 | candidate -> output = Melder_dup (U"atma"); |
| 66 | candidate -> marks = zero_INTVEC (candidate -> numberOfConstraints = 3); |
| 67 | candidate -> marks [1] = 1; |
| 68 | candidate = & tableau -> candidates [2]; |
| 69 | candidate -> output = Melder_dup (U"apma"); |
| 70 | candidate -> marks = zero_INTVEC (candidate -> numberOfConstraints = 3); |
| 71 | candidate -> marks [3] = 1; |
| 72 | OTGrammar_checkIndex (me.get()); |
| 73 | OTGrammar_newDisharmonies (me.get(), 0.0); |
| 74 | return me; |
| 75 | } catch (MelderError) { |
| 76 | Melder_throw (U"Nasal place assimilation grammar not created."); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | autoPairDistribution OTGrammar_create_NPA_distribution () { |
| 81 | try { |
| 82 | autoPairDistribution me = PairDistribution_create (); |
| 83 | PairDistribution_add (me.get(), U"at+ma", U"atma", 100); |
| 84 | PairDistribution_add (me.get(), U"at+ma", U"apma", 0); |
| 85 | PairDistribution_add (me.get(), U"an+pa", U"anpa", 20); |
| 86 | PairDistribution_add (me.get(), U"an+pa", U"ampa", 80); |
| 87 | return me; |
| 88 | } catch (MelderError) { |
| 89 | Melder_throw (U"Nasal place assimilation distribution not created."); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /* End of file OTGrammar_ex_NPA.cpp */ |