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

#include <ConditionalDictionary.h>

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

List of all members.

Public Member Functions

 ConditionalDictionary ()
 Default constructor.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ConditionalDictionarydeepCopy (CopiesMap &copies) const
virtual void getValues (TVec< string > options, Vec &values)
 Fills a Vec containing every possible ID values of the Dictionary Options can be specified to restrict the number of possible values.
virtual int size (TVec< string > options=TVec< string >(0))
 Get size of the dictionary (number of symbols in the dictionary) Options can be specified to restrict the number of possible values.
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

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

Public Attributes

bool options_to_lower_case
 Put options to lower case.
string mapping_file_path
 Mapping file.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

map< string, Vecoptions_to_symbols
 Option fields to possible symbols mapping.
Vec possible_values
 possible values vector

Private Types

typedef Dictionary inherited

Private Member Functions

void build_ ()
 This does the actual building.
string get_option_string (TVec< string > options)

Private Attributes

string tmp_str
TVec< inttmp_sym

Detailed Description

This class implements a Dictionary where possible symbols depend on the option fields. It is defined simply by giving a mapping file, where each row has the form:

OPTION_1 ... OPTION_M[\tab]TAG_1 TAG_2 TAG_3 ...

where [\tab] is the tabulation character. For instance, a Part Of Speech Dictionary could be defined using lines like:

pet[\tab]NN VB VBD

When the option fields are not found in the mapping, then the possible values are simply the set of all possible symbols (TAG fields) of the Dictionary

Definition at line 69 of file ConditionalDictionary.h.


Member Typedef Documentation

Reimplemented from PLearn::Dictionary.

Definition at line 74 of file ConditionalDictionary.h.


Constructor & Destructor Documentation

PLearn::ConditionalDictionary::ConditionalDictionary ( )

Default constructor.

Definition at line 63 of file ConditionalDictionary.cc.

    : options_to_lower_case(false)
{}

Member Function Documentation

string PLearn::ConditionalDictionary::_classname_ ( ) [static]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

OptionList & PLearn::ConditionalDictionary::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

RemoteMethodMap & PLearn::ConditionalDictionary::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

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

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

Object * PLearn::ConditionalDictionary::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

StaticInitializer ConditionalDictionary::_static_initializer_ & PLearn::ConditionalDictionary::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

void PLearn::ConditionalDictionary::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::Dictionary.

Definition at line 133 of file ConditionalDictionary.cc.

References PLearn::Dictionary::build(), and build_().

Here is the call graph for this function:

void PLearn::ConditionalDictionary::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::Dictionary.

Definition at line 91 of file ConditionalDictionary.cc.

References PLearn::TVec< T >::append(), PLearn::PStream::eof(), PLearn::TVec< T >::find(), get_option_string(), PLearn::Dictionary::getId(), PLearn::getNextNonBlankLine(), i, PLearn::TVec< T >::length(), mapping_file_path, PLearn::openFile(), options_to_symbols, PLERROR, PLearn::PStream::raw_ascii, PLearn::TVec< T >::size(), PLearn::split(), tmp_str, UPDATE, and PLearn::Dictionary::update_mode.

Referenced by build().

