PLearn 0.1
|
A VMatrix view of a SimpleDB: columns whose type is string are removed from the view, all others are converted to real (characters to their ascii code, and dates to the float date format: 990324) More...
#include <AutoSDBVMatrix.h>
Public Member Functions | |
AutoSDBVMatrix (const string &dbname) | |
int | nstrings () |
Returns the number of string fields (these will not be used in getRow!) | |
void | getMappings () |
gets mappings for each string field | |
virtual string | getValString (int col, real val) const |
returns the string associated with value val for field# col. | |
Protected Member Functions | |
virtual void | getNewRow (int i, const Vec &v) const |
This is the only method requiring implementation in subclasses. | |
Protected Attributes | |
SDB | sdb_ |
Row | row_ |
hash_map< string, StringFieldMapping > | string_field_map |
hash_map< string, NumToStringMapping > | num2string_map |
A VMatrix view of a SimpleDB: columns whose type is string are removed from the view, all others are converted to real (characters to their ascii code, and dates to the float date format: 990324)
Definition at line 156 of file AutoSDBVMatrix.h.
PLearn::AutoSDBVMatrix::AutoSDBVMatrix | ( | const string & | dbname | ) |
Definition at line 51 of file AutoSDBVMatrix.cc.
References PLearn::VMField::Date, PLearn::DateType, PLearn::VMatrix::declareField(), PLearn::extract_directory(), PLearn::extract_filename(), PLearn::force_mkdir(), getMappings(), PLearn::SimpleDB< KeyType, QueryResult >::getSchema(), i, PLearn::SimpleDB< KeyType, QueryResult >::length(), PLearn::VMatrix::length_, PLearn::VMatrix::map_rs, PLearn::VMatrix::map_sr, PLearn::VMatrix::metadatadir, PLWARNING, row_, sdb_, PLearn::VMField::UnknownType, PLearn::SimpleDB< KeyType, QueryResult >::width(), and PLearn::VMatrix::width_.
:sdb_(extract_filename(dbname), extract_directory(dbname), SDB::readonly, true), string_field_map() { metadatadir = extract_directory(dbname) + extract_filename(dbname) + ".metadata"; if(!force_mkdir(metadatadir)) PLWARNING("In AutoSDBVMatrix constructor, could not create directory %s",metadatadir.c_str()); const Schema& sc = sdb_.getSchema(); //get string mappings from sdb metadatadir getMappings(); row_ = Row(&sc); Schema::const_iterator it = sc.begin(); Schema::const_iterator itend = sc.end(); width_= sdb_.width(); length_ = sdb_.length(); // resize the string mappings (TODO/WARNING : two string maping systems coexist (not so peacfully), next 2 line are from the newer system but // transition is uncompleted map_sr = TVec<map<string,real> >(width_); map_rs = TVec<map<real,string> >(width_); int i=0; for(it=sc.begin(); it!=itend; ++it) { if(it->field_type==DateType) declareField(i++, it->name, VMField::Date); else declareField(i++, it->name, VMField::UnknownType); } }
void PLearn::AutoSDBVMatrix::getMappings | ( | ) |
gets mappings for each string field
Definition at line 110 of file AutoSDBVMatrix.cc.
References PLearn::SimpleDB< KeyType, QueryResult >::getSchema(), PLearn::isfile(), PLearn::load(), PLearn::VMatrix::metadatadir, MISSING_VALUE, num2string_map, sdb_, string_field_map, and PLearn::StringType.
Referenced by AutoSDBVMatrix().
{ const Schema& sc = sdb_.getSchema(); for(Schema::const_iterator it= sc.begin(); it < sc.end(); ++it) if(it->field_type == StringType) { PPath field_filename = metadatadir / (it->name + ".strings"); real dft_val = MISSING_VALUE; // Get value for others, if file exists if( isfile(field_filename + ".others") ) PLearn::load(field_filename + ".others", dft_val); // Get mapping, if it exists string_field_map[it->name] = StringFieldMapping(field_filename, dft_val); num2string_map[it->name] = NumToStringMapping(field_filename); } }
This is the only method requiring implementation in subclasses.
Implements PLearn::RowBufferedVMatrix.
Definition at line 85 of file AutoSDBVMatrix.cc.
References PLearn::RowIterator::asCharacter(), PLearn::RowIterator::asString(), PLearn::Row::begin(), PLearn::SimpleDB< KeyType, QueryResult >::getInRow(), PLearn::RowIterator::isCharacter(), PLearn::RowIterator::isMissing(), PLearn::RowIterator::isString(), j, PLearn::TVec< T >::length(), MISSING_VALUE, PLearn::RowIterator::name(), PLERROR, row_, sdb_, string_field_map, PLearn::RowIterator::toDouble(), w, and PLearn::VMatrix::width().
{ sdb_.getInRow(i, row_); Row::const_iterator it = row_.begin(); int w = width(); if(w!=v.length()) PLERROR("In AutoSDBVMatrix::getNewRow length of v must be width of VMatrix"); int j=0; while(j<w) { if(it.isString()) v[j]= string_field_map.find(it.name())->second[it.asString()]; else if(it.isMissing()) v[j] = MISSING_VALUE; else if(it.isCharacter()) v[j] = (real)*(it.asCharacter()); else v[j] = (real)it.toDouble(); ++j; ++it; } }
returns the string associated with value val for field# col.
Or returns "" if no string is associated.
Reimplemented from PLearn::VMatrix.
Definition at line 170 of file AutoSDBVMatrix.h.
{ hash_map<string, NumToStringMapping>::const_iterator it= num2string_map.find(fieldName(col)); if(it != num2string_map.end()) return it->second[val]; return ""; }
int PLearn::AutoSDBVMatrix::nstrings | ( | ) | [inline] |
Returns the number of string fields (these will not be used in getRow!)
Definition at line 163 of file AutoSDBVMatrix.h.
hash_map<string, NumToStringMapping> PLearn::AutoSDBVMatrix::num2string_map [protected] |
Definition at line 186 of file AutoSDBVMatrix.h.
Referenced by getMappings().
Row PLearn::AutoSDBVMatrix::row_ [mutable, protected] |
Definition at line 184 of file AutoSDBVMatrix.h.
Referenced by AutoSDBVMatrix(), and getNewRow().
SDB PLearn::AutoSDBVMatrix::sdb_ [protected] |
Definition at line 183 of file AutoSDBVMatrix.h.
Referenced by AutoSDBVMatrix(), getMappings(), and getNewRow().
hash_map<string, StringFieldMapping> PLearn::AutoSDBVMatrix::string_field_map [protected] |
Definition at line 185 of file AutoSDBVMatrix.h.
Referenced by getMappings(), and getNewRow().