PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // Dictionary.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: Dictionary.h 8184 2007-10-15 20:09:46Z nouiz $ 00037 ******************************************************* */ 00038 00039 // Authors: Hugo Larochelle, Christopher Kermorvant 00040 00044 #ifndef Dictionary_INC 00045 #define Dictionary_INC 00046 #include <plearn/base/Object.h> 00047 #include <plearn/base/stringutils.h> 00048 #include <map> 00049 #include <string> 00050 00051 #define NO_UPDATE 0 00052 #define UPDATE 1 00053 00054 namespace PLearn { 00055 using namespace std; 00056 00087 class Dictionary: public Object 00088 { 00089 00090 private: 00091 00092 typedef Object inherited; 00093 00094 protected: 00095 // ********************* 00096 // * protected options * 00097 // ********************* 00098 00100 map<string,int> string_to_int; 00102 map<int,string> int_to_string; 00103 00104 public: 00105 00106 // ************************ 00107 // * public build options * 00108 // ************************ 00110 int update_mode; 00113 bool dont_insert_oov_symbol; 00115 string oov_symbol; 00116 00117 // **************** 00118 // * Constructors * 00119 // **************** 00120 00122 Dictionary(); 00123 00124 // ****************** 00125 // * Object methods * 00126 // ****************** 00127 00128 private: 00130 void build_(); 00131 00132 protected: 00134 static void declareOptions(OptionList& ol); 00135 00136 public: 00137 00138 PLEARN_DECLARE_OBJECT(Dictionary); 00139 00141 virtual void setUpdateMode(int up_mode); 00142 00150 virtual int getId(string symbol, TVec<string> options = TVec<string>(0)); 00151 00155 virtual string getSymbol(int id, TVec<string> options = TVec<string>(0))const; 00156 00159 virtual int size(TVec<string> options=TVec<string>(0)); 00160 00165 virtual void getValues(TVec<string> options, Vec& values); 00166 00171 virtual bool isIn(string symbol, TVec<string> options=TVec<string>(0)); 00172 00177 virtual bool isIn(int id, TVec<string> options=TVec<string>(0)); 00178 00179 virtual void clear(); 00180 00181 // simply calls inherited::build() then build_() 00182 virtual void build(); 00183 00185 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00186 00187 }; 00188 00189 // Declares a few other classes and functions related to this class 00190 DECLARE_OBJECT_PTR(Dictionary); 00191 00192 } // end of namespace PLearn 00193 00194 #endif 00195 00196 00197 /* 00198 Local Variables: 00199 mode:c++ 00200 c-basic-offset:4 00201 c-file-style:"stroustrup" 00202 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00203 indent-tabs-mode:nil 00204 fill-column:79 00205 End: 00206 */ 00207 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :