Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

svm_problem* Impala::Persistency::SvmProblemRepositoryInFile::Read ( File  file  )  [inline, private]

Definition at line 81 of file SvmProblemRepositoryInFile.h.

References Impala::Util::IOBuffer::Available(), Impala::Persistency::File::GetPath(), Impala::Persistency::File::GetReadBuffer(), ILOG_ERROR, Impala::Util::IOBuffer::ReadLine(), and Impala::Util::IOBuffer::SetPosition().

Referenced by Get().

00082     {
00083         const double cInvalid = 666;
00084         Util::IOBuffer* buf = file.GetReadBuffer();
00085         if (!buf)
00086             return 0;
00087 
00088         int sample = 0;
00089         int nrNodes = 0;
00090         while (buf->Available() > 0)
00091         {
00092             std::istringstream iss(buf->ReadLine());
00093             double label = cInvalid;
00094             iss >> label;
00095             if (label == cInvalid) // no label: empty line at the end of the file
00096                 break;
00097             sample++;
00098             while(!iss.eof())
00099             {
00100                 int index;
00101                 double value;
00102                 char c = 0;
00103                 iss >> index >> c >> value; // c should be ':'
00104                 if (c != ':')
00105                 {
00106                     ILOG_ERROR("Read: parse error in svm file "
00107                                << file.GetPath() << " on line " << sample);
00108                     delete buf;
00109                     return 0;
00110                 }
00111                 nrNodes++;
00112             }
00113             nrNodes++; // extra node with index == -1
00114         }
00115         buf->SetPosition(0);
00116 
00117         // seccond pass:
00118         svm_problem* p = new svm_problem;
00119         p->l = sample;
00120         p->y = new double[sample];
00121         p->x = new svm_node*[sample];
00122         svm_node* nodes = new svm_node[nrNodes];
00123         svm_node* dst = nodes;
00124         for (int i=0 ; i<sample ; i++)
00125         {
00126             std::istringstream iss(buf->ReadLine());
00127             iss >> p->y[i];
00128             p->x[i] = dst;
00129             while (!iss.eof())
00130             {
00131                 char c;
00132                 iss >> dst->index >> c >> dst->value;
00133                 dst++;
00134             }
00135             dst->index = -1;
00136             dst++;
00137         }
00138         delete buf;
00139         return p;
00140     }

Here is the call graph for this function:


Generated on Thu Jan 13 09:23:49 2011 for ImpalaSrc by  doxygen 1.5.1