PLearn 0.1
|
Feature set that maintains a cached mapping between tokens and their features. More...
#include <CachedFeatureSet.h>
Public Member Functions | |
CachedFeatureSet () | |
Default constructor. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual CachedFeatureSet * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual void | getFeatures (string token, TVec< int > &feats) |
Gives features of token in index form. | |
virtual string | getStringFeature (int index) |
Gives string form of a feature in index form. | |
virtual int | getIndexFeature (string str) |
Gives index form of a feature in string form. | |
virtual int | size () |
Gives the number of features in the set. | |
virtual void | addFeatures (string token) |
Adds the features for a given token in the set. | |
virtual void | addFeatures (VMat tokens, int min_freq=-1) |
Adds the features for the tokens contained in the set. | |
virtual void | clear () |
Clears all features from the feature set. | |
virtual void | getNewFeaturesString (string token, TVec< string > &feats_str) |
Gives the possibly new features in string form for a token. | |
Static Public Member Functions | |
static string | _classname_ () |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
PP< FeatureSet > | source |
Source feature set, for which a buffer is maintained. | |
bool | report_progress |
Indication that progress should be reported in a ProgressBar when adding features in the cache in addFeatures(VMat,int). | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Protected Attributes | |
hash_map< string, TVec< int > > | token_to_features |
Token to features mapping. | |
Private Types | |
typedef FeatureSet | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
Private Attributes | |
TVec< int > | f |
Temporary computations vectors. | |
TVec< int > | f_temp |
int | index |
Feature set that maintains a cached mapping between tokens and their features.
This cache permits potentially faster access to a token's features using the getFeatures() function, when a call to to that function has been done previously for that given token. A source FeatureSet that provides the features most be given. It is assumed that adding features will not change the index assignements of the previously added features.
Definition at line 57 of file CachedFeatureSet.h.
typedef FeatureSet PLearn::CachedFeatureSet::inherited [private] |
Reimplemented from PLearn::FeatureSet.
Definition at line 59 of file CachedFeatureSet.h.
PLearn::CachedFeatureSet::CachedFeatureSet | ( | ) |
string PLearn::CachedFeatureSet::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 55 of file CachedFeatureSet.cc.
OptionList & PLearn::CachedFeatureSet::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 55 of file CachedFeatureSet.cc.
RemoteMethodMap & PLearn::CachedFeatureSet::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 55 of file CachedFeatureSet.cc.
Reimplemented from PLearn::FeatureSet.
Definition at line 55 of file CachedFeatureSet.cc.
Object * PLearn::CachedFeatureSet::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 55 of file CachedFeatureSet.cc.
StaticInitializer CachedFeatureSet::_static_initializer_ & PLearn::CachedFeatureSet::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 55 of file CachedFeatureSet.cc.
void PLearn::CachedFeatureSet::addFeatures | ( | string | token | ) | [virtual] |
Adds the features for a given token in the set.
Implements PLearn::FeatureSet.
Definition at line 124 of file CachedFeatureSet.cc.
References f_temp, getFeatures(), and source.
{ source->addFeatures(token); // Insert these features in the cache getFeatures(token,f_temp); return; }
Adds the features for the tokens contained in the set.
Features with frequency smaller than min_freq are not added.
Implements PLearn::FeatureSet.
Definition at line 132 of file CachedFeatureSet.cc.
References f_temp, getFeatures(), i, j, PLearn::VMat::length(), report_progress, source, PLearn::tostring(), and PLearn::VMat::width().
{ source->addFeatures(tokens, min_freq); // Inserting these features in the cache string token; Vec row(tokens->width()); PP<ProgressBar> pb; int id=0; if(report_progress) pb = new ProgressBar("Adding in cache the features of " + tostring(tokens->length()*tokens->width()) + " tokens", tokens->length()*tokens->width()); for(int i=0; i<tokens->length(); i++) { tokens->getRow(i,row); for(int j=0; j<tokens->width(); j++) { token = tokens->getValString(j,row[j]); getFeatures(token,f_temp); if(report_progress) pb->update(++id); } } return; }
void PLearn::CachedFeatureSet::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::FeatureSet.
Definition at line 62 of file CachedFeatureSet.cc.
References PLearn::FeatureSet::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::CachedFeatureSet::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::FeatureSet.
Definition at line 93 of file CachedFeatureSet.cc.
Referenced by build().
{}
string PLearn::CachedFeatureSet::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file CachedFeatureSet.cc.
void PLearn::CachedFeatureSet::clear | ( | ) | [virtual] |
Clears all features from the feature set.
Implements PLearn::FeatureSet.
Definition at line 159 of file CachedFeatureSet.cc.
References source, and token_to_features.
{ source->clear(); token_to_features.clear(); }
void PLearn::CachedFeatureSet::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::FeatureSet.
Definition at line 76 of file CachedFeatureSet.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::FeatureSet::declareOptions(), PLearn::OptionBase::learntoption, report_progress, source, and token_to_features.
{ declareOption(ol, "source", &CachedFeatureSet::source, OptionBase::buildoption, "Source feature set, for which a buffer is maintained"); declareOption(ol, "token_to_features", &CachedFeatureSet::token_to_features, OptionBase::learntoption, "Token to features mapping"); declareOption(ol, "report_progress", &CachedFeatureSet::report_progress, OptionBase::buildoption, "Indication that progress should be reported in a ProgressBar\n" "when adding features in the cache in addFeatures(VMat,int).\n"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::CachedFeatureSet::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 79 of file CachedFeatureSet.h.
:
//##### Protected Options ###############################################
CachedFeatureSet * PLearn::CachedFeatureSet::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::FeatureSet.
Definition at line 55 of file CachedFeatureSet.cc.
Gives features of token in index form.
Implements PLearn::FeatureSet.
Definition at line 96 of file CachedFeatureSet.cc.
References PLearn::TVec< T >::copy(), f, PLearn::TVec< T >::length(), PLearn::TVec< T >::resize(), source, and token_to_features.
Referenced by addFeatures().
{ if(token_to_features.find(token) != token_to_features.end()) { f = token_to_features[token]; feats.resize(f.length()); feats << f; return; } source->getFeatures(token,feats); token_to_features[token] = feats.copy(); }
int PLearn::CachedFeatureSet::getIndexFeature | ( | string | str | ) | [virtual] |
Gives index form of a feature in string form.
Implements PLearn::FeatureSet.
Definition at line 114 of file CachedFeatureSet.cc.
References source.
{ return source->getIndexFeature(str); }
void PLearn::CachedFeatureSet::getNewFeaturesString | ( | string | token, |
TVec< string > & | feats_str | ||
) | [virtual] |
Gives the possibly new features in string form for a token.
Implements PLearn::FeatureSet.
Definition at line 165 of file CachedFeatureSet.cc.
References source.
OptionList & PLearn::CachedFeatureSet::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file CachedFeatureSet.cc.
OptionMap & PLearn::CachedFeatureSet::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file CachedFeatureSet.cc.
RemoteMethodMap & PLearn::CachedFeatureSet::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file CachedFeatureSet.cc.
string PLearn::CachedFeatureSet::getStringFeature | ( | int | index | ) | [virtual] |
Gives string form of a feature in index form.
Implements PLearn::FeatureSet.
Definition at line 109 of file CachedFeatureSet.cc.
References source.
{ return source->getStringFeature(index); }
void PLearn::CachedFeatureSet::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::FeatureSet.
Definition at line 68 of file CachedFeatureSet.cc.
References PLearn::deepCopyField(), f, PLearn::FeatureSet::makeDeepCopyFromShallowCopy(), source, and token_to_features.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(source, copies); deepCopyField(token_to_features, copies); deepCopyField(f, copies); }
int PLearn::CachedFeatureSet::size | ( | ) | [virtual] |
Gives the number of features in the set.
Implements PLearn::FeatureSet.
Definition at line 119 of file CachedFeatureSet.cc.
References source.
{ return source->size(); }
Reimplemented from PLearn::FeatureSet.
Definition at line 79 of file CachedFeatureSet.h.
TVec<int> PLearn::CachedFeatureSet::f [private] |
Temporary computations vectors.
Definition at line 134 of file CachedFeatureSet.h.
Referenced by getFeatures(), and makeDeepCopyFromShallowCopy().
TVec<int> PLearn::CachedFeatureSet::f_temp [private] |
Definition at line 134 of file CachedFeatureSet.h.
Referenced by addFeatures().
int PLearn::CachedFeatureSet::index [private] |
Definition at line 135 of file CachedFeatureSet.h.
Indication that progress should be reported in a ProgressBar when adding features in the cache in addFeatures(VMat,int).
Definition at line 68 of file CachedFeatureSet.h.
Referenced by addFeatures(), and declareOptions().
Source feature set, for which a buffer is maintained.
Definition at line 65 of file CachedFeatureSet.h.
Referenced by addFeatures(), clear(), declareOptions(), getFeatures(), getIndexFeature(), getNewFeaturesString(), getStringFeature(), makeDeepCopyFromShallowCopy(), and size().
hash_map<string, TVec<int> > PLearn::CachedFeatureSet::token_to_features [protected] |
Token to features mapping.
Definition at line 116 of file CachedFeatureSet.h.
Referenced by clear(), declareOptions(), getFeatures(), and makeDeepCopyFromShallowCopy().