PLearn 0.1
|
PLearn command that fills a FeatureSet with the features instantiated in a VMat. More...
#include <OutputFeaturesCommand.h>
Public Member Functions | |
OutputFeaturesCommand () | |
virtual void | run (const std::vector< std::string > &args) |
The actual implementation of the 'OutputFeaturesCommand' command. | |
Static Protected Attributes | |
static PLearnCommandRegistry | reg_ |
This allows to register the 'OutputFeaturesCommand' command in the command registry. | |
Private Types | |
typedef PLearnCommand | inherited |
PLearn command that fills a FeatureSet with the features instantiated in a VMat.
A .plearn file for the FeatureSet and a .vmat file for the VMatrix need to be provided. Only the features of the input fields of the VMatrix are are inserted. A path for the saved FeatureSet needs also to be provided
Definition at line 54 of file OutputFeaturesCommand.h.
typedef PLearnCommand PLearn::OutputFeaturesCommand::inherited [private] |
Definition at line 56 of file OutputFeaturesCommand.h.
PLearn::OutputFeaturesCommand::OutputFeaturesCommand | ( | ) |
Definition at line 55 of file OutputFeaturesCommand.cc.
: PLearnCommand( "output-features", "PLearn command that outputs the features found in a VMatrix input fields", "Usage: output-features <dataset> <feat_set> <output_string> [used_feat_set]\n" " Will use feat_set to obtain the features from dataset and output\n" " them. If output_string == 1, the features will be in string \n" " format and if output_string == 0, the feature IDs will be given.\n" " Optionaly, feat_set can be saved in a new file (used_feat_set)\n" " after it has been used. This can be useful when the feature set\n" " maintains a cache of the previously requested features of tokens.\n" " Only the input fields' features are output, with the features of\n" " a single token separated with by ' ' and the features from \n" " different fields separated by '\\t'." ) {}
void PLearn::OutputFeaturesCommand::run | ( | const std::vector< std::string > & | args | ) | [virtual] |
The actual implementation of the 'OutputFeaturesCommand' command.
Implements PLearn::PLearnCommand.
Definition at line 73 of file OutputFeaturesCommand.cc.
References PLearn::endl(), PLearn::getDataSet(), PLearn::PLearnCommand::helpmsg, i, j, PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::load(), PLERROR, PLearn::save(), PLearn::tobool(), w, and PLearn::VMat::width().
{ if(args.size() != 3 && args.size() != 4) { cerr << helpmsg << endl; return; } string vmat_file = args[0]; string feat_file = args[1]; string output_string = args[2]; if(args[2] != "0" && args[2] != "1") PLERROR("In OutputFeaturesCommand::run(): output_string should be 0 or 1"); bool bool_output_string = tobool(output_string); string used_feat_file = ""; if(args.size() == 4) used_feat_file = args[3]; VMat vmat = getDataSet(vmat_file); VMat get_input_vmat; get_input_vmat = new SubVMatrix(vmat,0,0,vmat->length(), vmat->inputsize()); PP<FeatureSet> feat; load(feat_file,feat); Vec row(get_input_vmat->width()); string token; TVec<int> features; TVec<string> f_str; int l = get_input_vmat->length(); int w = get_input_vmat->width(); for(int i=0; i<l; i++) { get_input_vmat->getRow(i,row); for(int j=0; j<w; j++) { token = get_input_vmat->getValString(j,row[j]); feat->getFeatures(token, features); if(bool_output_string) for(int k=0; k<features.length(); k++) { cout << feat->getStringFeature(features[k]); if( k < features.length()-1) cout << " "; } else for(int k=0; k<features.length(); k++) { cout << features[k]; if( k < features.length()-1) cout << " "; } if(j < l-1) cout << "\t"; } cout << endl; } if(used_feat_file != "") save(used_feat_file,feat); }
PLearnCommandRegistry PLearn::OutputFeaturesCommand::reg_ [static, protected] |
This allows to register the 'OutputFeaturesCommand' command in the command registry.
Definition at line 63 of file OutputFeaturesCommand.h.