SortWordString.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) 1999-2008 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
00010  */
00011 
00012 #include "preproc/SortWordString.h"
00013 #include "features/Features.h"
00014 #include "features/StringFeatures.h"
00015 #include "lib/Mathematics.h"
00016 
00017 CSortWordString::CSortWordString()
00018 : CStringPreProc<WORD>("SortWordString", "STWS") 
00019 {
00020 }
00021 
00022 CSortWordString::~CSortWordString()
00023 {
00024 }
00025 
00027 bool CSortWordString::init(CFeatures* f)
00028 {
00029     ASSERT(f->get_feature_class()==C_STRING);
00030     ASSERT(f->get_feature_type()==F_WORD);
00031 
00032     return true;
00033 }
00034 
00036 void CSortWordString::cleanup()
00037 {
00038 }
00039 
00041 bool CSortWordString::load(FILE* f)
00042 {
00043     return false;
00044 }
00045 
00047 bool CSortWordString::save(FILE* f)
00048 {
00049     return false;
00050 }
00051 
00055 bool CSortWordString::apply_to_string_features(CFeatures* f)
00056 {
00057     INT i;
00058     INT num_vec=((CStringFeatures<WORD>*)f)->get_num_vectors() ;
00059     
00060     for (i=0; i<num_vec; i++)
00061     {
00062         INT len = 0 ;
00063         WORD* vec = ((CStringFeatures<WORD>*)f)->get_feature_vector(i, len) ;
00064         
00065         //CMath::qsort(vec, len);
00066         CMath::radix_sort(vec, len);
00067     }
00068     return true ;
00069 }
00070 
00072 WORD* CSortWordString::apply_to_string(WORD* f, INT& len)
00073 {
00074     WORD* vec=new WORD[len];
00075     INT i=0;
00076 
00077     for (i=0; i<len; i++)
00078         vec[i]=f[i];
00079 
00080     //CMath::qsort(vec, len);
00081     CMath::radix_sort(vec, len);
00082 
00083     return vec;
00084 }
00085 
00087 bool CSortWordString::load_init_data(FILE* src)
00088 {
00089     return true;
00090 }
00091 
00093 bool CSortWordString::save_init_data(FILE* dst)
00094 {
00095     return true;
00096 }

SHOGUN Machine Learning Toolbox - Documentation