StreamingVwFile.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_VWFILE_H__
00011 #define __STREAMING_VWFILE_H__
00012 
00013 #include <shogun/io/streaming/StreamingFile.h>
00014 #include <shogun/classifier/vw/vw_common.h>
00015 #include <shogun/classifier/vw/VwParser.h>
00016 
00017 namespace shogun
00018 {
00020 typedef int32_t (CVwParser::*parse_func)(CIOBuffer*, VwExample*&);
00021 
00026 class CStreamingVwFile: public CStreamingFile
00027 {
00028 public:
00033     CStreamingVwFile();
00034 
00041     CStreamingVwFile(const char* fname, char rw='r');
00042 
00046     virtual ~CStreamingVwFile();
00047 
00054     void set_parser_type(E_VW_PARSER_TYPE type = T_VW);
00055 
00066     virtual void get_vector(VwExample* &ex, int32_t &len);
00067 
00077     virtual void get_vector_and_label(VwExample* &ex, int32_t &len, float64_t &label);
00078 
00084     void set_env(CVwEnvironment* env_to_use)
00085     {
00086         parser->set_env(env_to_use);
00087     }
00088 
00094     CVwEnvironment* get_env()
00095     {
00096         SG_REF(env);
00097         return env;
00098     }
00099 
00105     void set_write_to_cache(bool write_cache)
00106     {
00107         write_to_cache = write_cache;
00108         parser->set_write_cache(write_cache);
00109     }
00110 
00116     bool get_write_to_cache() { return write_to_cache; }
00117 
00118     virtual bool is_seekable() { return false; }
00119 
00121     virtual const char* get_name() const
00122     {
00123         return "StreamingVwFile";
00124     }
00125 
00126 public:
00128     parse_func parse_example;
00129 
00130 private:
00134     virtual void init();
00135 
00136 protected:
00138     CVwParser* parser;
00139 
00141     E_VW_PARSER_TYPE parser_type;
00142 
00144     CVwEnvironment* env;
00145 
00147     bool write_to_cache;
00148 };
00149 }
00150 #endif //__STREAMING_VWFILE_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation