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 using namespace shogun;
00017 
00018 CSortWordString::CSortWordString()
00019 : CStringPreProc<uint16_t>("SortWordString", "STWS") 
00020 {
00021 }
00022 
00023 CSortWordString::~CSortWordString()
00024 {
00025 }
00026 
00028 bool CSortWordString::init(CFeatures* f)
00029 {
00030     ASSERT(f->get_feature_class()==C_STRING);
00031     ASSERT(f->get_feature_type()==F_WORD);
00032 
00033     return true;
00034 }
00035 
00037 void CSortWordString::cleanup()
00038 {
00039 }
00040 
00042 bool CSortWordString::load(FILE* f)
00043 {
00044     return false;
00045 }
00046 
00048 bool CSortWordString::save(FILE* f)
00049 {
00050     return false;
00051 }
00052 
00056 bool CSortWordString::apply_to_string_features(CFeatures* f)
00057 {
00058     int32_t i;
00059     int32_t num_vec=((CStringFeatures<uint16_t>*)f)->get_num_vectors() ;
00060     
00061     for (i=0; i<num_vec; i++)
00062     {
00063         int32_t len = 0 ;
00064         bool free_vec;
00065         uint16_t* vec = ((CStringFeatures<uint16_t>*)f)->get_feature_vector(i, len, free_vec);
00066         ASSERT(!free_vec); // won't work with non-in-memory string features
00067         
00068         //CMath::qsort(vec, len);
00069         CMath::radix_sort(vec, len);
00070 
00071     }
00072     return true ;
00073 }
00074 
00076 uint16_t* CSortWordString::apply_to_string(uint16_t* f, int32_t& len)
00077 {
00078     uint16_t* vec=new uint16_t[len];
00079     int32_t i=0;
00080 
00081     for (i=0; i<len; i++)
00082         vec[i]=f[i];
00083 
00084     //CMath::qsort(vec, len);
00085     CMath::radix_sort(vec, len);
00086 
00087     return vec;
00088 }

SHOGUN Machine Learning Toolbox - Documentation