SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
StreamingFileFromStringFeatures.h
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2011 Shashwat Lal Das
00008  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
00009  */
00010 #ifndef __STREAMING_FILEFROMSTRING_H__
00011 #define __STREAMING_FILEFROMSTRING_H__
00012 
00013 #include <shogun/io/streaming/StreamingFileFromFeatures.h>
00014 #include <shogun/features/StringFeatures.h>
00015 
00016 namespace shogun
00017 {
00022 template <class T> class CStreamingFileFromStringFeatures: public CStreamingFileFromFeatures
00023 {
00024 public:
00028     CStreamingFileFromStringFeatures();
00029 
00035     CStreamingFileFromStringFeatures(CStringFeatures<T>* feat);
00036 
00043     CStreamingFileFromStringFeatures(CStringFeatures<T>* feat, float64_t* lab);
00044 
00048     virtual ~CStreamingFileFromStringFeatures();
00049 
00058     virtual void get_string(T* &vec, int32_t &len);
00059 
00069     virtual void get_string_and_label(T* &vec, int32_t &len, float64_t &label);
00070 
00076     void reset_stream()
00077     {
00078         vector_num = 0;
00079     }
00080 
00082     virtual const char* get_name() const
00083     {
00084         return "StreamingFileFromStringFeatures";
00085 
00086     }
00087 
00088 private:
00092     void init(CStringFeatures<T>* feat=NULL);
00093 
00094 protected:
00095 
00097     CStringFeatures<T>* features;
00098 
00100     int32_t vector_num;
00101 
00102 };
00103 
00104 template <class T>
00105 CStreamingFileFromStringFeatures<T>::CStreamingFileFromStringFeatures()
00106     : CStreamingFileFromFeatures()
00107 {
00108     init();
00109 }
00110 
00111 template <class T>
00112 CStreamingFileFromStringFeatures<T>::CStreamingFileFromStringFeatures(CStringFeatures<T>* feat)
00113     : CStreamingFileFromFeatures(feat)
00114 {
00115     init(feat);
00116 }
00117 
00118 template <class T>
00119 CStreamingFileFromStringFeatures<T>::CStreamingFileFromStringFeatures(CStringFeatures<T>* feat, float64_t* lab)
00120     : CStreamingFileFromFeatures(feat,lab)
00121 {
00122     init(feat);
00123 }
00124 
00125 template <class T>
00126 CStreamingFileFromStringFeatures<T>::~CStreamingFileFromStringFeatures()
00127 {
00128 }
00129 
00130 template <class T>
00131 void CStreamingFileFromStringFeatures<T>::init(CStringFeatures<T>* feat)
00132 {
00133     vector_num=0;
00134     features = feat;
00135 
00136     set_generic<T>();
00137 }
00138 
00139 /* Functions to return the vector from the StringFeatures object */
00140 template <class T>
00141 void CStreamingFileFromStringFeatures<T>::get_string(T*& vector, int32_t& num_feat)
00142 {
00143     if (vector_num >= features->get_num_vectors())
00144     {
00145         vector=NULL;
00146         num_feat=-1;
00147         return;
00148     }
00149 
00150     SGVector<T> sg_vector=
00151         features->get_feature_vector(vector_num);
00152 
00153     vector = sg_vector.vector;
00154     num_feat = sg_vector.vlen;
00155     sg_vector.vector = NULL;
00156     sg_vector.vlen = -1;
00157     vector_num++;
00158 }
00159 
00160 /* Functions to return the vector from the StringFeatures object with label */
00161 template <class T>
00162 void CStreamingFileFromStringFeatures<T>::get_string_and_label
00163 (T*& vector, int32_t& num_feat, float64_t& label)
00164 {
00165     if (vector_num >= features->get_num_vectors())
00166     {
00167         vector=NULL;
00168         num_feat=-1;
00169         return;
00170     }
00171 
00172     SGVector<T> sg_vector
00173         =features->get_feature_vector(vector_num);
00174 
00175     vector = sg_vector.vector;
00176     num_feat = sg_vector.vlen;
00177     label = labels[vector_num];
00178 
00179     vector_num++;
00180 }
00181 
00182 
00183 }
00184 #endif //__STREAMING_FILEFROMSTRING_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation