FreeLing  3.0
traces.h
Go to the documentation of this file.
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 #include "freeling/morfo/util.h"
00040 
00042 #define SPLIT_TRACE         0x00000001
00043 #define TOKEN_TRACE         0x00000002
00044 #define MACO_TRACE          0x00000004
00045 #define OPTIONS_TRACE       0x00000008
00046 #define NUMBERS_TRACE       0x00000010
00047 #define DATES_TRACE         0x00000020
00048 #define PUNCT_TRACE         0x00000040
00049 #define DICT_TRACE          0x00000080
00050 #define AFF_TRACE           0x00000100
00051 #define LOCUT_TRACE         0x00000200
00052 #define NP_TRACE            0x00000400
00053 #define PROB_TRACE          0x00000800
00054 #define QUANT_TRACE         0x00001000
00055 #define NEC_TRACE           0x00002000
00056 #define AUTOMAT_TRACE       0x00004000
00057 #define TAGGER_TRACE        0x00008000
00058 #define SENSES_TRACE        0x00010000
00059 #define CHART_TRACE         0x00020000
00060 #define GRAMMAR_TRACE       0x00040000
00061 #define DEP_TRACE           0x00080000
00062 #define COREF_TRACE         0x00100000
00063 #define UTIL_TRACE          0x00200000
00064 #define WSD_TRACE           0x00400000
00065 #define CORRECTOR_TRACE     0x00800000
00066 #define DATABASE_TRACE      0x01000000
00067 #define FEX_TRACE           0x02000000
00068 #define LANGIDENT_TRACE     0x04000000
00069 #define OMLET_TRACE         0x08000000
00070 #define PHONETICS_TRACE     0x10000000
00071 //#define AVAILABLE           0x20000000
00072 //#define AVAILABLE           0x40000000
00073 //#define AVAILABLE           0x80000000
00074 
00077 #undef MOD_TRACECODE
00078 #undef MOD_TRACENAME
00079 
00083 
00084 class WINDLL traces {
00085  public:
00086   // current trace level
00087   static int TraceLevel;
00088   // modules to trace
00089   static unsigned long TraceModule;
00090 
00091   static void error_crash(const std::wstring &, const std::wstring &, unsigned long);
00092   static void warning(const std::wstring &, const std::wstring &, unsigned long);
00093   static void trace(int,const std::wstring &, const std::wstring &, unsigned long);
00094   static void trace_word (int lv, const word &, const std::wstring &, unsigned long);
00095   static void trace_word_list(int,const std::list<word> &, const std::wstring &, unsigned long);
00096   static void trace_sentence(int,const sentence &, const std::wstring &, unsigned long);
00097   static void trace_sentence_list(int,const std::list<sentence> &, const std::wstring &, unsigned long);
00098 };
00099 
00101 //---------------------------------
00102 inline void traces::error_crash(const std::wstring &msg, const std::wstring &modname, unsigned long modcode) {
00103   std::wcerr<<modname<<L": "<<msg<<std::endl; 
00104   exit(1);
00105 }
00106 
00107 //---------------------------------
00108 inline void traces::warning(const std::wstring &msg, const std::wstring &modname, unsigned long modcode) {
00109   std::wcerr<<modname<<L": "<<msg<<std::endl; 
00110 }
00111 
00112 //---------------------------------
00113 inline void traces::trace(int lv, const std::wstring &msg, const std::wstring &modname, unsigned long modcode) {
00114   if (traces::TraceLevel>=lv && (traces::TraceModule&modcode))
00115     std::wcerr<<modname<<L": "<<msg<<std::endl;
00116 }
00117 
00118 
00119 //---------------------------------
00120 inline void traces::trace_word (int lv, const word &wd, const std::wstring &modname, unsigned long modcode) {
00121   word::const_iterator an; 
00122   std::list<word>::iterator p; 
00123   std::list<word> mw;
00124 
00125   std::wstring sel=L"";
00126   traces::trace(lv, L"Word form ["+wd.get_form()+L"] ("+util::int2wstring(wd.get_span_start())+L","+util::int2wstring(wd.get_span_finish())+L")",modname,modcode); 
00127   
00128   for (an=wd.unselected_begin(); an!=wd.unselected_end(); an++) {    
00129     traces::trace(lv, L"   analysis: <"+an->get_lemma()+L","+an->get_tag()+L","+util::double2wstring(an->get_prob())+L">",modname,modcode); 
00130   }
00131   for (an=wd.selected_begin(); an!=wd.selected_end(); an++) {    
00132     traces::trace(lv, L"   analysis: <"+an->get_lemma()+L","+an->get_tag()+L","+util::double2wstring(an->get_prob())+L"> **",modname,modcode); 
00133   }
00134   
00135   if (wd.is_multiword()) { 
00136     traces::trace(lv, L"   is a multiword composed by:",modname,modcode); 
00137     mw = wd.get_words_mw(); 
00138     for (p=mw.begin(); p!=mw.end(); p++) 
00139       traces::trace(lv, L"     ("+p->get_form()+L")",modname,modcode); 
00140   }
00141 }
00142 
00143 //---------------------------------
00144 inline void traces::trace_word_list(int lv, const std::list<word> &wl, const std::wstring &modname, unsigned long modcode) {
00145   std::list<word>::const_iterator wd; 
00146 
00147   if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00148     for (wd=wl.begin(); wd!=wl.end(); wd++) { 
00149       traces::trace_word(lv, *wd, modname, modcode);
00150     }
00151   }
00152 }
00153 
00154 //---------------------------------
00155 inline void traces::trace_sentence(int lv, const sentence &s, const std::wstring &modname, unsigned long modcode) {
00156   sentence::const_iterator wd; 
00157   
00158   if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00159     traces::trace(lv, L"BEGIN sentence",modname,modcode); 
00160  
00161     if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00162       for (wd=s.begin(); wd!=s.end(); wd++) { 
00163         traces::trace_word(lv, *wd, modname, modcode);
00164       }
00165     }
00166     
00167     traces::trace(lv,L"END sentence",modname,modcode); 
00168   }
00169 }
00170 
00171 //---------------------------------
00172 inline void traces::trace_sentence_list(int lv, const std::list<sentence> &ls, const std::wstring &modname, unsigned long modcode) {
00173   std::list<sentence>::const_iterator s; 
00174 
00175   if (traces::TraceLevel>=lv && (traces::TraceModule&modcode)) {
00176     for(s=ls.begin(); s!=ls.end(); s++) traces::trace_sentence(lv,*s,modname,modcode);  
00177   }
00178 }
00179 
00180 
00183 
00184 #define ERROR_CRASH(msg) traces::error_crash(msg,MOD_TRACENAME,MOD_TRACECODE)
00185 
00188 #ifdef NO_WARNINGS
00189 #define WARNING(msg)
00190 #else
00191 #define WARNING(msg) traces::warning(msg,MOD_TRACENAME,MOD_TRACECODE)
00192 #endif
00193 
00196 #ifdef VERBOSE   
00197 
00198 #define TRACE(x,y) traces::trace(x,y,MOD_TRACENAME,MOD_TRACECODE)
00199 #define TRACE_WORD(x,y) traces::trace_word(x,y,MOD_TRACENAME,MOD_TRACECODE)
00200 #define TRACE_WORD_LIST(x,y) traces::trace_word_list(x,y,MOD_TRACENAME,MOD_TRACECODE)
00201 #define TRACE_SENTENCE(x,y) traces::trace_sentence(x,y,MOD_TRACENAME,MOD_TRACECODE)
00202 #define TRACE_SENTENCE_LIST(x,y) traces::trace_sentence_list(x,y,MOD_TRACENAME,MOD_TRACECODE)
00203 #else
00204 
00205 #define TRACE(x,y)
00206 #define TRACE_WORD(x,y)
00207 #define TRACE_WORD_LIST(x,y)
00208 #define TRACE_SENTENCE(x,y)
00209 #define TRACE_SENTENCE_LIST(x,y)
00210 #endif
00211 
00212 
00213 
00214 
00215 #endif