PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // FillFeatureSetCommand.cc 00004 // 00005 // Copyright (C) 2006 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 // Authors: Hugo Larochelle 00036 00040 #include "FillFeatureSetCommand.h" 00041 #include <plearn/feat/FeatureSet.h> 00042 #include <plearn/vmat/VMatrix.h> 00043 #include <plearn/vmat/SubVMatrix.h> 00044 #include <plearn/db/getDataSet.h> 00045 #include <plearn/io/load_and_save.h> 00046 00047 namespace PLearn { 00048 using namespace std; 00049 00051 PLearnCommandRegistry FillFeatureSetCommand::reg_(new FillFeatureSetCommand); 00052 00053 FillFeatureSetCommand::FillFeatureSetCommand() 00054 : PLearnCommand( 00055 "fill-feat-set", 00056 "PLearn command that fills a FeatureSet with the features instantiated in a VMat", 00057 "Usage: fill-feat-set <dataset> <feat_set> <filled_feat_set> [min_freq] [col]\n" 00058 " Will fill the FeatureSet instantiated from <feat_set> \n" 00059 " from the input tokens found in the <dataset> VMat.\n" 00060 " The filled FeatureSet will be saved in file <filled_feat_set>.\n" 00061 " A minimum frequency can be specified for the features to be\n" 00062 " included in the FeatureSet. The FeatureSet can be filled by\n" 00063 " the features of the tokens found in a particular column of\n" 00064 " <dataset>. If not specified, then the tokens found in all the\n" 00065 " input columns are used.\n" 00066 ) 00067 {} 00068 00070 void FillFeatureSetCommand::run(const vector<string>& args) 00071 { 00072 if(args.size() != 3 && args.size() != 4 && args.size() != 5) 00073 { 00074 cerr << helpmsg << endl; 00075 return; 00076 } 00077 string vmat_file = args[0]; 00078 string feat_file = args[1]; 00079 string filled_feat_file = args[2]; 00080 int min_freq = -1; 00081 int col = -1; 00082 if(args.size() >= 4) 00083 min_freq = toint(args[3]); 00084 if(args.size() >=5) 00085 col = toint(args[4]); 00086 VMat vmat = getDataSet(vmat_file); 00087 VMat get_input_vmat; 00088 if(col < 0) 00089 get_input_vmat = 00090 new SubVMatrix(vmat,0,0,vmat->length(), 00091 vmat->inputsize()); 00092 else 00093 get_input_vmat = 00094 new SubVMatrix(vmat,0,col,vmat->length(), 00095 1); 00096 00097 PP<FeatureSet> feat; 00098 load(feat_file,feat); 00099 feat->addFeatures(get_input_vmat,min_freq); 00100 save(filled_feat_file,feat); 00101 } 00102 00103 } // end of namespace PLearn 00104 00105 00106 /* 00107 Local Variables: 00108 mode:c++ 00109 c-basic-offset:4 00110 c-file-style:"stroustrup" 00111 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00112 indent-tabs-mode:nil 00113 fill-column:79 00114 End: 00115 */ 00116 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :