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 <shogun/preprocessor/SortWordString.h> 00012 #include <shogun/features/Features.h> 00013 #include <shogun/features/StringFeatures.h> 00014 #include <shogun/mathematics/Math.h> 00015 00016 using namespace shogun; 00017 00018 CSortWordString::CSortWordString() 00019 : CStringPreprocessor<uint16_t>() 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 SG_SET_LOCALE_C; 00045 SG_RESET_LOCALE; 00046 return false; 00047 } 00048 00050 bool CSortWordString::save(FILE* f) 00051 { 00052 SG_SET_LOCALE_C; 00053 SG_RESET_LOCALE; 00054 return false; 00055 } 00056 00060 bool CSortWordString::apply_to_string_features(CFeatures* f) 00061 { 00062 int32_t i; 00063 int32_t num_vec=((CStringFeatures<uint16_t>*)f)->get_num_vectors() ; 00064 00065 for (i=0; i<num_vec; i++) 00066 { 00067 int32_t len = 0 ; 00068 bool free_vec; 00069 uint16_t* vec = ((CStringFeatures<uint16_t>*)f)->get_feature_vector(i, len, free_vec); 00070 ASSERT(!free_vec); // won't work with non-in-memory string features 00071 00072 //CMath::qsort(vec, len); 00073 CMath::radix_sort(vec, len); 00074 00075 } 00076 return true ; 00077 } 00078 00080 uint16_t* CSortWordString::apply_to_string(uint16_t* f, int32_t& len) 00081 { 00082 uint16_t* vec=SG_MALLOC(uint16_t, len); 00083 int32_t i=0; 00084 00085 for (i=0; i<len; i++) 00086 vec[i]=f[i]; 00087 00088 //CMath::qsort(vec, len); 00089 CMath::radix_sort(vec, len); 00090 00091 return vec; 00092 }