00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00029 #ifndef _TRACES
00030 #define _TRACES
00031
00032 #include <iostream>
00033 #include <string>
00034 #include <list>
00035 #include "util.h"
00036 #include "language.h"
00037
00039 #define SPLIT_TRACE 0x00000001
00040 #define TOKEN_TRACE 0x00000002
00041 #define MACO_TRACE 0x00000004
00042 #define OPTIONS_TRACE 0x00000008
00043 #define NUMBERS_TRACE 0x00000010
00044 #define DATES_TRACE 0x00000020
00045 #define PUNCT_TRACE 0x00000040
00046 #define DICT_TRACE 0x00000080
00047 #define SUFF_TRACE 0x00000100
00048 #define LOCUT_TRACE 0x00000200
00049 #define NP_TRACE 0x00000400
00050 #define PROB_TRACE 0x00000800
00051 #define QUANT_TRACE 0x00001000
00052 #define NEC_TRACE 0x00002000
00053 #define AUTOMAT_TRACE 0x00004000
00054 #define TAGGER_TRACE 0x00008000
00055 #define HMM_TRACE 0x00010000
00056 #define RELAX_TRACE 0x00020000
00057 #define RELAX_TAGGER_TRACE 0x00040000
00058 #define CONST_GRAMMAR_TRACE 0x00080000
00059 #define SENSES_TRACE 0x00100000
00060 #define CHART_TRACE 0x00200000
00061 #define GRAMMAR_TRACE 0x00400000
00062 #define DEP_TRACE 0x00800000
00063 #define UTIL_TRACE 0x01000000
00064
00067 #undef MOD_TRACECODE
00068 #undef MOD_TRACENAME
00069
00073
00074 class traces {
00075 public:
00076
00077 static int TraceLevel;
00078
00079 static unsigned long TraceModule;
00080
00081 static void error_crash(const string &, const string &, unsigned long);
00082 static void warning(const string &, const string &, unsigned long);
00083 static void trace(int,const string &, const string &, unsigned long);
00084 static void trace_word (int lv, const word &, const string &, unsigned long);
00085 static void trace_word_list(int,const list<word> &, const string &, unsigned long);
00086 static void trace_sentence(int,const sentence &, const string &, unsigned long);
00087 static void trace_sentence_list(int,const list<sentence> &, const string &, unsigned long);
00088 };
00089
00091
00092 inline void traces::error_crash(const string &msg, const string &modname, unsigned long modcode) {
00093 cerr<<modname<<": "<<msg<<endl;
00094 exit(1);
00095 }
00096
00097
00098 inline void traces::warning(const string &msg, const string &modname, unsigned long modcode) {
00099 cerr<<modname<<": "<<msg<<endl;
00100 }
00101
00102
00103 inline void traces::trace(int lv, const string &msg, const string &modname, unsigned long modcode) {
00104 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode))
00105 cerr<<modname<<": "<<msg<<endl;
00106 }
00107
00108
00109
00110 inline void traces::trace_word (int lv, const word &wd, const string &modname, unsigned long modcode) {
00111 word::const_iterator an;
00112 list<word>::const_iterator p;
00113 list<word> mw;
00114
00115 traces::trace(lv, "Word form ["+wd.get_form()+"]",modname,modcode);
00116
00117 for (an=wd.analysis_begin(); an!=wd.analysis_end(); an++)
00118 traces::trace(lv, " analysis: <"+an->get_lemma()+","+an->get_parole()+","+util::double2string(an->get_prob())+">",modname,modcode);
00119
00120 if (wd.is_multiword()) {
00121 traces::trace(lv, " is a multiword composed by:",modname,modcode);
00122 mw = wd.get_words_mw();
00123 for (p=mw.begin(); p!=mw.end(); p++)
00124 traces::trace(lv, " ("+p->get_form()+")",modname,modcode);
00125 }
00126 }
00127
00128
00129 inline void traces::trace_word_list(int lv, const list<word> &wl, const string &modname, unsigned long modcode) {
00130 list<word>::const_iterator wd;
00131
00132 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00133 for (wd=wl.begin(); wd!=wl.end(); wd++) {
00134 traces::trace_word(lv, *wd, modname, modcode);
00135 }
00136 }
00137 }
00138
00139
00140 inline void traces::trace_sentence(int lv, const sentence &s, const string &modname, unsigned long modcode) {
00141 sentence::const_iterator wd;
00142
00143 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00144 traces::trace(lv, "BEGIN sentence",modname,modcode);
00145
00146 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00147 for (wd=s.begin(); wd!=s.end(); wd++) {
00148 traces::trace_word(lv, *wd, modname, modcode);
00149 }
00150 }
00151
00152 traces::trace(lv,"END sentence",modname,modcode);
00153 }
00154 }
00155
00156
00157 inline void traces::trace_sentence_list(int lv, const list<sentence> &ls, const string &modname, unsigned long modcode) {
00158 list<sentence>::const_iterator s;
00159
00160 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00161 for(s=ls.begin(); s!=ls.end(); s++) traces::trace_sentence(lv,*s,modname,modcode);
00162 }
00163 }
00164
00165
00168
00169 #define ERROR_CRASH(msg) traces::error_crash(msg,MOD_TRACENAME,MOD_TRACECODE)
00170 #define WARNING(msg) traces::warning(msg,MOD_TRACENAME,MOD_TRACECODE)
00171
00174 #ifdef VERBOSE
00175
00176 #define TRACE(x,y) traces::trace(x,y,MOD_TRACENAME,MOD_TRACECODE)
00177 #define TRACE_WORD_LIST(x,y) traces::trace_word_list(x,y,MOD_TRACENAME,MOD_TRACECODE)
00178 #define TRACE_SENTENCE(x,y) traces::trace_sentence(x,y,MOD_TRACENAME,MOD_TRACECODE)
00179 #define TRACE_SENTENCE_LIST(x,y) traces::trace_sentence_list(x,y,MOD_TRACENAME,MOD_TRACECODE)
00180 #endif
00181 #ifndef VERBOSE
00182
00183 #define TRACE(x,y)
00184 #define TRACE_WORD_LIST(x,y)
00185 #define TRACE_SENTENCE(x,y)
00186 #define TRACE_SENTENCE_LIST(x,y)
00187 #endif
00188
00189
00190
00191
00192 #endif