PLearn 0.1
|
#include <SDBVMat.h>
Public Member Functions | |
SDBVMatrix (const string &dbname, bool detect_missing=false) | |
Currently, the constructor assumes that the SDB exists on-disk. | |
void | appendField (const string &name, SDBVMField *new_field) |
Use default dtor, copy ctor, op=. | |
const FieldsVector & | getFields () const |
Obtain a list of the added fields. | |
virtual void | getRow (int i, Vec v) const |
Transform row i of the SimpldDB into a row of the VMatrix. | |
SDBWithStats & | sdb () |
Access underlying sdb. | |
const SDBWithStats & | sdb () const |
Protected Attributes | |
SDBWithStats | sdb_ |
FieldsVector | fields_ |
Row | row_ |
bool | detect_missing_ |
Private Types | |
typedef RowBufferedVMatrix | inherited |
typedef vector< PSDBVMField > | FieldsVector |
This is a VMatrix that acts as a front-end to a SimpleDB (actually, an SDBWithStats). You can add as many fields derived from SDBVMField as required with the appendField function.
typedef vector<PSDBVMField> PLearn::SDBVMatrix::FieldsVector [private] |
typedef RowBufferedVMatrix PLearn::SDBVMatrix::inherited [private] |
Reimplemented from PLearn::RowBufferedVMatrix.
PLearn::SDBVMatrix::SDBVMatrix | ( | const string & | dbname, |
bool | detect_missing = false |
||
) |
Currently, the constructor assumes that the SDB exists on-disk.
Definition at line 216 of file SDBVMat.cc.
References PLearn::SDBWithStats::computeStats(), PLearn::SimpleDB< KeyType, QueryResult >::getSchema(), PLearn::SDBWithStats::hasStats(), PLearn::VMatrix::length_, PLearn::SDBWithStats::loadStats(), row_, PLearn::SDBWithStats::saveStats(), sdb_, PLearn::SimpleDB< KeyType, QueryResult >::size(), and PLearn::VMatrix::width_.
: sdb_(dbname, "", SDB::readonly), detect_missing_(detect_missing) { row_ = Row(&sdb_.getSchema()); length_ = sdb_.size(); width_ = 0; if (sdb_.hasStats()) sdb_.loadStats(); else { sdb_.computeStats(); sdb_.saveStats(); } }
void PLearn::SDBVMatrix::appendField | ( | const string & | name, |
SDBVMField * | new_field | ||
) |
Use default dtor, copy ctor, op=.
Add a new field to the VMatrix. The VMatrix assumes ownership of the field.
Definition at line 230 of file SDBVMat.cc.
References PLearn::RowBufferedVMatrix::current_row, PLearn::VMatrix::declareField(), fields_, PLearn::SDBVMField::fieldType(), PLearn::SDBVMField::fieldWidth(), i, PLearn::TVec< T >::resize(), PLearn::split(), and PLearn::VMatrix::width_.
{ int fieldwidth = new_field->fieldWidth(); vector<string> fieldnames = split(name); if(fieldwidth>1 && int(fieldnames.size())==fieldwidth) { for(unsigned int i=0; i<fieldnames.size(); i++) { width_++; declareField(width_-1,fieldnames[i],new_field->fieldType()); } } else { for(int k=0; k<fieldwidth; k++) { width_++; declareField(width_-1,name,new_field->fieldType()); } } fields_.push_back(PSDBVMField(new_field)); current_row.resize(width_); }
const FieldsVector& PLearn::SDBVMatrix::getFields | ( | ) | const [inline] |
Transform row i of the SimpldDB into a row of the VMatrix.
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 255 of file SDBVMat.cc.
References detect_missing_, fields_, PLearn::SimpleDB< KeyType, QueryResult >::getInRow(), PLearn::TVec< T >::hasMissing(), PLWARNING, row_, sdb_, and PLearn::TVec< T >::subVec().
{ //prof.start("getrow"); //prof.start("getrow1"); sdb_.getInRow(i, row_); //prof.end("getrow1"); FieldsVector::const_iterator it = fields_.begin(), end = fields_.end(); int curpos=0, curwidth; for (int f=0; it != end; ++it, curpos+=curwidth, f++) { curwidth = (*it)->fieldWidth(); Vec output = v.subVec(curpos,curwidth); //prof.start("getrow2"); (*it)->convertField(sdb_, row_, output); //prof.end("getrow2"); if (detect_missing_ && output.hasMissing()) PLWARNING("SDBVMatrix::getRow(%d,v) has missing value for %d-th field (columns %d-%d)", i,f,curpos,curpos+curwidth-1); } //prof.end("getrow"); }
SDBWithStats& PLearn::SDBVMatrix::sdb | ( | ) | [inline] |
const SDBWithStats& PLearn::SDBVMatrix::sdb | ( | ) | const [inline] |
bool PLearn::SDBVMatrix::detect_missing_ [protected] |
FieldsVector PLearn::SDBVMatrix::fields_ [protected] |
Definition at line 284 of file SDBVMat.h.
Referenced by appendField(), and getRow().
Row PLearn::SDBVMatrix::row_ [mutable, protected] |
Definition at line 285 of file SDBVMat.h.
Referenced by getRow(), and SDBVMatrix().
SDBWithStats PLearn::SDBVMatrix::sdb_ [protected] |
Definition at line 283 of file SDBVMat.h.
Referenced by getRow(), and SDBVMatrix().