/*---------------------------------------------------------------------------------------------------------------------
- File      : grace_tags.h                                                                Project ELSE, EPFL - DI/LIA -
-                                                                       Evaluation in Language and Speech Engineering -
- Author    : Seydoux Florian   Creation date : 19 Sep 1999                                                           -
- Eulogist  : -                 Approval date : -                  Version: 0.1                                       -
-                                                                                                                     -
- Descript. : Define the Html Tags used in the evaluation.                                                            -
-                                                                                                                     -
- Requested : -                                                                                                       -
-                                                                                                                     -
- Gaps      : o)                                                                                                      -
-                                                                                                                     -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Rev. date | Reviser               | Revise's description                                                            -
- - - - - - + - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- ../../....| ........              | ...                                                                             -
---------------------------------------------------------------------------------------------------------------------*/

#ifndef GRACE_TAGS_H
#define GRACE_TAGS_H    

#include "globaldef.h"
#include "tags_mapping_table.h"
#include "user_configuration.h"
#include "html_tag.h"


#ifdef _USE_NAMESPACES
    namespace Else { 
#endif // _USE_NAMESPACES

class HtmlComment: public conform_string,
                   public TagAttribute,
                   public HtmlField {
public:
    HtmlComment();
    HtmlComment(const string& cmt);
    HtmlComment(const char*const cmt);
    const string& name() const;
    const string& tagName() const;
    void write(ostream& os) const;
private:
    void writeSingle(ostream& os) const;
    void readSingle(istream& is);

	static const string TAG_NAME;
};

class HtmlSystem: public HtmlField {
public:
	HtmlSystem();
	HtmlSystem(const string& id);
	HtmlSystem(const string& id, const string& name);

	const string& tagName() const;
	void write(ostream& os) const;

public:
	StringAttribute id;
	StringAttribute sys_name;

// private:
	static const string TAG_NAME;
	static const string ATTRIB_ID_NAME;
	static const string ATTRIB_SYS_NAME;
};


class HtmlCorpus: public HtmlField {
public:
	HtmlCorpus();
	HtmlCorpus(const ShortNatural& id);

	const string& tagName() const;
	void write(ostream& os) const;

public:
	ShortNaturalAttribute id;

// private:
	static const string TAG_NAME;
	static const string ATTRIB_ID_NAME;
};


class HtmlCase: public HtmlField {
public:
	HtmlCase();
	HtmlCase(const VeryLongNatural& caseNo);

	const string& tagName() const;
	void write(ostream& os) const;

public:
	VeryLongNaturalAttribute caseNo;

// private:
	static const string TAG_NAME;
	static const string ATTRIB_CASE_NAME;
};

class HtmlToken: public HtmlField {
public:
	HtmlToken();
	HtmlToken(const VeryLongNatural& pos, const string& tag,
	          const string& sgOrig, const string& token);

	const string& tagName() const;
	void readField(istream& in);
	void writeField(ostream& os) const;

public:
	VeryLongNaturalAttribute pos;
	StringAttribute          tag;
	StringAttribute          segOrig;
	string                   tok;

// private:
	static const string TAG_NAME;
	static const string ATTRIB_POS_NAME;
	static const string ATTRIB_TAG_NAME;
	static const string ATTRIB_SEG_NAME;
};	


class HtmlRes: public HtmlField, public TagAttribute {
public:
	HtmlRes();
	HtmlRes(const Natural ver, const SingleRes res);
	const string& name() const;
	const string& tagName() const;
	void write(ostream& os) const;
private:
	void writeSingle(ostream& os) const;
	
public:
	NaturalAttribute ver;
	SingleRes        res;

// private:
	static const string TAG_NAME;
	static const string ATTRIB_VER_NAME;
	static const string ATTRIB_RES_NAME;
};

class HtmlTranscoded: public HtmlField {
public:
	HtmlTranscoded();
	HtmlTranscoded(const Natural ver, const string& tag);
	const string& tagName() const;
	void write(ostream& os) const;
	
public:
	NaturalAttribute ver;
	StringAttribute  val;

private:
	static const string TAG_NAME;
	static const string ATTRIB_VER_NAME;
	static const string ATTRIB_VAL_NAME;
};


template <class T>
class Formatted: public GenericAttribute<T> {
public:
   	Formatted(const string& name, const T& init):GenericAttribute<T>(name, init, true, false) {}
protected:
   	void writeSingle(ostream& os) const  { os << attribute << '\n'; }  // not '\n' for Martin Compl.
};
typedef Formatted<Real>            RealF;
typedef Formatted<Natural>         NaturalF;
typedef Formatted<VeryLongNatural> VLNaturalF;

class HtmlResultats: public HtmlField {
public:
	HtmlResultats();
	void reset();
	const string& tagName() const;
	void mergeWith(const HtmlResultats& res);
	void computeScore();
	void dump(ostream& os) const;
public:
	enum Evaluation { Directe, Relative };
	class EvaluationType: public TagAttribute {
	public:
		EvaluationType(): TagAttribute(true, false, false), id("eval_type"), attribute(Directe) { }
		const string& name() const { return id; }
		const Evaluation& operator()() const { return attribute; }
		Evaluation& operator()() { return attribute; }
	protected:
		void readSingle(istream& in) { string s; in >> s; attribute = (s==string("relative") ? Relative : Directe); }
	    void writeSingle(ostream& os) const  { os << (attribute == Relative ? "relative" : "directe"); }
	private:
		const string id;
		Evaluation attribute;
	};

	EvaluationType evalType;
	NaturalF       ver;
	VLNaturalF     nbCases;
	VLNaturalF     silences;
	VLNaturalF     oks;
	VLNaturalF     silencesOk;
	VLNaturalF     silencesErr;
	VLNaturalF     errs;
	VLNaturalF     neutralized;
	VLNaturalF     unevaluable;
	VLNaturalF     wrongAlign;
	RealF          averageSilOk;
	RealF          averageSilErr;
	RealF          ratioUnevaluable;
	RealF          precision;
	RealF          decision;
	RealF          minPrecision;
	RealF          subMinPrecision;
	RealF          averagePrecision;
	RealF          subAveragePrecision;
	RealF          supAveragePrecision;
	RealF          maxPrecision;
	RealF          supMaxPrecision;
private:
	static const string TAG_NAME;
	static const string ATTRIBS_NAME[22];  // not very good... but..
};


#ifdef __USE_NAMESPACES
}
#endif // _USE_NAMESPACES

#endif // defined GRACE_TAGS_H
        
