Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _CDECOMPRESS_STRING__H__
00012 #define _CDECOMPRESS_STRING__H__
00013
00014 #include "features/Features.h"
00015 #include "features/StringFeatures.h"
00016 #include "lib/common.h"
00017 #include "lib/Compressor.h"
00018 #include "preproc/StringPreProc.h"
00019
00020 namespace shogun
00021 {
00022 template <class ST> class CStringFeatures;
00023 class CCompressor;
00024 enum E_COMPRESSION_TYPE;
00025
00036 template <class ST> class CDecompressString : public CStringPreProc<ST>
00037 {
00038 public:
00040 CDecompressString(void)
00041 : CStringPreProc<ST>("DecompressString", "DECS")
00042 {
00043 compressor=NULL;
00044 }
00045
00048 CDecompressString(E_COMPRESSION_TYPE ct)
00049 : CStringPreProc<ST>("DecompressString", "DECS")
00050 {
00051 compressor=new CCompressor(ct);
00052 }
00053
00055 virtual ~CDecompressString()
00056 {
00057 delete compressor;
00058 }
00059
00061 virtual bool init(CFeatures* f)
00062 {
00063 ASSERT(f->get_feature_class()==C_STRING);
00064 return true;
00065 }
00066
00068 virtual void cleanup()
00069 {
00070 }
00071
00073 bool load(FILE* f)
00074 {
00075 SG_SET_LOCALE_C;
00076 SG_RESET_LOCALE;
00077 return false;
00078 }
00079
00081 bool save(FILE* f)
00082 {
00083 SG_SET_LOCALE_C;
00084 SG_RESET_LOCALE;
00085 return false;
00086 }
00087
00091 virtual bool apply_to_string_features(CFeatures* f)
00092 {
00093 int32_t i;
00094 int32_t num_vec=((CStringFeatures<ST>*)f)->get_num_vectors();
00095
00096 for (i=0; i<num_vec; i++)
00097 {
00098 int32_t len=0;
00099 bool free_vec;
00100 ST* vec=((CStringFeatures<ST>*)f)->
00101 get_feature_vector(i, len, free_vec);
00102
00103 ST* decompressed=apply_to_string(vec, len);
00104 ((CStringFeatures<ST>*)f)->
00105 free_feature_vector(vec, i, free_vec);
00106 ((CStringFeatures<ST>*)f)->
00107 cleanup_feature_vector(i);
00108 ((CStringFeatures<ST>*)f)->
00109 set_feature_vector(i, decompressed, len);
00110 }
00111 return true;
00112 }
00113
00115 virtual ST* apply_to_string(ST* f, int32_t &len)
00116 {
00117 uint64_t compressed_size=((int32_t*) f)[0];
00118 uint64_t uncompressed_size=((int32_t*) f)[1];
00119
00120 int32_t offs=CMath::ceil(2.0*sizeof(int32_t)/sizeof(ST));
00121 ASSERT(uint64_t(len)==uint64_t(offs)+compressed_size);
00122
00123 len=uncompressed_size;
00124 uncompressed_size*=sizeof(ST);
00125 ST* vec=new ST[len];
00126 compressor->decompress((uint8_t*) (&f[offs]), compressed_size,
00127 (uint8_t*) vec, uncompressed_size);
00128
00129 ASSERT(uncompressed_size==((uint64_t) len)*sizeof(ST));
00130 return vec;
00131 }
00132
00133 protected:
00135 CCompressor* compressor;
00136 };
00137 }
00138 #endif