FreeLing  4.0
coref_fex.h
Go to the documentation of this file.
00001 
00002 //
00003 //    FreeLing - Open Source Language Analyzers
00004 //
00005 //    Copyright (C) 2014   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 Affero 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 //    Affero General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU Affero 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 
00069   class mention_ab {
00070   public:
00071     int sent;
00072     int numde;
00073     parse_tree::iterator ptree;
00074     int posbegin;
00075     int posend;
00076     std::vector<std::wstring> tokens;
00077     std::vector<std::wstring> tags;
00078     int chain;
00079   };
00080 
00084 
00085   class coref_fex {
00086 
00087   private:
00089     semanticDB *semdb;
00091     unsigned int active_features;
00092 
00094     wchar_t extract_number(const std::wstring &);
00095     wchar_t extract_gender(const std::wstring &);
00096     std::wstring extract_semclass(const std::wstring &, const std::wstring &);
00097     const word& get_head_word(parse_tree::iterator);
00098     bool check_tag(const mention_ab &, int, const std::wstring &);
00099     bool check_word(const std::wstring &, const std::wstring &);
00100     bool check_acronim(const mention_ab &, const mention_ab &);
00101     bool check_prefix(const mention_ab &, const mention_ab &);
00102     bool check_sufix(const mention_ab &, const mention_ab &);
00103     bool check_order(const mention_ab &, const mention_ab &);
00104 
00106     int get_dist(const mention_ab &, const mention_ab &); 
00107     int get_numdedist(const mention_ab &, const mention_ab &);
00108     int get_dedist(const mention_ab &, const mention_ab &);
00109     int get_i_pronoun(const mention_ab &, const mention_ab &);
00110     int get_j_pronoun(const mention_ab &, const mention_ab &);
00111     int get_i_pronoun_p(const mention_ab &, const mention_ab &);
00112     int get_j_pronoun_p(const mention_ab &, const mention_ab &);
00113     int get_i_pronoun_d(const mention_ab &, const mention_ab &);
00114     int get_j_pronoun_d(const mention_ab &, const mention_ab &);
00115     int get_i_pronoun_x(const mention_ab &, const mention_ab &);
00116     int get_j_pronoun_x(const mention_ab &, const mention_ab &);
00117     int get_i_pronoun_i(const mention_ab &, const mention_ab &);
00118     int get_j_pronoun_i(const mention_ab &, const mention_ab &);
00119     int get_i_pronoun_t(const mention_ab &, const mention_ab &);
00120     int get_j_pronoun_t(const mention_ab &, const mention_ab &);
00121     int get_i_pronoun_r(const mention_ab &, const mention_ab &);
00122     int get_j_pronoun_r(const mention_ab &, const mention_ab &);
00123     int get_i_pronoun_e(const mention_ab &, const mention_ab &);
00124     int get_j_pronoun_e(const mention_ab &, const mention_ab &);
00125     int get_str_match(const mention_ab &, const mention_ab &);
00126     int get_def_np(const mention_ab &, const mention_ab &);
00127     int get_dem_np(const mention_ab &, const mention_ab &);
00128     int get_number(const mention_ab &, const mention_ab &);
00129     int get_gender(const mention_ab &, const mention_ab &);
00130     int get_semclass(const mention_ab &, const mention_ab &);
00131     int get_proper_noun_i(const mention_ab &, const mention_ab &);
00132     int get_proper_noun_j(const mention_ab &, const mention_ab &);
00133     int get_alias_acro(const mention_ab &, const mention_ab &);
00134     int get_alias_prefix(const mention_ab &, const mention_ab &);
00135     int get_alias_sufix(const mention_ab &, const mention_ab &);
00136     int get_alias_order(const mention_ab &, const mention_ab &);
00137     int get_appositive(const mention_ab &, const mention_ab &);
00138     int get_i_inquotes(const mention_ab &, const mention_ab &);
00139     int get_j_inquotes(const mention_ab &, const mention_ab &);
00140     int get_i_inparenthesis(const mention_ab &, const mention_ab &);
00141     int get_j_inparenthesis(const mention_ab &, const mention_ab &);
00142     int get_i_thirdperson(const mention_ab &, const mention_ab &);
00143     int get_j_thirdperson(const mention_ab &, const mention_ab &);
00144   
00145     inline void put_feature(int, std::vector<int> &);
00146 
00147   public:
00148     coref_fex(unsigned int, const std::wstring&);
00149     ~coref_fex();
00150 
00151     void extract(const mention_ab &, const mention_ab &, std::vector<int> &);
00152   };
00153 
00154 } // namespace
00155 
00156 #endif