OTGrammar_ex_NPA.cpp 3.6 KB

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