PLearn 0.1
DictionaryVMatrix.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // DictionaryVMatrix.h
00004 //
00005 // Copyright (C) 2004 Hugo Larochelle
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: DictionaryVMatrix.h 9436 2008-09-04 18:48:55Z nouiz $
00037  ******************************************************* */
00038 
00039 // Authors: Hugo Larochelle
00040 
00044 #ifndef DictionaryVMatrix_INC
00045 #define DictionaryVMatrix_INC
00046 
00047 #include <plearn/python/PythonCodeSnippet.h>
00048 
00049 #include <plearn/base/stringutils.h>
00050 #include <plearn/vmat/RowBufferedVMatrix.h>
00051 #include <plearn/dict/Dictionary.h>
00052 
00053 // number of attributes of dictionary specifications
00054 #define DIC_SPECIFICATION_SIZE 3
00055 
00056 namespace PLearn {
00057 using namespace std;
00058 
00080 
00081 class DictionaryVMatrix: public RowBufferedVMatrix
00082 {
00083 
00084 private:
00085 
00086 
00087     typedef RowBufferedVMatrix inherited;
00088 
00089     Mat data;
00090 
00091 protected:
00092 
00093     // *********************
00094     // * protected options *
00095     // *********************
00096 
00098     int n_attributes;
00099 
00101     PP<PythonCodeSnippet> python;
00102 
00103 public:
00104 
00105     // ************************
00106     // * public build options *
00107     // ************************
00108 
00110     TVec<PPath> file_names;
00111 
00113     TVec< PP<Dictionary> > dictionaries;
00114 
00116     TVec< TVec <int> > option_fields;
00117 
00119     string delimiters;
00120 
00122     string code;
00123 
00126     TVec<int> minimum_frequencies;
00127 
00129     TVec< TVec<string> >symbols_to_ignore;
00130 
00133     bool remove_rows_with_oov;
00134 
00135     // ****************
00136     // * Constructors *
00137     // ****************
00138 
00139     // Default constructor, make sure the implementation in the .cc
00140     // initializes all fields to reasonable default values.
00141     DictionaryVMatrix();
00142 
00143 private:
00144 
00146     // (Please implement in .cc)
00147     void build_();
00148 
00149 protected:
00150 
00152     // (Please implement in .cc)
00153     static void declareOptions(OptionList& ol);
00154 
00157     virtual void getNewRow(int i, const Vec& v) const;
00158 
00159 public:
00160 
00162     virtual real getStringVal(int col, const string & str) const;
00163 
00164     virtual string getValString(int col, real val) const;
00165 
00166     virtual void getValues(int row, int col, Vec& values) const;
00167 
00169     virtual void getValues(const Vec& input, int col, Vec& values) const;
00170 
00171     // Simply call inherited::build() then build_().
00172     virtual void build();
00173 
00175     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00176 
00178     virtual PP<Dictionary> getDictionary(int col) const;
00179 
00180     //  virtual void save(const string& filename) ;
00182     PLEARN_DECLARE_OBJECT(DictionaryVMatrix);
00183 
00184 };
00185 
00186 DECLARE_OBJECT_PTR(DictionaryVMatrix);
00187 
00188 } // end of namespace PLearn
00189 #endif
00190 
00191 
00192 /*
00193   Local Variables:
00194   mode:c++
00195   c-basic-offset:4
00196   c-file-style:"stroustrup"
00197   c-file-offsets:((innamespace . 0)(inline-open . 0))
00198   indent-tabs-mode:nil
00199   fill-column:79
00200   End:
00201 */
00202 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines