SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StreamingFileFromStringFeatures.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011 Shashwat Lal Das
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
10 #ifndef __STREAMING_FILEFROMSTRING_H__
11 #define __STREAMING_FILEFROMSTRING_H__
12 
13 #include <shogun/lib/config.h>
14 
17 
18 namespace shogun
19 {
25 {
26 public:
31 
38 
46 
51 
60  virtual void get_string(T* &vec, int32_t &len);
61 
71  virtual void get_string_and_label(T* &vec, int32_t &len, float64_t &label);
72 
78  void reset_stream()
79  {
80  vector_num = 0;
81  }
82 
84  virtual const char* get_name() const
85  {
86  return "StreamingFileFromStringFeatures";
87 
88  }
89 
90 private:
94  void init(CStringFeatures<T>* feat=NULL);
95 
96 protected:
97 
100 
102  int32_t vector_num;
103 
104 };
105 
106 template <class T>
109 {
110  init();
111 }
112 
113 template <class T>
116 {
117  init(feat);
118 }
119 
120 template <class T>
122  : CStreamingFileFromFeatures(feat,lab)
123 {
124  init(feat);
125 }
126 
127 template <class T>
129 {
130 }
131 
132 template <class T>
134 {
135  vector_num=0;
136  features = feat;
137 
138  set_generic<T>();
139 }
140 
141 /* Functions to return the vector from the StringFeatures object */
142 template <class T>
143 void CStreamingFileFromStringFeatures<T>::get_string(T*& vector, int32_t& num_feat)
144 {
145  if (vector_num >= features->get_num_vectors())
146  {
147  vector=NULL;
148  num_feat=-1;
149  return;
150  }
151 
152  SGVector<T> sg_vector=
153  features->get_feature_vector(vector_num);
154 
155  vector = sg_vector.vector;
156  num_feat = sg_vector.vlen;
157  sg_vector.vector = NULL;
158  sg_vector.vlen = -1;
159  vector_num++;
160 }
161 
162 /* Functions to return the vector from the StringFeatures object with label */
163 template <class T>
165 (T*& vector, int32_t& num_feat, float64_t& label)
166 {
167  if (vector_num >= features->get_num_vectors())
168  {
169  vector=NULL;
170  num_feat=-1;
171  return;
172  }
173 
174  SGVector<T> sg_vector
175  =features->get_feature_vector(vector_num);
176 
177  vector = sg_vector.vector;
178  num_feat = sg_vector.vlen;
179  label = labels[vector_num];
180 
181  vector_num++;
182 }
183 
184 
185 }
186 #endif //__STREAMING_FILEFROMSTRING_H__

SHOGUN Machine Learning Toolbox - Documentation