| 1 |
#ifndef _OTGrammar_h_ |
| 2 |
#define _OTGrammar_h_ |
| 3 |
/* OTGrammar.h |
| 4 |
* |
| 5 |
* Copyright (C) 1997-2012,2014-2018,2021,2025 Paul Boersma |
| 6 |
* |
| 7 |
* This code is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 10 |
* your option) any later version. |
| 11 |
* |
| 12 |
* This code is distributed in the hope that it will be useful, but |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 |
* See the GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "Strings_.h" |
| 22 |
#include "Graphics.h" |
| 23 |
#include "PairDistribution.h" |
| 24 |
#include "Distributions.h" |
| 25 |
#include "TableOfReal.h" |
| 26 |
|
| 27 |
#include "OTGrammar_enums.h" |
| 28 |
|
| 29 |
#include "OTGrammar_def.h" |
| 30 |
|
| 31 |
Thing_define (OTHistory, TableOfReal) { |
| 32 |
}; |
| 33 |
|
| 34 |
void OTGrammar_sort (OTGrammar me); |
| 35 |
/* Low level: meant to maintain the invariant |
| 36 |
* my constraints [my index [i]]. disharmony >= my constraints [my index [i+1]]. disharmony |
| 37 |
* Therefore, call after every direct assignment to the 'disharmony' attribute. |
| 38 |
* Tied constraints are sorted alphabetically. |
| 39 |
*/ |
| 40 |
|
| 41 |
void OTGrammar_newDisharmonies (OTGrammar me, double spreading); |
| 42 |
|
| 43 |
integer OTGrammar_getTableau (constOTGrammar me, conststring32 input); |
| 44 |
int OTGrammar_compareCandidates (OTGrammar me, integer itab1, integer icand1, integer itab2, integer icand2); |
| 45 |
/* |
| 46 |
* Function: |
| 47 |
* to compare the optimality of candidates icand1 in tableau itab1 |
| 48 |
* and icand2 in tableau itab2. |
| 49 |
* Return value: |
| 50 |
* -1 if candidate icand1 is more optimal than candidate icand2; |
| 51 |
* +1 if candidate icand2 is more optimal than candidate icand1; |
| 52 |
* 0 if both candidates are equally optimal. |
| 53 |
* Algorithm: |
| 54 |
* the current disharmony ranking is considered. |
| 55 |
* Takes into account crucial ties: if multiple constraints are ranked at |
| 56 |
* exactly the same height (disharmony), they count as a single constraint. |
| 57 |
* This is original OT. To get Anttila's and GLA's variationist interpretation |
| 58 |
* of ties instead (even in EDCD), make sure you introduce a bit of noise |
| 59 |
* (e.g. 1e-6 if the strata are 1.0 apart). That makes |
| 60 |
* the probability of ties almost zero. |
| 61 |
*/ |
| 62 |
|
| 63 |
/* Productive parsing. */ |
| 64 |
integer OTGrammar_getWinner (OTGrammar me, integer itab); |
| 65 |
/* Gives randomized results in case of tied candidates. */ |
| 66 |
integer OTGrammar_getNumberOfOptimalCandidates (OTGrammar me, integer itab); |
| 67 |
bool OTGrammar_isCandidateGrammatical (OTGrammar me, integer itab, integer icand); |
| 68 |
bool OTGrammar_isCandidateSinglyGrammatical (OTGrammar me, integer itab, integer icand); |
| 69 |
|
| 70 |
/* Interpretive parsing. */ |
| 71 |
void OTGrammar_getInterpretiveParse |
| 72 |
(OTGrammar me, conststring32 partialOutput, integer *bestTableau, integer *bestCandidate); |
| 73 |
/* Gives randomized results in case of tied candidates. */ |
| 74 |
bool OTGrammar_isPartialOutputGrammatical (OTGrammar me, conststring32 partialOutput); |
| 75 |
/* Is there an input for which this partial output is contained in any of the optimal outputs? */ |
| 76 |
bool OTGrammar_isPartialOutputSinglyGrammatical (OTGrammar me, conststring32 partialOutput); |
| 77 |
/* Is every optimal output that contains this partial output the only optimal output in its tableau? */ |
| 78 |
bool OTGrammar_areAllPartialOutputsGrammatical (OTGrammar me, Strings thee); |
| 79 |
bool OTGrammar_areAllPartialOutputsSinglyGrammatical (OTGrammar me, Strings thee); |
| 80 |
|
| 81 |
void OTGrammar_drawTableau (OTGrammar me, Graphics g, bool vertical, conststring32 input); |
| 82 |
|
| 83 |
autoStrings OTGrammar_generateInputs (OTGrammar me, integer numberOfTrials); |
| 84 |
autoStrings OTGrammar_getInputs (OTGrammar me); |
| 85 |
autostring32 OTGrammar_inputToOutput (OTGrammar me, conststring32 input, double evaluationNoise); |
| 86 |
autoStrings OTGrammar_inputsToOutputs (OTGrammar me, Strings inputs, double evaluationNoise); |
| 87 |
autoStrings OTGrammar_inputToOutputs (OTGrammar me, conststring32 input, integer n, double evaluationNoise); |
| 88 |
autoDistributions OTGrammar_to_Distribution (OTGrammar me, integer trialsPerInput, double evaluationNoise); |
| 89 |
autoPairDistribution OTGrammar_to_PairDistribution (OTGrammar me, integer trialsPerInput, double evaluationNoise); |
| 90 |
autoDistributions OTGrammar_measureTypology_WEAK (OTGrammar me); // WEAK because it has a progress bar |
| 91 |
|
| 92 |
void OTGrammar_learnOne (OTGrammar me, conststring32 input, conststring32 adultOutput, |
| 93 |
double rankingSpreading, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings, |
| 94 |
double demotionMean, double relativeDemotionSpreading, bool newDisharmonies, |
| 95 |
bool warnIfStalled, bool *grammarHasChanged); |
| 96 |
void OTGrammar_learn (OTGrammar me, Strings inputs, Strings outputs, |
| 97 |
double rankingSpreading, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings, |
| 98 |
double demotionMean, double relativeDemotionSpreading, integer numberOfChews); |
| 99 |
void OTGrammar_PairDistribution_learn (OTGrammar me, PairDistribution thee, |
| 100 |
double evaluationNoise, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings, |
| 101 |
double initialPlasticity, integer replicationsPerPlasticity, double plasticityDecrement, |
| 102 |
integer numberOfPlasticities, double relativePlasticityNoise, integer numberOfChews); |
| 103 |
bool OTGrammar_PairDistribution_findPositiveWeights (OTGrammar me, PairDistribution thee, double weightFloor, double marginOfSeparation); |
| 104 |
void OTGrammar_learnOneFromPartialOutput (OTGrammar me, conststring32 partialAdultOutput, |
| 105 |
double rankingSpreading, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings, |
| 106 |
double demotionMean, double relativeDemotionSpreading, integer numberOfChews, bool warnIfStalled); |
| 107 |
void OTGrammar_learnFromPartialOutputs (OTGrammar me, Strings partialOutputs, |
| 108 |
double rankingSpreading, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings, |
| 109 |
double demotionMean, double relativeDemotionSpreading, integer numberOfChews, integer storeHistoryEvery, autoOTHistory *history); |
| 110 |
void OTGrammar_Distributions_learnFromPartialOutputs (OTGrammar me, Distributions thee, integer columnNumber, |
| 111 |
double evaluationNoise, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings, |
| 112 |
double initialPlasticity, integer replicationsPerPlasticity, double plasticityDecrement, |
| 113 |
integer numberOfPlasticities, double relativePlasticityNoise, integer numberOfChews, |
| 114 |
integer storeHistoryEvery, autoOTHistory *history_out, |
| 115 |
bool resampleForVirtualProduction, bool compareOnlyPartialOutput, integer resampleForCorrectForm); |
| 116 |
double OTGrammar_PairDistribution_getFractionCorrect (OTGrammar me, PairDistribution thee, |
| 117 |
double evaluationNoise, integer numberOfInputs); |
| 118 |
integer OTGrammar_PairDistribution_getMinimumNumberCorrect (OTGrammar me, PairDistribution thee, |
| 119 |
double evaluationNoise, integer numberOfReplications); |
| 120 |
double OTGrammar_Distributions_getFractionCorrect (OTGrammar me, Distributions thee, integer columnNumber, |
| 121 |
double evaluationNoise, integer numberOfInputs); |
| 122 |
|
| 123 |
void OTGrammar_checkIndex (OTGrammar me); |
| 124 |
|
| 125 |
autoOTGrammar OTGrammar_create_NoCoda_grammar (); |
| 126 |
autoOTGrammar OTGrammar_create_NPA_grammar (); |
| 127 |
autoPairDistribution OTGrammar_create_NPA_distribution (); |
| 128 |
autoOTGrammar OTGrammar_create_tongueRoot_grammar ( |
| 129 |
kOTGrammar_createTongueRootGrammar_constraintSet small_large, |
| 130 |
kOTGrammar_createTongueRootGrammar_ranking equal_random_infant_Wolof |
| 131 |
); |
| 132 |
autoOTGrammar OTGrammar_create_metrics ( |
| 133 |
kOTGrammar_createMetricsGrammar_initialRanking equal_footForm_wsp, |
| 134 |
int trochaicityConstraint, bool includeFootBimoraic, bool includeFootBisyllabic, |
| 135 |
bool includePeripheral, int nonfinalityConstraint, bool overtFormsHaveSecondaryStress, bool includeClashAndLapse, bool includeCodas); |
| 136 |
/* T&S: 1, false, false, false, 1, true, false, false */ |
| 137 |
|
| 138 |
void OTGrammar_reset (OTGrammar me, double ranking); |
| 139 |
void OTGrammar_resetToRandomRanking (OTGrammar me, double mean, double standardDeviation); |
| 140 |
void OTGrammar_resetToRandomTotalRanking (OTGrammar me, double maximumRanking, double rankingDistance); |
| 141 |
void OTGrammar_setRanking (OTGrammar me, integer constraint, double ranking, double disharmony); |
| 142 |
void OTGrammar_setConstraintPlasticity (OTGrammar me, integer constraint, double plasticity); |
| 143 |
|
| 144 |
void OTGrammar_removeConstraint (OTGrammar me, conststring32 constraintName); |
| 145 |
void OTGrammar_removeHarmonicallyBoundedCandidates (OTGrammar me, bool singly); |
| 146 |
bool OTGrammar_areAllOutputsDistinguishable (OTGrammar me); |
| 147 |
autoTable OTGrammar_tabulateEquivalentPairs (OTGrammar me); |
| 148 |
void OTGrammar_PairDistribution_listObligatoryRankings (OTGrammar me, PairDistribution thee); |
| 149 |
void OTGrammar_Distributions_listObligatoryRankings (OTGrammar me, Distributions thee, integer columnNumber); |
| 150 |
autoTable OTGrammar_tabulateAllCorrectRankings (constOTGrammar me, constStrings inputs, constStrings partialOutputs); |
| 151 |
|
| 152 |
void OTGrammar_writeToHeaderlessSpreadsheetFile (OTGrammar me, MelderFile file); |
| 153 |
|
| 154 |
/* End of file OTGrammar.h */ |
| 155 |
#endif |