StreamingVwFile.cpp

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 
00011 #include <shogun/io/StreamingVwFile.h>
00012 
00013 using namespace shogun;
00014 
00015 CStreamingVwFile::CStreamingVwFile()
00016     : CStreamingFile()
00017 {
00018     init();
00019 }
00020 
00021 CStreamingVwFile::CStreamingVwFile(char* fname, char rw)
00022     : CStreamingFile(fname, rw)
00023 {
00024     init();
00025 }
00026 
00027 CStreamingVwFile::~CStreamingVwFile()
00028 {
00029     SG_UNREF(env);
00030     SG_UNREF(parser);
00031 }
00032 
00033 void CStreamingVwFile::set_parser_type(E_VW_PARSER_TYPE type)
00034 {
00035     switch (type)
00036     {
00037     case T_VW:
00038         parse_example = &CVwParser::read_features;
00039         parser_type = T_VW;
00040         return;
00041     case T_SVMLIGHT:
00042         parse_example = &CVwParser::read_svmlight_features;
00043         parser_type = T_SVMLIGHT;
00044         return;
00045     case T_DENSE:
00046         parse_example = &CVwParser::read_dense_features;
00047         parser_type = T_DENSE;
00048         return;
00049     }
00050 
00051     SG_SERROR("Unrecognized parser type!\n");
00052 }
00053 
00054 void CStreamingVwFile::get_vector(VwExample* &ex, int32_t &len)
00055 {
00056     len = (parser->*parse_example)(buf, ex);
00057     if (len == 0)
00058         len = -1;   // indicates failure
00059 }
00060 
00061 void CStreamingVwFile::get_vector_and_label(VwExample* &ex, int32_t &len, float64_t &label)
00062 {
00063     len = (parser->*parse_example)(buf, ex);
00064     if (len == 0)
00065         len = -1;   // indicates failure
00066 }
00067 
00068 void CStreamingVwFile::init()
00069 {
00070     parser = new CVwParser();
00071     env = parser->get_env();
00072 
00073     set_parser_type(T_VW);
00074     write_to_cache = false;
00075     SG_REF(env);
00076 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation