#ifndef _OTGrammar_h_
#define _OTGrammar_h_
/* OTGrammar.h; Paul Boersma, November 24, 2001 */

#ifndef _Strings_h_
	#include "Strings.h"
#endif
#ifndef _Graphics_h_
	#include "Graphics.h"
#endif
#ifndef _PairDistribution_h_
	#include "PairDistribution.h"
#endif
#ifndef _Distributions_h_
	#include "Distributions.h"
#endif

#include "OTGrammar_def.h"

#define OTGrammar_methods Data_methods
oo_CLASS_CREATE (OTGrammar, Data)

void OTGrammar_sort (OTGrammar me);
/* Low level: meant to maintain the invariant
 *      my constraints [my index [i]]. disharmony >= my constraints [my index [i+1]]. disharmony
 * Therefore, call after every direct assignment to the 'disharmony' attribute.
 * High level: ties are randomly sorted, so repetitive calls cause different orders if there are ties.
 */

void OTGrammar_newDisharmonies (OTGrammar me, double spreading);

long OTGrammar_getTableau (OTGrammar me, const char *input);
long OTGrammar_getWinner (OTGrammar me, long itab);
OTGrammarCandidate OTGrammar_getInterpretiveParse
	(OTGrammar me, const char *overtForm, long *bestInput, long *bestOutput);
void OTGrammar_drawTableau (OTGrammar me, Graphics g, const char *input);

Strings OTGrammar_generateInputs (OTGrammar me, long numberOfTrials);
Strings OTGrammar_getInputs (OTGrammar me);
int OTGrammar_inputToOutput (OTGrammar me, const char *input, char *output, double noise);
Strings OTGrammar_inputsToOutputs (OTGrammar me, Strings inputs, double noise);
Strings OTGrammar_inputToOutputs (OTGrammar me, const char *input, long n, double noise);
Distributions OTGrammar_to_Distribution (OTGrammar me, long trialsPerInput, double noise);
PairDistribution OTGrammar_to_PairDistribution (OTGrammar me, long trialsPerInput, double noise);
Distributions OTGrammar_measureTypology (OTGrammar me);

#define OTGrammar_DEMOTION_ONLY  0
#define OTGrammar_SYMMETRIC_ONE  1
#define OTGrammar_SYMMETRIC_ALL  2
#define OTGrammar_WEIGHTED_UNCANCELLED  3
#define OTGrammar_WEIGHTED_ALL  4
#define OTGrammar_EDCD  5

int OTGrammar_learnOne (OTGrammar me, const char *underlyingForm, const char *adultOutput,
	double rankingSpreading, int strategy, int honourLocalRankings,
	double demotionMean, double relativeDemotionSpreading, int newDisharmonies);
int OTGrammar_learn (OTGrammar me, Strings inputs, Strings outputs,
	double rankingSpreading, int strategy, int honourLocalRankings,
	double demotionMean, double relativeDemotionSpreading, long chews);
int OTGrammar_PairDistribution_learn (OTGrammar me, PairDistribution thee,
	double evaluationNoise, int strategy, int honourLocalRankings,
	double initialPlasticity, long replicationsPerPlasticity, double plasticityDecrement,
	long numberOfPlasticities, double relativePlasticityNoise, long numberOfChews);
int OTGrammar_learnOneFromPartialOutput (OTGrammar me, const char *partialAdultOutput,
	double rankingSpreading, int strategy, int honourLocalRankings,
	double demotionMean, double relativeDemotionSpreading);
int OTGrammar_learnFromPartialOutputs (OTGrammar me, Strings partialOutputs,
	double rankingSpreading, int strategy, int honourLocalRankings,
	double demotionMean, double relativeDemotionSpreading, long chews);
int OTGrammar_PairDistribution_getFractionCorrect (OTGrammar me, PairDistribution thee,
	double evaluationNoise, long numberOfInputs, double *fractionCorrect);

void OTGrammar_checkIndex (OTGrammar me);

OTGrammar OTGrammar_create_NoCoda_grammar (void);
OTGrammar OTGrammar_create_NPA_grammar (void);
PairDistribution OTGrammar_create_NPA_distribution (void);
OTGrammar OTGrammar_create_tongueRoot_grammar (int small_large, int equal_random_infant_Wolof);
OTGrammar OTGrammar_create_metrics (int parsing, int equal_footForm_wsp);

void OTGrammar_reset (OTGrammar me, double ranking);
int OTGrammar_setRanking (OTGrammar me, long constraint, double ranking, double disharmony);

/* End of file OTGrammar.h */
#endif
