FreeLing
3.1
|
00001 00002 // 00003 // FreeLing - Open Source Language Analyzers 00004 // 00005 // Copyright (C) 2004 TALP Research Center 00006 // Universitat Politecnica de Catalunya 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 3 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 // 00022 // contact: Lluis Padro (padro@lsi.upc.es) 00023 // TALP Research Center 00024 // despatx C6.212 - Campus Nord UPC 00025 // 08034 Barcelona. SPAIN 00026 // 00028 00029 #ifndef _TRACES 00030 #define _TRACES 00031 00032 #include <iostream> 00033 #include <string> 00034 #include <list> 00035 #include <cstdlib> 00036 00037 #include "freeling/windll.h" 00038 #include "freeling/morfo/language.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 SENSES_TRACE 0x00010000 00058 #define CHART_TRACE 0x00020000 00059 #define GRAMMAR_TRACE 0x00040000 00060 #define DEP_TRACE 0x00080000 00061 #define COREF_TRACE 0x00100000 00062 #define UTIL_TRACE 0x00200000 00063 #define WSD_TRACE 0x00400000 00064 #define ALTERNATIVES_TRACE 0x00800000 00065 #define DATABASE_TRACE 0x01000000 00066 #define FEX_TRACE 0x02000000 00067 #define LANGIDENT_TRACE 0x04000000 00068 #define OMLET_TRACE 0x08000000 00069 #define PHONETICS_TRACE 0x10000000 00070 //#define AVAILABLE 0x20000000 00071 //#define AVAILABLE 0x40000000 00072 //#define AVAILABLE 0x80000000 00073 00076 #undef MOD_TRACECODE 00077 #undef MOD_TRACENAME 00078 00079 namespace freeling { 00080 00084 00085 class WINDLL traces { 00086 public: 00087 // current trace level 00088 static int TraceLevel; 00089 // modules to trace 00090 static unsigned long TraceModule; 00091 00092 static void error_crash(const std::wstring &, const std::wstring &, unsigned long); 00093 static void warning(const std::wstring &, const std::wstring &, unsigned long); 00094 static void trace(int,const std::wstring &, const std::wstring &, unsigned long); 00095 static void trace_word (int lv, const word &, const std::wstring &, unsigned long); 00096 static void trace_word_list(int,const std::list<word> &, const std::wstring &, unsigned long); 00097 static void trace_sentence(int,const sentence &, const std::wstring &, unsigned long); 00098 static void trace_sentence_list(int,const std::list<sentence> &, const std::wstring &, unsigned long); 00099 }; 00100 00102 //--------------------------------- 00103 inline void traces::error_crash(const std::wstring &msg, const std::wstring &modname, unsigned long modcode) { 00104 std::wcerr<<modname<<L": "<<msg<<std::endl; 00105 exit(1); 00106 } 00107 00108 //--------------------------------- 00109 inline void traces::warning(const std::wstring &msg, const std::wstring &modname, unsigned long modcode) { 00110 std::wcerr<<modname<<L": "<<msg<<std::endl; 00111 } 00112 00113 //--------------------------------- 00114 inline void traces::trace(int lv, const std::wstring &msg, const std::wstring &modname, unsigned long modcode) { 00115 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) 00116 std::wcerr<<modname<<L": "<<msg<<std::endl; 00117 } 00118 00119 00120 //--------------------------------- 00121 inline void traces::trace_word (int lv, const word &wd, const std::wstring &modname, unsigned long modcode) { 00122 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) { 00123 00124 std::wcerr<<L"Word form [" 00125 <<wd.get_form()<<L"] (" 00126 <<wd.get_span_start()<<L","<<wd.get_span_finish()<<L")"<<std::endl; 00127 00128 for (word::const_iterator an=wd.unselected_begin(); an!=wd.unselected_end(); an++) 00129 std::wcerr<<L" analysis: <" 00130 <<an->get_lemma()<<L"," 00131 <<an->get_tag()<<L"," 00132 <<an->get_prob()<<L">"<<std::endl; 00133 00134 for (word::const_iterator an=wd.selected_begin(); an!=wd.selected_end(); an++) 00135 std::wcerr<<L" analysis: <" 00136 <<an->get_lemma()<<L"," 00137 <<an->get_tag()<<L"," 00138 <<an->get_prob()<<L"> **"<<std::endl; 00139 00140 if (wd.is_multiword()) { 00141 std::wcerr<<L" is a multiword composed by:"<<std::endl; 00142 const std::list<word> & mw = wd.get_words_mw(); 00143 for (std::list<word>::const_iterator p=mw.begin(); p!=mw.end(); p++) 00144 std::wcerr<<L" ("<<p->get_form()<<L")"<<std::endl; 00145 } 00146 } 00147 } 00148 00149 //--------------------------------- 00150 inline void traces::trace_word_list(int lv, const std::list<word> &wl, const std::wstring &modname, unsigned long modcode) { 00151 std::list<word>::const_iterator wd; 00152 00153 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) { 00154 for (wd=wl.begin(); wd!=wl.end(); wd++) { 00155 traces::trace_word(lv, *wd, modname, modcode); 00156 } 00157 } 00158 } 00159 00160 //--------------------------------- 00161 inline void traces::trace_sentence(int lv, const sentence &s, const std::wstring &modname, unsigned long modcode) { 00162 sentence::const_iterator wd; 00163 00164 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) { 00165 traces::trace(lv, L"BEGIN sentence",modname,modcode); 00166 00167 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) { 00168 for (wd=s.begin(); wd!=s.end(); wd++) { 00169 traces::trace_word(lv, *wd, modname, modcode); 00170 } 00171 } 00172 00173 traces::trace(lv,L"END sentence",modname,modcode); 00174 } 00175 } 00176 00177 //--------------------------------- 00178 inline void traces::trace_sentence_list(int lv, const std::list<sentence> &ls, const std::wstring &modname, unsigned long modcode) { 00179 std::list<sentence>::const_iterator s; 00180 00181 if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) { 00182 for(s=ls.begin(); s!=ls.end(); s++) traces::trace_sentence(lv,*s,modname,modcode); 00183 } 00184 } 00185 00186 00187 } // namespace 00188 00189 00192 00193 #define ERROR_CRASH(msg) freeling::traces::error_crash(msg,MOD_TRACENAME,MOD_TRACECODE) 00194 00197 #ifdef NO_WARNINGS 00198 #define WARNING(msg) 00199 #else 00200 #define WARNING(msg) freeling::traces::warning(msg,MOD_TRACENAME,MOD_TRACECODE) 00201 #endif 00202 00205 #ifdef VERBOSE 00206 00207 #define TRACE(x,y) freeling::traces::trace(x,y,MOD_TRACENAME,MOD_TRACECODE) 00208 #define TRACE_WORD(x,y) freeling::traces::trace_word(x,y,MOD_TRACENAME,MOD_TRACECODE) 00209 #define TRACE_WORD_LIST(x,y) freeling::traces::trace_word_list(x,y,MOD_TRACENAME,MOD_TRACECODE) 00210 #define TRACE_SENTENCE(x,y) freeling::traces::trace_sentence(x,y,MOD_TRACENAME,MOD_TRACECODE) 00211 #define TRACE_SENTENCE_LIST(x,y) freeling::traces::trace_sentence_list(x,y,MOD_TRACENAME,MOD_TRACECODE) 00212 #else 00213 00214 #define TRACE(x,y) 00215 #define TRACE_WORD(x,y) 00216 #define TRACE_WORD_LIST(x,y) 00217 #define TRACE_SENTENCE(x,y) 00218 #define TRACE_SENTENCE_LIST(x,y) 00219 #endif 00220 00221 #endif