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

SHOGUN Machine Learning Toolbox - Documentation