PLearn 0.1
|
Feature set that is the concatenation of disjoint feature sets. More...
#include <ConcatDisjointFeatureSet.h>
Public Member Functions | |
ConcatDisjointFeatureSet () | |
Default constructor. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ConcatDisjointFeatureSet * | 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 | |
TVec< PP< FeatureSet > > | feature_sets |
Feature sets to concatenate. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef FeatureSet | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
Private Attributes | |
TVec< string > | f_str |
Temporary computations variables. | |
TVec< int > | subfeats |
string | s |
Feature set that is the concatenation of disjoint feature sets.
This class concatenates different feature sets but forces them to be disjoint. This means that, even though two feature sets to concatenate contain the same feature, a distinction will be made between the feature coming from the first and second set.
Definition at line 55 of file ConcatDisjointFeatureSet.h.
typedef FeatureSet PLearn::ConcatDisjointFeatureSet::inherited [private] |
Reimplemented from PLearn::FeatureSet.
Definition at line 57 of file ConcatDisjointFeatureSet.h.
PLearn::ConcatDisjointFeatureSet::ConcatDisjointFeatureSet | ( | ) |
string PLearn::ConcatDisjointFeatureSet::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
OptionList & PLearn::ConcatDisjointFeatureSet::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
RemoteMethodMap & PLearn::ConcatDisjointFeatureSet::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
Reimplemented from PLearn::FeatureSet.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
Object * PLearn::ConcatDisjointFeatureSet::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
StaticInitializer ConcatDisjointFeatureSet::_static_initializer_ & PLearn::ConcatDisjointFeatureSet::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
void PLearn::ConcatDisjointFeatureSet::addFeatures | ( | string | token | ) | [virtual] |
Adds the features for a given token in the set.
Implements PLearn::FeatureSet.
Definition at line 149 of file ConcatDisjointFeatureSet.cc.
References i.
{ for(int i=0; i<feature_sets.length(); i++) feature_sets[i]->addFeatures(token); }
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 155 of file ConcatDisjointFeatureSet.cc.
References i.
{ for(int i=0; i<feature_sets.length(); i++) feature_sets[i]->addFeatures(tokens, min_freq); }
void PLearn::ConcatDisjointFeatureSet::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 59 of file ConcatDisjointFeatureSet.cc.
{ inherited::build(); build_(); }
void PLearn::ConcatDisjointFeatureSet::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::FeatureSet.
Definition at line 82 of file ConcatDisjointFeatureSet.cc.
string PLearn::ConcatDisjointFeatureSet::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
void PLearn::ConcatDisjointFeatureSet::clear | ( | ) | [virtual] |
Clears all features from the feature set.
Implements PLearn::FeatureSet.
Definition at line 161 of file ConcatDisjointFeatureSet.cc.
References PLearn::clear(), and i.
{ for(int i=0; i<feature_sets.length(); i++) feature_sets[i]->clear(); }
void PLearn::ConcatDisjointFeatureSet::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::FeatureSet.
Definition at line 72 of file ConcatDisjointFeatureSet.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), and feature_sets.
{ // Now call the parent class' declareOptions declareOption(ol, "feature_sets", &ConcatDisjointFeatureSet::feature_sets, OptionBase::buildoption, "Feature sets to concatenate"); inherited::declareOptions(ol); }
static const PPath& PLearn::ConcatDisjointFeatureSet::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::FeatureSet.
Definition at line 74 of file ConcatDisjointFeatureSet.h.
:
//##### Protected Options ###############################################
ConcatDisjointFeatureSet * PLearn::ConcatDisjointFeatureSet::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::FeatureSet.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
Gives features of token in index form.
Implements PLearn::FeatureSet.
Definition at line 89 of file ConcatDisjointFeatureSet.cc.
References PLearn::TVec< T >::append(), i, and PLearn::TVec< T >::resize().
{ feats.resize(0); int s = 0; for(int i=0; i<feature_sets.length(); i++) { feature_sets[i]->getFeatures(token,subfeats); subfeats += s; feats.append(subfeats); s += feature_sets[i]->size(); } }
int PLearn::ConcatDisjointFeatureSet::getIndexFeature | ( | string | str | ) | [virtual] |
Gives index form of a feature in string form.
Implements PLearn::FeatureSet.
Definition at line 129 of file ConcatDisjointFeatureSet.cc.
References i, PLERROR, PLearn::toint(), and PLearn::tostring().
{ int fi = toint(tostring(str[1])); int s = 0; #ifdef BOUNDCHECK if(fi >= feature_sets.length()) PLERROR("In ConcatDisjointFeatureSet::getIndexFeature(): string prefix %s of feature is invalid", str.substr(0,3).c_str()); #endif for(int i=0; i<fi; i++) s += feature_sets[i]->size(); return feature_sets[fi]->getIndexFeature(str.substr(3,str.length()-3))+s; }
void PLearn::ConcatDisjointFeatureSet::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 102 of file ConcatDisjointFeatureSet.cc.
References PLearn::TVec< T >::append(), i, j, PLearn::TVec< T >::resize(), and PLearn::tostring().
{ feats_str.resize(0); for(int i=0; i<feature_sets.length(); i++) { feature_sets[i]->getNewFeaturesString(token, f_str); for(int j=0; j<f_str.length(); j++) f_str[j] = "f" + tostring(i) + ":" + f_str[j]; feats_str.append(f_str); } }
OptionList & PLearn::ConcatDisjointFeatureSet::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
OptionMap & PLearn::ConcatDisjointFeatureSet::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
RemoteMethodMap & PLearn::ConcatDisjointFeatureSet::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatDisjointFeatureSet.cc.
string PLearn::ConcatDisjointFeatureSet::getStringFeature | ( | int | index | ) | [virtual] |
Gives string form of a feature in index form.
Implements PLearn::FeatureSet.
Definition at line 114 of file ConcatDisjointFeatureSet.cc.
References i, PLERROR, and PLearn::tostring().
{ #ifdef BOUNDCHECK if(index<0 || index >= size()) PLERROR("In ConcatDisjointFeatureSet::getStringFeature(): index %d is an invalid feature index", index); #endif int sub_index = index; for(int i=0; i<feature_sets.length(); i++) { if(sub_index<feature_sets[i]->size()) return "f" + tostring(i) + ":" + feature_sets[i]->getStringFeature(sub_index); else sub_index -= feature_sets[i]->size(); } PLERROR("In ConcatDisjointFeatureSet::getStringFeature(): index %d is an invalid feature index", index); return ""; }
void PLearn::ConcatDisjointFeatureSet::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::FeatureSet.
Definition at line 65 of file ConcatDisjointFeatureSet.cc.
References PLearn::deepCopyField().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(feature_sets, copies); //PLERROR("ConcatDisjointFeatureSet::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
int PLearn::ConcatDisjointFeatureSet::size | ( | ) | [virtual] |
Gives the number of features in the set.
Implements PLearn::FeatureSet.
Definition at line 141 of file ConcatDisjointFeatureSet.cc.
References i.
{ int ret = 0; for(int i=0; i<feature_sets.length(); i++) ret += feature_sets[i]->size(); return ret; }
Reimplemented from PLearn::FeatureSet.
Definition at line 74 of file ConcatDisjointFeatureSet.h.
TVec<string> PLearn::ConcatDisjointFeatureSet::f_str [private] |
Temporary computations variables.
Definition at line 126 of file ConcatDisjointFeatureSet.h.
Feature sets to concatenate.
Definition at line 63 of file ConcatDisjointFeatureSet.h.
Referenced by declareOptions().
string PLearn::ConcatDisjointFeatureSet::s [private] |
Definition at line 128 of file ConcatDisjointFeatureSet.h.
TVec<int> PLearn::ConcatDisjointFeatureSet::subfeats [private] |
Definition at line 127 of file ConcatDisjointFeatureSet.h.