SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
preprocessor
SortWordString.cpp
浏览该文件的文档.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* Written (W) 1999-2009 Soeren Sonnenburg
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#include <
shogun/preprocessor/SortWordString.h
>
12
#include <
shogun/features/Features.h
>
13
#include <
shogun/features/StringFeatures.h
>
14
#include <
shogun/mathematics/Math.h
>
15
16
using namespace
shogun;
17
18
CSortWordString::CSortWordString
()
19
:
CStringPreprocessor
<uint16_t>()
20
{
21
}
22
23
CSortWordString::~CSortWordString
()
24
{
25
}
26
28
bool
CSortWordString::init(
CFeatures
* f)
29
{
30
ASSERT
(f->
get_feature_class
()==
C_STRING
)
31
ASSERT
(f->
get_feature_type
()==
F_WORD
)
32
33
return
true
;
34
}
35
37
void
CSortWordString::cleanup
()
38
{
39
}
40
42
bool
CSortWordString::load
(FILE* f)
43
{
44
SG_SET_LOCALE_C
;
45
SG_RESET_LOCALE
;
46
return
false
;
47
}
48
50
bool
CSortWordString::save
(FILE* f)
51
{
52
SG_SET_LOCALE_C
;
53
SG_RESET_LOCALE
;
54
return
false
;
55
}
56
60
bool
CSortWordString::apply_to_string_features
(
CFeatures
* f)
61
{
62
int32_t i;
63
int32_t num_vec=((
CStringFeatures<uint16_t>
*)f)->get_num_vectors() ;
64
65
for
(i=0; i<num_vec; i++)
66
{
67
int32_t len = 0 ;
68
bool
free_vec;
69
uint16_t* vec = ((
CStringFeatures<uint16_t>
*)f)->get_feature_vector(i, len, free_vec);
70
ASSERT
(!free_vec)
// won't work with non-in-memory string features
71
72
//CMath::qsort(vec, len);
73
CMath::radix_sort
(vec, len);
74
75
}
76
return
true ;
77
}
78
80
uint16_t*
CSortWordString::apply_to_string
(uint16_t* f, int32_t& len)
81
{
82
uint16_t* vec=SG_MALLOC(uint16_t, len);
83
int32_t i=0;
84
85
for
(i=0; i<len; i++)
86
vec[i]=f[i];
87
88
//CMath::qsort(vec, len);
89
CMath::radix_sort
(vec, len);
90
91
return
vec;
92
}
SHOGUN
机器学习工具包 - 项目文档