|
FreeLing
3.0
|
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 00030 // Feature extractor for coreference resolution 00032 00033 #ifndef CORE_FEX_H 00034 #define CORE_FEX_H 00035 00036 #include <list> 00037 #include <fstream> 00038 #include <iostream> 00039 #include <string> 00040 #include <vector> 00041 #include <algorithm> 00042 #include <cctype> 00043 00044 #include "freeling/morfo/language.h" 00045 #include "freeling/morfo/semdb.h" 00046 00047 // -- Feature group codes 00048 #define COREFEX_DIST 0x00000001 00049 #define COREFEX_IPRON 0x00000002 00050 #define COREFEX_JPRON 0x00000004 00051 #define COREFEX_IPRONM 0x00000008 00052 #define COREFEX_JPRONM 0x00000010 00053 #define COREFEX_STRMATCH 0x00000020 00054 #define COREFEX_DEFNP 0x00000040 00055 #define COREFEX_DEMNP 0x00000080 00056 #define COREFEX_NUMBER 0x00000100 00057 #define COREFEX_GENDER 0x00000200 00058 #define COREFEX_SEMCLASS 0x00000400 00059 #define COREFEX_PROPNAME 0x00000800 00060 #define COREFEX_ALIAS 0x00001000 00061 #define COREFEX_APPOS 0x00002000 00062 #define COREFEX_QUOTES 0x00004000 00063 #define COREFEX_THIRDP 0x00010000 00064 // 00065 #define COREFEX_ALL 0xFFFFFFFF 00066 00070 00071 class mention { 00072 public: 00073 int sent; 00074 int numde; 00075 int posbegin; 00076 int posend; 00077 parse_tree::iterator ptree; 00078 std::vector<std::wstring> tokens; 00079 std::vector<std::wstring> tags; 00080 }; 00081 00082 00086 00087 class coref_fex { 00088 private: 00090 semanticDB *semdb; 00092 unsigned int active_features; 00093 00095 wchar_t extract_number(const std::wstring &); 00096 wchar_t extract_gender(const std::wstring &); 00097 std::wstring extract_semclass(const std::wstring &, const std::wstring &); 00098 word& get_head_word(parse_tree::iterator); 00099 bool check_tag(const mention &, int, const std::wstring &); 00100 bool check_word(const std::wstring &, const std::wstring &); 00101 bool check_acronim(const mention &, const mention &); 00102 bool check_prefix(const mention &, const mention &); 00103 bool check_sufix(const mention &, const mention &); 00104 bool check_order(const mention &, const mention &); 00105 00107 int get_dist(const mention &, const mention &); 00108 int get_numdedist(const mention &, const mention &); 00109 int get_dedist(const mention &, const mention &); 00110 int get_i_pronoun(const mention &, const mention &); 00111 int get_j_pronoun(const mention &, const mention &); 00112 int get_i_pronoun_p(const mention &, const mention &); 00113 int get_j_pronoun_p(const mention &, const mention &); 00114 int get_i_pronoun_d(const mention &, const mention &); 00115 int get_j_pronoun_d(const mention &, const mention &); 00116 int get_i_pronoun_x(const mention &, const mention &); 00117 int get_j_pronoun_x(const mention &, const mention &); 00118 int get_i_pronoun_i(const mention &, const mention &); 00119 int get_j_pronoun_i(const mention &, const mention &); 00120 int get_i_pronoun_t(const mention &, const mention &); 00121 int get_j_pronoun_t(const mention &, const mention &); 00122 int get_i_pronoun_r(const mention &, const mention &); 00123 int get_j_pronoun_r(const mention &, const mention &); 00124 int get_i_pronoun_e(const mention &, const mention &); 00125 int get_j_pronoun_e(const mention &, const mention &); 00126 int get_str_match(const mention &, const mention &); 00127 int get_def_np(const mention &, const mention &); 00128 int get_dem_np(const mention &, const mention &); 00129 int get_number(const mention &, const mention &); 00130 int get_gender(const mention &, const mention &); 00131 int get_semclass(const mention &, const mention &); 00132 int get_proper_noun_i(const mention &, const mention &); 00133 int get_proper_noun_j(const mention &, const mention &); 00134 int get_alias_acro(const mention &, const mention &); 00135 int get_alias_prefix(const mention &, const mention &); 00136 int get_alias_sufix(const mention &, const mention &); 00137 int get_alias_order(const mention &, const mention &); 00138 int get_appositive(const mention &, const mention &); 00139 int get_i_inquotes(const mention &, const mention &); 00140 int get_j_inquotes(const mention &, const mention &); 00141 int get_i_inparenthesis(const mention &, const mention &); 00142 int get_j_inparenthesis(const mention &, const mention &); 00143 int get_i_thirdperson(const mention &, const mention &); 00144 int get_j_thirdperson(const mention &, const mention &); 00145 00146 inline void put_feature(int, std::vector<int> &); 00147 00148 public: 00149 coref_fex(const unsigned int, const std::wstring&); 00150 ~coref_fex(); 00151 00152 void extract(const mention &, const mention &, std::vector<int> &); 00153 }; 00154 #endif
1.7.6.1