PLearn 0.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions
PLearn::NGramTree Class Reference

#include <NGramTree.h>

Inheritance diagram for PLearn::NGramTree:
Inheritance graph
[legend]
Collaboration diagram for PLearn::NGramTree:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 NGramTree ()
 Default constructor.
 NGramTree (PP< SymbolNode > root_)
 Makes an NGramTree from a given root.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual NGramTreedeepCopy (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< intfreq (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< intnormalization (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< intn_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 PPathdeclaringFile ()

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options.

Protected Attributes

PP< SymbolNoderoot

Private Types

typedef Object inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 53 of file NGramTree.h.


Member Typedef Documentation

Reimplemented from PLearn::Object.

Definition at line 58 of file NGramTree.h.


Constructor & Destructor Documentation

PLearn::NGramTree::NGramTree ( )

Default constructor.

Definition at line 49 of file NGramTree.cc.

{
    forget();
}
PLearn::NGramTree::NGramTree ( PP< SymbolNode root_)

Makes an NGramTree from a given root.

Definition at line 54 of file NGramTree.cc.

{
    setRoot(root_);
}

Member Function Documentation

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.

bool PLearn::NGramTree::_isa_ ( const Object o) [static]

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.

void PLearn::NGramTree::add ( TVec< int ngram)

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]);
    }
}

Here is the call graph for this function:

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.

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);
}

Here is the call graph for this function:

static const PPath& PLearn::NGramTree::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Object.

Definition at line 97 of file NGramTree.h.

{root = root_;}
NGramTree * PLearn::NGramTree::deepCopy ( CopiesMap copies) const [virtual]

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();
}
TVec< int > PLearn::NGramTree::freq ( TVec< int ngram)

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;
}

Here is the call graph for this function:

TVec< map< int, int > * > PLearn::NGramTree::freqs ( TVec< int ngram)

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;
}

Here is the call graph for this function:

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!");
}
int PLearn::NGramTree::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.

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();;
}

Here is the call graph for this function:

TVec< int > PLearn::NGramTree::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.

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;
}

Here is the call graph for this function:

TVec< int > PLearn::NGramTree::normalization ( TVec< int ngram)

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;
}

Here is the call graph for this function:

void PLearn::NGramTree::setRoot ( PP< SymbolNode root_) [inline]

Sets root to the given SymbolNode.

Definition at line 137 of file NGramTree.h.

{root = root_;}

Member Data Documentation

Reimplemented from PLearn::Object.

Definition at line 97 of file NGramTree.h.

Definition at line 65 of file NGramTree.h.

Referenced by declareOptions().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines