#ifndef _OTGrammar_h_
#define _OTGrammar_h_
/* OTGrammar.h
 *
 * Copyright (C) 1997-2003 Paul Boersma
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * pb 2003/05/24
 */

#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 warnIfStalled);
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 warnIfStalled);
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,
	int trochaicityConstraint, int includeFootBimoraic, int includeFootBisyllabic,
	int includePeripheral, int nonfinalityConstraint);
	/* T&S: 1, FALSE, FALSE, FALSE, 1 */

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

int OTGrammar_removeConstraint (OTGrammar me, const char *constraintName);

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