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 _DATES_MOD 00030 #define _DATES_MOD 00031 00032 #include <map> 00033 00034 #include "freeling/regexp.h" 00035 #include "freeling/morfo/language.h" 00036 #include "freeling/morfo/automat.h" 00037 00038 namespace freeling { 00039 00040 // Date/time regular expressions definitions 00041 00042 const std::wstring RE_ROMAN=L"^([IVXLCDM]+)$"; 00043 00044 // Default: 00045 const std::wstring RE_DATE_DF=L"^(?:(?:((?:[0-3])?(?:\\d))/)(?:((?:(?:[0-1])?(?:\\d)))/)(\\d{1,4}))$"; 00046 const std::wstring RE_TIME1_DF=L"^(?:((?:(?:[0-1])?(?:\\d))|(?:2(?:[0-4])))(?:h|:)(?:((?:[0-5])?(?:\\d))(?:min|m)?)?)$"; 00047 const std::wstring RE_TIME2_DF=L"^(?:((?:[0-5])?(?:\\d))(?:min\\.?|m\\.?))$"; 00048 00049 // Spanish: 00050 const std::wstring RE_DATE_ES=L"^(?:(?:((?:[0-3])?(?:\\d))/)(?:((?:(?:[0-1])?(?:\\d))|enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre|ene|feb|mar|abr|may|jun|jul|ago|sep|oct|nov|dic)/)(\\d{1,4}))$"; 00051 const std::wstring RE_TIME1_ES=L"^(?:((?:(?:[0-1])?(?:\\d))|(?:2(?:[0-4])))(?:h|:)(?:((?:[0-5])?(?:\\d))(?:minutos|min|m)?)?)$"; 00052 const std::wstring RE_TIME2_ES=L"^(?:((?:[0-5])?(?:\\d))(?:minutos|min\\.?|m\\.?))$"; 00053 00054 // Catalan: 00055 const std::wstring RE_DATE_CA=L"^(?:(?:((?:[0-3])?(?:\\d))/)(?:((?:(?:[0-1])?(?:\\d))|gener|febrer|març|abril|maig|juny|juliol|agost|setembre|octubre|novembre|desembre|gen|feb|mar|abr|mai|jun|jul|ago|set|oct|nov|des)/)(\\d{1,4}))$"; 00056 const std::wstring RE_TIME1_CA=L"^(?:((?:(?:[0-1])?(?:\\d))|(?:2(?:[0-4])))(?:h|:)(?:((?:[0-5])?(?:\\d))(?:minuts|min|m)?)?)$"; 00057 const std::wstring RE_TIME2_CA=L"^(?:((?:[0-5])?(?:\\d))(?:minuts|min\\.?|m\\.?))$"; 00058 00059 // English: 00060 const std::wstring RE_DATE_EN=L"^(?:(?:((?:[0-3])?(?:\\d))/)(?:((?:(?:[0-1])?(?:\\d))|january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/)(\\d{1,4}))$"; 00061 const std::wstring RE_TIME1_EN=L"^(?:((?:(?:[0-1])?(?:\\d))|(?:2(?:[0-4])))(?:h|:)(?:((?:[0-5])?(?:\\d))(?:minutes|min|m)?)?)$"; 00062 const std::wstring RE_TIME2_EN=L"^(?:((?:[0-5])?(?:\\d))(?:minutes|min\\.?|m\\.?))$"; 00063 00064 // Galician: 00065 const std::wstring RE_DATE_GL=L"^(?:(?:((?:[0-3])?(?:\\d))/)(?:((?:(?:[0-1])?(?:\\d))|xaneiro|febreiro|marzo|abril|maio|xuño|xullo|agosto|setembro|outubro|novembro|decembro|xan|feb|mar|abr|mai|xuñ|xul|ago|set|out|nov|dec)/)(\\d{1,4}))$"; 00066 const std::wstring RE_TIME1_GL=L"^(?:((?:(?:[0-1])?(?:\\d))|(?:2(?:[0-4])))(?:h|:)(?:((?:[0-5])?(?:\\d))(?:minutos|min|m)?)?)$"; 00067 const std::wstring RE_TIME2_GL=L"^(?:((?:[0-5])?(?:\\d))(?:minutos|min\\.?|m\\.?))$"; 00068 00069 // Portuguese: 00070 const std::wstring RE_DATE_PT=L"^(?:(?:((?:[0-3])?(?:\\d))/)(?:((?:(?:[0-1])?(?:\\d))|janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro|jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/)(\\d{1,4}))$"; 00071 const std::wstring RE_TIME1_PT=L"^(?:((?:(?:[0-1])?(?:\\d))|(?:2(?:[0-4])))(?:h|:)(?:((?:[0-5])?(?:\\d))(?:minutos|min|m)?)?)$"; 00072 const std::wstring RE_TIME2_PT=L"^(?:((?:[0-5])?(?:\\d))(?:minutos|min\\.?|m\\.?))$"; 00073 00074 // Russian: 00075 const std::wstring RE_DATE_RU=L"^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./]([0]?[1-9]|[1][0-2])[./]([0-9]{4}|[0-9]{2})$"; 00076 const std::wstring RE_TIME_RU=L"^(?:((?:(?:[0-1])?(?:\\d))|(?:2(?:[0-4])))(?:ч\\.?|:)(?:((?:[0-5])?(?:\\d))(?:минуты?|мин\\.?)?)?)$"; 00077 const std::wstring RE_MINUTES_RU=L"^(?:((?:[0-5])?(?:\\d))(?:минуты?|мин\\.?))$"; 00078 00079 // Value of unspecified fields in normalized date 00080 const std::wstring UNKNOWN_SYMB = L"??"; 00081 00085 00086 class dates_status : public automat_status { 00087 public: 00089 std::wstring century,year,month,day,weekday,hour,minute,meridian; 00091 int temp; 00092 int sign; // for Catalan "un quart menys(-1)/i(1) cinc de sis" or 00093 // for English: a quarter to(-1)/past(1) five. 00094 00095 int daytemp; // for special state Gbb in English 00096 bool inGbb; 00097 00098 std::vector<std::wstring> rem; // remember results of last matched RegEx 00099 }; 00100 00105 00106 class dates_module: public automat<dates_status> { 00107 00108 protected: 00110 std::map<std::wstring,int> nMes; 00112 std::map<std::wstring,std::wstring> nDia; 00114 std::map<std::wstring,int> tok; 00115 00116 // required regular expressions objects 00117 freeling::regexp RE_Date; 00118 freeling::regexp RE_Time1; 00119 freeling::regexp RE_Time2; 00120 freeling::regexp RE_Roman; 00121 00122 // to unify notation (01 -> 1), maybe adding an offset 00123 std::wstring normalize(const std::wstring &in, int offs=0) const; 00124 00125 private: 00126 virtual void ResetActions(dates_status *) const; 00127 00128 public: 00130 dates_module(const std::wstring &, const std::wstring &, const std::wstring &, const std::wstring &); 00131 virtual ~dates_module() {} 00132 }; 00133 00134 00139 00140 class dates_default : public dates_module { 00141 00142 private: 00143 int ComputeToken(int, sentence::iterator &, sentence &) const; 00144 void StateActions(int, int, int, sentence::const_iterator, dates_status *) const; 00145 void SetMultiwordAnalysis(sentence::iterator, int, const dates_status *) const; 00146 00147 public: 00149 dates_default(); 00150 }; 00151 00156 00157 class dates_es : public dates_module { 00158 00159 private: 00160 int ComputeToken(int, sentence::iterator &, sentence &) const; 00161 void StateActions(int, int, int, sentence::const_iterator, dates_status*) const; 00162 void SetMultiwordAnalysis(sentence::iterator, int, const dates_status*) const; 00163 00164 public: 00166 dates_es(); 00167 }; 00168 00169 00174 00175 class dates_ca : public dates_module { 00176 00177 private: 00178 int ComputeToken(int, sentence::iterator &, sentence &) const; 00179 void StateActions(int, int, int, sentence::const_iterator, dates_status*) const; 00180 void SetMultiwordAnalysis(sentence::iterator, int, const dates_status*) const; 00181 00182 public: 00184 dates_ca(); 00185 }; 00186 00191 00192 class dates_gl : public dates_module { 00193 00194 private: 00195 int ComputeToken(int, sentence::iterator &, sentence &) const; 00196 void StateActions(int, int, int, sentence::const_iterator, dates_status*) const; 00197 void SetMultiwordAnalysis(sentence::iterator, int, const dates_status*) const; 00198 00199 public: 00201 dates_gl(); 00202 }; 00203 00208 00209 class dates_pt : public dates_module { 00210 00211 private: 00212 int ComputeToken(int, sentence::iterator &, sentence &) const; 00213 void StateActions(int, int, int, sentence::const_iterator, dates_status*) const; 00214 void SetMultiwordAnalysis(sentence::iterator, int, const dates_status*) const; 00215 00216 public: 00218 dates_pt(); 00219 }; 00220 00221 00226 00227 class dates_en : public dates_module { 00228 00229 private: 00230 int ComputeToken(int, sentence::iterator &, sentence &) const; 00231 void StateActions(int, int, int, sentence::const_iterator, dates_status*) const; 00232 void SetMultiwordAnalysis(sentence::iterator, int, const dates_status*) const; 00233 00235 std::map<std::wstring,int> numDay; 00236 00237 public: 00239 dates_en(); 00240 }; 00241 00246 00247 class dates_ru : public dates_module { 00248 00249 private: 00250 int ComputeToken(int, sentence::iterator &, sentence &) const; 00251 void StateActions(int, int, int, sentence::const_iterator, dates_status*) const; 00252 void SetMultiwordAnalysis(sentence::iterator, int, const dates_status*) const; 00253 00254 int GetPrevStateValue(dates_status *) const; 00255 void SetPrevStateValue(int, dates_status *) const; 00256 00257 public: 00259 dates_ru(); 00260 }; 00261 00262 } // namespace 00263 00264 #endif 00265