PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // WordNetSenseDictionary.h 00004 // 00005 // Copyright (C) 2004 Hugo Larochelle Christopher Kermorvant 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 /* ******************************************************* 00036 * $Id: WordNetSenseDictionary.h 6338 2006-10-23 20:33:09Z larocheh $ 00037 ******************************************************* */ 00038 00039 // Authors: Hugo Larochelle, Christopher Kermorvant 00040 00044 #ifndef WordNetSenseDictionary_INC 00045 #define WordNetSenseDictionary_INC 00046 #include "Dictionary.h" 00047 #include "wn.h" 00048 00049 #define WN_ROOT_NODE "wn_root_node" 00050 #define WN_NOUN_NODE "wn_noun_node" 00051 #define WN_VERB_NODE "wn_verb_node" 00052 #define WN_ADJ_NODE "wn_adj_node" 00053 #define WN_ADV_NODE "wn_adv_node" 00054 00055 namespace PLearn { 00056 using namespace std; 00057 00058 // Tool functions 00059 00063 char* cstr(string& str); 00065 string getSynsetKey(SynsetPtr ssp); 00067 SynsetPtr getSynsetPtr(string synset_key); 00071 void extractSenses(string word, int wn_pos, string symbol_type, TVec<string>& senses,TVec<int>& tagcnts, TVec< TVec<string> >& ancestors, bool extract_ancestors=false); 00073 void extractAncestors(TVec<SynsetPtr> anc, TVec< TVec<string> >& anc_str, string root_node=WN_ROOT_NODE); 00075 string stemWord(string word); 00077 string stemWord(string word, int wn_pos); 00079 void stemsOfWord(string word, int wn_pos, TVec<string>& stems); 00081 void stemsOfWord(string word, TVec<string>& stems); 00082 00087 class WordNetSenseDictionary: public Dictionary 00088 { 00089 00090 private: 00091 00092 typedef Dictionary inherited; 00093 00094 protected: 00095 00097 Vec possible_values; 00098 00099 public: 00100 00101 // ************************ 00102 // * public build options * 00103 // ************************ 00104 00106 bool options_stem_words; 00107 00109 bool options_to_lower_case; 00110 00112 string symbol_type; 00113 00115 hash_map<string,Vec > possible_values_for_word; 00116 00117 // Hierarchy information: 00118 00120 bool use_wordnet_hierarchy; 00121 00123 hash_map<int, TVec<int> > children; 00124 00126 hash_map<int, TVec<int> > parents; 00127 00129 hash_map<string, real> sense_prior; 00130 00131 protected: 00132 00134 TVec<string> stems; 00135 00137 TVec<string> senses; 00138 00140 TVec< TVec<string> > ancestors_vec; 00141 00143 TVec<int> tagcnts; 00144 00146 int ret; 00147 00149 string word_sense; 00150 00151 00152 // ****************** 00153 // * Object methods * 00154 // ****************** 00155 00156 private: 00158 void build_(); 00159 00160 protected: 00162 static void declareOptions(OptionList& ol); 00163 00164 void getSensesFromWordNet(TVec<string> options); 00165 00166 public: 00167 00168 // **************** 00169 // * Constructors * 00170 // **************** 00171 00173 WordNetSenseDictionary(); 00174 00175 // Declares other standard object methods. 00176 PLEARN_DECLARE_OBJECT(WordNetSenseDictionary); 00177 00178 virtual int getId(string symbol, TVec<string> options = TVec<string>(0)); 00179 00180 virtual void getValues(TVec<string> options, Vec& values); 00181 00182 virtual int size(TVec<string> options=TVec<string>(0)); 00183 00187 virtual void parentsOf(int sense, TVec<int>& the_parents); 00188 00192 virtual void childrenOf(int sense, TVec<int>& the_children); 00193 00195 virtual int rootNode(); 00196 00198 virtual real sensePrior(string word, string sense); 00199 00200 // simply calls inherited::build() then build_() 00201 virtual void build(); 00202 00204 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00205 00206 }; 00207 00208 // Declares a few other classes and functions related to this class 00209 DECLARE_OBJECT_PTR(WordNetSenseDictionary); 00210 00211 } // end of namespace PLearn 00212 00213 #endif 00214 00215 00216 /* 00217 Local Variables: 00218 mode:c++ 00219 c-basic-offset:4 00220 c-file-style:"stroustrup" 00221 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00222 indent-tabs-mode:nil 00223 fill-column:79 00224 End: 00225 */ 00226 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :