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 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 namespace freeling { 00048 00049 // -- Feature group codes 00050 #define COREFEX_DIST 0x00000001 00051 #define COREFEX_IPRON 0x00000002 00052 #define COREFEX_JPRON 0x00000004 00053 #define COREFEX_IPRONM 0x00000008 00054 #define COREFEX_JPRONM 0x00000010 00055 #define COREFEX_STRMATCH 0x00000020 00056 #define COREFEX_DEFNP 0x00000040 00057 #define COREFEX_DEMNP 0x00000080 00058 #define COREFEX_NUMBER 0x00000100 00059 #define COREFEX_GENDER 0x00000200 00060 #define COREFEX_SEMCLASS 0x00000400 00061 #define COREFEX_PROPNAME 0x00000800 00062 #define COREFEX_ALIAS 0x00001000 00063 #define COREFEX_APPOS 0x00002000 00064 #define COREFEX_QUOTES 0x00004000 00065 #define COREFEX_THIRDP 0x00010000 00066 // 00067 #define COREFEX_ALL 0xFFFFFFFF 00068 00072 00073 class mention { 00074 public: 00075 int sent; 00076 int numde; 00077 int posbegin; 00078 int posend; 00079 parse_tree::iterator ptree; 00080 std::vector<std::wstring> tokens; 00081 std::vector<std::wstring> tags; 00082 }; 00083 00084 00088 00089 class coref_fex { 00090 private: 00092 semanticDB *semdb; 00094 unsigned int active_features; 00095 00097 wchar_t extract_number(const std::wstring &); 00098 wchar_t extract_gender(const std::wstring &); 00099 std::wstring extract_semclass(const std::wstring &, const std::wstring &); 00100 const word& get_head_word(parse_tree::iterator); 00101 bool check_tag(const mention &, int, const std::wstring &); 00102 bool check_word(const std::wstring &, const std::wstring &); 00103 bool check_acronim(const mention &, const mention &); 00104 bool check_prefix(const mention &, const mention &); 00105 bool check_sufix(const mention &, const mention &); 00106 bool check_order(const mention &, const mention &); 00107 00109 int get_dist(const mention &, const mention &); 00110 int get_numdedist(const mention &, const mention &); 00111 int get_dedist(const mention &, const mention &); 00112 int get_i_pronoun(const mention &, const mention &); 00113 int get_j_pronoun(const mention &, const mention &); 00114 int get_i_pronoun_p(const mention &, const mention &); 00115 int get_j_pronoun_p(const mention &, const mention &); 00116 int get_i_pronoun_d(const mention &, const mention &); 00117 int get_j_pronoun_d(const mention &, const mention &); 00118 int get_i_pronoun_x(const mention &, const mention &); 00119 int get_j_pronoun_x(const mention &, const mention &); 00120 int get_i_pronoun_i(const mention &, const mention &); 00121 int get_j_pronoun_i(const mention &, const mention &); 00122 int get_i_pronoun_t(const mention &, const mention &); 00123 int get_j_pronoun_t(const mention &, const mention &); 00124 int get_i_pronoun_r(const mention &, const mention &); 00125 int get_j_pronoun_r(const mention &, const mention &); 00126 int get_i_pronoun_e(const mention &, const mention &); 00127 int get_j_pronoun_e(const mention &, const mention &); 00128 int get_str_match(const mention &, const mention &); 00129 int get_def_np(const mention &, const mention &); 00130 int get_dem_np(const mention &, const mention &); 00131 int get_number(const mention &, const mention &); 00132 int get_gender(const mention &, const mention &); 00133 int get_semclass(const mention &, const mention &); 00134 int get_proper_noun_i(const mention &, const mention &); 00135 int get_proper_noun_j(const mention &, const mention &); 00136 int get_alias_acro(const mention &, const mention &); 00137 int get_alias_prefix(const mention &, const mention &); 00138 int get_alias_sufix(const mention &, const mention &); 00139 int get_alias_order(const mention &, const mention &); 00140 int get_appositive(const mention &, const mention &); 00141 int get_i_inquotes(const mention &, const mention &); 00142 int get_j_inquotes(const mention &, const mention &); 00143 int get_i_inparenthesis(const mention &, const mention &); 00144 int get_j_inparenthesis(const mention &, const mention &); 00145 int get_i_thirdperson(const mention &, const mention &); 00146 int get_j_thirdperson(const mention &, const mention &); 00147 00148 inline void put_feature(int, std::vector<int> &); 00149 00150 public: 00151 coref_fex(const unsigned int, const std::wstring&); 00152 ~coref_fex(); 00153 00154 void extract(const mention &, const mention &, std::vector<int> &); 00155 }; 00156 00157 } // namespace 00158 00159 #endif