{
    if(options_to_symbols.size() == 0)
    {
        int last_update_mode = update_mode;
        update_mode = UPDATE;
        
        TVec<string> tokens;
        TVec<string> options;
        TVec<string> symbols;
        int id;
        string line; 
        PStream input_stream = openFile(mapping_file_path, PStream::raw_ascii);
        while (!input_stream.eof()){
            getNextNonBlankLine(input_stream, line);
            tokens = split(line, "\t");
            if(tokens.length() != 2)
                PLERROR("In ConditionalDictionary::build_(): line \"%s\" is in bad format",line.c_str());
            options = split(tokens[0]," ");
            symbols = split(tokens[1]," ");
            
            Vec symbols_id = Vec(0); 

            // Insert symbols in dictionaries
            for(int i=0; i<symbols.size(); i++)
            {
                id = getId(symbols[i]);
                if(symbols_id.find(id) < 0)
                    symbols_id.append(id);
            }
            // Insert symbols in map
            tmp_str = get_option_string(options);
            if(options_to_symbols.find(tmp_str) == options_to_symbols.end())
                PLERROR("In ConditionalDictionary::build_(): there is more than one mapping for option \"%s\"",tmp_str.c_str());
            options_to_symbols[tmp_str] = symbols_id;
        }
        
        update_mode = last_update_mode;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::ConditionalDictionary::classname ( ) const [virtual]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

void PLearn::ConditionalDictionary::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::Dictionary.

Definition at line 84 of file ConditionalDictionary.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Dictionary::declareOptions(), mapping_file_path, and options_to_lower_case.

{
    declareOption(ol, "options_to_lower_case", &ConditionalDictionary::options_to_lower_case, OptionBase::buildoption, "Indication that the given options should be put to lower case");
    declareOption(ol, "mapping_file_path", &ConditionalDictionary::mapping_file_path, OptionBase::buildoption, "Path to the mapping file");
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Dictionary.

Definition at line 122 of file ConditionalDictionary.h.

ConditionalDictionary * PLearn::ConditionalDictionary::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

string PLearn::ConditionalDictionary::get_option_string ( TVec< string >  options) [private]

Definition at line 52 of file ConditionalDictionary.cc.

References i, PLearn::TVec< T >::length(), and PLearn::lowerstring().

Referenced by build_(), getValues(), and size().

{
    string ret = options[0];
    for(int i=1; i<options.length(); i++)
        ret = ret + " " + options[i];
    if(options_to_lower_case)
        return lowerstring(ret);
    else
        return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OptionList & PLearn::ConditionalDictionary::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

OptionMap & PLearn::ConditionalDictionary::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

RemoteMethodMap & PLearn::ConditionalDictionary::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Dictionary.

Definition at line 82 of file ConditionalDictionary.cc.

void PLearn::ConditionalDictionary::getValues ( TVec< string >  options,
Vec values 
) [virtual]

Fills a Vec containing every possible ID values of the Dictionary Options can be specified to restrict the number of possible values.

A Vec instead of a TVec<int> is required, for compatibility with the getValues() function of VMatrix objects.

Reimplemented from PLearn::Dictionary.

Definition at line 139 of file ConditionalDictionary.cc.

References get_option_string(), PLearn::Dictionary::getValues(), PLearn::TVec< T >::length(), and options_to_symbols.

{ 
    if(options.length() == 0)
        inherited::getValues(options, values);

    string ret = get_option_string(options);
    if(options_to_symbols.find(ret) != options_to_symbols.end())
        values << options_to_symbols[ret];
    else
        inherited::getValues(options, values);
}

Here is the call graph for this function:

void PLearn::ConditionalDictionary::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Dictionary.

Definition at line 164 of file ConditionalDictionary.cc.

References PLearn::deepCopyField(), PLearn::Dictionary::makeDeepCopyFromShallowCopy(), options_to_symbols, and tmp_sym.

Here is the call graph for this function:

int PLearn::ConditionalDictionary::size ( TVec< string >  options = TVec<string>(0)) [virtual]

Get size of the dictionary (number of symbols in the dictionary) Options can be specified to restrict the number of possible values.

Reimplemented from PLearn::Dictionary.

Definition at line 151 of file ConditionalDictionary.cc.

References get_option_string(), PLearn::TVec< T >::length(), options_to_symbols, and PLearn::Dictionary::size().

                                                   {
    if(options.length() == 0)
        return inherited::size();
    else         
    {
        string ret = get_option_string(options);
        if(options_to_symbols.find(ret) != options_to_symbols.end())
            return options_to_symbols[ret].length();
        else
            return inherited::size();
    }
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::Dictionary.

Definition at line 122 of file ConditionalDictionary.h.

Mapping file.

Definition at line 97 of file ConditionalDictionary.h.

Referenced by build_(), and declareOptions().

Put options to lower case.

Definition at line 94 of file ConditionalDictionary.h.

Referenced by declareOptions().

Option fields to possible symbols mapping.

Definition at line 82 of file ConditionalDictionary.h.

Referenced by build_(), getValues(), makeDeepCopyFromShallowCopy(), and size().

possible values vector

Definition at line 85 of file ConditionalDictionary.h.

Definition at line 76 of file ConditionalDictionary.h.

Referenced by build_().

Definition at line 77 of file ConditionalDictionary.h.

Referenced by makeDeepCopyFromShallowCopy().


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