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 <cstdlib>
00036
00037 #include "fries/language.h"
00038 #include "fries/util.h"
00039
00041 #define SPLIT_TRACE 0x00000001
00042 #define TOKEN_TRACE 0x00000002
00043 #define MACO_TRACE 0x00000004
00044 #define OPTIONS_TRACE 0x00000008
00045 #define NUMBERS_TRACE 0x00000010
00046 #define DATES_TRACE 0x00000020
00047 #define PUNCT_TRACE 0x00000040
00048 #define DICT_TRACE 0x00000080
00049 #define AFF_TRACE 0x00000100
00050 #define LOCUT_TRACE 0x00000200
00051 #define NP_TRACE 0x00000400
00052 #define PROB_TRACE 0x00000800
00053 #define QUANT_TRACE 0x00001000
00054 #define NEC_TRACE 0x00002000
00055 #define AUTOMAT_TRACE 0x00004000
00056 #define TAGGER_TRACE 0x00008000
00057 #define HMM_TRACE 0x00010000
00058 #define RELAX_TRACE 0x00020000
00059 #define RELAX_TAGGER_TRACE 0x00040000
00060 #define CONST_GRAMMAR_TRACE 0x00080000
00061 #define SENSES_TRACE 0x00100000
00062 #define CHART_TRACE 0x00200000
00063 #define GRAMMAR_TRACE 0x00400000
00064 #define DEP_TRACE 0x00800000
00065 #define COREF_TRACE 0x01000000
00066 #define UTIL_TRACE 0x02000000
00067 #define CORRECTOR_TRACE 0x04000000
00068 #define PHONETICS_TRACE 0x08000000
00069 #define DATABASE_TRACE 0x10000000
00070
00071
00074 #undef MOD_TRACECODE
00075 #undef MOD_TRACENAME
00076
00080
00081 class traces {
00082 public:
00083
00084 static int TraceLevel;
00085
00086 static unsigned long TraceModule;
00087
00088 static void error_crash(const std::string &, const std::string &, unsigned long);
00089 static void warning(const std::string &, const std::string &, unsigned long);
00090 static void trace(int,const std::string &, const std::string &, unsigned long);
00091 static void trace_word (int lv, const word &, const std::string &, unsigned long);
00092 static void trace_word_list(int,const std::list<word> &, const std::string &, unsigned long);
00093 static void trace_sentence(int,const sentence &, const std::string &, unsigned long);
00094 static void trace_sentence_list(int,const std::list<sentence> &, const std::string &, unsigned long);
00095 };
00096
00098
00099 inline void traces::error_crash(const std::string &msg, const std::string &modname, unsigned long modcode) {
00100 std::cerr<<modname<<": "<<msg<<std::endl;
00101 exit(1);
00102 }
00103
00104
00105 inline void traces::warning(const std::string &msg, const std::string &modname, unsigned long modcode) {
00106 std::cerr<<modname<<": "<<msg<<std::endl;
00107 }
00108
00109
00110 inline void traces::trace(int lv, const std::string &msg, const std::string &modname, unsigned long modcode) {
00111 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode))
00112 std::cerr<<modname<<": "<<msg<<std::endl;
00113 }
00114
00115
00116
00117 inline void traces::trace_word (int lv, const word &wd, const std::string &modname, unsigned long modcode) {
00118 word::const_iterator an;
00119 std::list<word>::iterator p;
00120 std::list<word> mw;
00121
00122 std::string sel="";
00123 traces::trace(lv, "Word form ["+wd.get_form()+"] ("+util::int2string(wd.get_span_start())+","+util::int2string(wd.get_span_finish())+")",modname,modcode);
00124
00125 for (an=wd.unselected_begin(); an!=wd.unselected_end(); an++) {
00126 traces::trace(lv, " analysis: <"+an->get_lemma()+","+an->get_parole()+","+util::double2string(an->get_prob())+">",modname,modcode);
00127 }
00128 for (an=wd.selected_begin(); an!=wd.selected_end(); an++) {
00129 traces::trace(lv, " analysis: <"+an->get_lemma()+","+an->get_parole()+","+util::double2string(an->get_prob())+"> **",modname,modcode);
00130 }
00131
00132 if (wd.is_multiword()) {
00133 traces::trace(lv, " is a multiword composed by:",modname,modcode);
00134 mw = wd.get_words_mw();
00135 for (p=mw.begin(); p!=mw.end(); p++)
00136 traces::trace(lv, " ("+p->get_form()+")",modname,modcode);
00137 }
00138 }
00139
00140
00141 inline void traces::trace_word_list(int lv, const std::list<word> &wl, const std::string &modname, unsigned long modcode) {
00142 std::list<word>::const_iterator wd;
00143
00144 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00145 for (wd=wl.begin(); wd!=wl.end(); wd++) {
00146 traces::trace_word(lv, *wd, modname, modcode);
00147 }
00148 }
00149 }
00150
00151
00152 inline void traces::trace_sentence(int lv, const sentence &s, const std::string &modname, unsigned long modcode) {
00153 sentence::const_iterator wd;
00154
00155 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00156 traces::trace(lv, "BEGIN sentence",modname,modcode);
00157
00158 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00159 for (wd=s.begin(); wd!=s.end(); wd++) {
00160 traces::trace_word(lv, *wd, modname, modcode);
00161 }
00162 }
00163
00164 traces::trace(lv,"END sentence",modname,modcode);
00165 }
00166 }
00167
00168
00169 inline void traces::trace_sentence_list(int lv, const std::list<sentence> &ls, const std::string &modname, unsigned long modcode) {
00170 std::list<sentence>::const_iterator s;
00171
00172 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00173 for(s=ls.begin(); s!=ls.end(); s++) traces::trace_sentence(lv,*s,modname,modcode);
00174 }
00175 }
00176
00177
00180
00181 #define ERROR_CRASH(msg) traces::error_crash(msg,MOD_TRACENAME,MOD_TRACECODE)
00182 #define WARNING(msg) traces::warning(msg,MOD_TRACENAME,MOD_TRACECODE)
00183
00186 #ifdef VERBOSE
00187
00188 #define TRACE(x,y) traces::trace(x,y,MOD_TRACENAME,MOD_TRACECODE)
00189 #define TRACE_WORD(x,y) traces::trace_word(x,y,MOD_TRACENAME,MOD_TRACECODE)
00190 #define TRACE_WORD_LIST(x,y) traces::trace_word_list(x,y,MOD_TRACENAME,MOD_TRACECODE)
00191 #define TRACE_SENTENCE(x,y) traces::trace_sentence(x,y,MOD_TRACENAME,MOD_TRACECODE)
00192 #define TRACE_SENTENCE_LIST(x,y) traces::trace_sentence_list(x,y,MOD_TRACENAME,MOD_TRACECODE)
00193 #endif
00194 #ifndef VERBOSE
00195
00196 #define TRACE(x,y)
00197 #define TRACE_WORD(x,y)
00198 #define TRACE_WORD_LIST(x,y)
00199 #define TRACE_SENTENCE(x,y)
00200 #define TRACE_SENTENCE_LIST(x,y)
00201 #endif
00202
00203
00204
00205
00206 #endif