PLearn 0.1
|
#include <NGramTree.h>
Public Member Functions | |
NGramTree () | |
Default constructor. | |
NGramTree (PP< SymbolNode > root_) | |
Makes an NGramTree from a given root. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual NGramTree * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
void | add (TVec< int > ngram) |
Adds a ngram to the tree. | |
TVec< int > | freq (TVec< int > ngram) |
Gives frequencies of the ngram, 1gram, ..., (n-1)gram and ngram (total frequency) | |
TVec< map< int, int > * > | freqs (TVec< int > ngram) |
Returns the freqency maps in the paths corresponding to the ngram. | |
TVec< int > | normalization (TVec< int > ngram) |
Gives the normalization factor for the 1gram, ..., (n-1)gram and ngram for max. likelihood estimator. | |
int | n_children (TVec< int > sequence) |
Gives the number of children of the node corresponding to the given sequence Sequence is w^i_{i-n+1}, w^i is ignored. | |
TVec< int > | n_freq (TVec< int > sequence) |
Gives the number of different symbols in frequencies map of the nodes corresponding to the given sequence This could be noted as N+1(w^{i-1}_{i-n+1}*) Sequence is w^i_{i-n+1}, w^i is ignored. | |
void | setRoot (PP< SymbolNode > root_) |
Sets root to the given SymbolNode. | |
void | forget () |
Reinitialize the NGramTree. | |
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 () |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
PP< SymbolNode > | root |
Private Types | |
typedef Object | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 53 of file NGramTree.h.
typedef Object PLearn::NGramTree::inherited [private] |
Reimplemented from PLearn::Object.
Definition at line 58 of file NGramTree.h.
PLearn::NGramTree::NGramTree | ( | ) |
PLearn::NGramTree::NGramTree | ( | PP< SymbolNode > | root_ | ) |
Makes an NGramTree from a given root.
Definition at line 54 of file NGramTree.cc.
{ setRoot(root_); }
string PLearn::NGramTree::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
OptionList & PLearn::NGramTree::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
RemoteMethodMap & PLearn::NGramTree::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
Object * PLearn::NGramTree::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
StaticInitializer NGramTree::_static_initializer_ & PLearn::NGramTree::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
Adds a ngram to the tree.
Definition at line 95 of file NGramTree.cc.
References i, and PLearn::TVec< T >::length().
{ if(ngram.length() == 0) return; PP<SymbolNode> it = root; it->incr(ngram[ngram.length()-1]); for(int i=ngram.length()-2; i>=0; i--) { it = it->add(ngram[i]); it->incr(ngram[ngram.length()-1]); } }
void PLearn::NGramTree::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::Object.
Definition at line 82 of file NGramTree.cc.
{ inherited::build(); build_(); }
void PLearn::NGramTree::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Object.
Definition at line 79 of file NGramTree.cc.
{}
string PLearn::NGramTree::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
void PLearn::NGramTree::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::Object.
Definition at line 65 of file NGramTree.cc.
References PLearn::declareOption(), PLearn::OptionBase::learntoption, and root.
{ // ### Declare all of this object's options here // ### For the "flags" of each option, you should typically specify // ### one of OptionBase::buildoption, OptionBase::learntoption or // ### OptionBase::tuningoption. Another possible flag to be combined with // ### is OptionBase::nosave declareOption(ol, "root", &NGramTree::root, OptionBase::learntoption, "root of the NGramTree"); inherited::declareOptions(ol); }
static const PPath& PLearn::NGramTree::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
void PLearn::NGramTree::forget | ( | ) |
Reinitialize the NGramTree.
Definition at line 237 of file NGramTree.cc.
{ root = new SymbolNode(); }
Gives frequencies of the ngram, 1gram, ..., (n-1)gram and ngram (total frequency)
Definition at line 108 of file NGramTree.cc.
References PLearn::TVec< T >::fill(), i, PLearn::TVec< T >::length(), and n.
{ TVec<int> ret(ngram.length()); ret.fill(0); ret[0] = root->freq(ngram[ngram.length()-1]); int n=1; PP<SymbolNode> it = root; for(int i=ngram.length()-2; i>=0; i--) { it = it->child(ngram[i]); if(!it) break; ret[n] = it->freq(ngram[ngram.length()-1]); n++; } return ret; }
Returns the freqency maps in the paths corresponding to the ngram.
Note that w^i in the ngram w^i_{i-n+1} is not needed, so it is ignored in the ngram field.
Definition at line 127 of file NGramTree.cc.
References i, PLearn::TVec< T >::length(), and n.
{ TVec<map<int,int>* > ret(ngram.length()); ret[0] = root->freqs(); int n=1; PP<SymbolNode> it = root; for(int i=ngram.length()-2; i>=0; i--) { it = it->child(ngram[i]); if(!it) break; ret[n] = it->freqs(); n++; } return ret; }
OptionList & PLearn::NGramTree::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
OptionMap & PLearn::NGramTree::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
RemoteMethodMap & PLearn::NGramTree::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file NGramTree.cc.
void PLearn::NGramTree::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Object.
Definition at line 88 of file NGramTree.cc.
{ inherited::makeDeepCopyFromShallowCopy(copies); //PLERROR("NGramTree::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
Gives the number of children of the node corresponding to the given sequence Sequence is w^i_{i-n+1}, w^i is ignored.
Definition at line 164 of file NGramTree.cc.
References i, and PLearn::TVec< T >::length().
{ if(sequence.length()==0) return 0; PP<SymbolNode> it = root; for(int i=sequence.length()-2; i>=0; i--) { it = it->child(sequence[i]); if(!it) return 0; } return it->n_children();; }
Gives the number of different symbols in frequencies map of the nodes corresponding to the given sequence This could be noted as N+1(w^{i-1}_{i-n+1}*) Sequence is w^i_{i-n+1}, w^i is ignored.
Definition at line 180 of file NGramTree.cc.
References PLearn::TVec< T >::fill(), i, PLearn::TVec< T >::length(), n, and PLearn::TVec< T >::resize().
{ TVec<int> ret(0); if(sequence.length()==0) return ret; ret.resize(sequence.length()); ret.fill(0); PP<SymbolNode> it = root; int n=0; ret[n++] = it->n_freq(); for(int i=sequence.length()-2; i>=0; i--) { it = it->child(sequence[i]); if(!it) return ret; ret[n++] = it->n_freq(); } return ret; }
Gives the normalization factor for the 1gram, ..., (n-1)gram and ngram for max. likelihood estimator.
Definition at line 145 of file NGramTree.cc.
References PLearn::TVec< T >::fill(), i, PLearn::TVec< T >::length(), and n.
{ TVec<int> ret(ngram.length()); ret.fill(0); ret[0] = root->freq(); int n=1; PP<SymbolNode> it = root; for(int i=ngram.length()-2; i>=0; i--) { it = it->child(ngram[i]); if(!it) break; ret[n] = it->freq(); n++; } return ret; }
void PLearn::NGramTree::setRoot | ( | PP< SymbolNode > | root_ | ) | [inline] |
Reimplemented from PLearn::Object.
Definition at line 97 of file NGramTree.h.
PP<SymbolNode> PLearn::NGramTree::root [protected] |
Definition at line 65 of file NGramTree.h.
Referenced by declareOptions().