-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
StringPreprocessor.cpp
134 lines (111 loc) · 2.9 KB
/
StringPreprocessor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Authors: Wuwei Lin
*/
#include <shogun/preprocessor/StringPreprocessor.h>
namespace shogun
{
template <>
inline EFeatureType CStringPreprocessor<uint64_t>::get_feature_type()
{
return F_ULONG;
}
template <>
inline EFeatureType CStringPreprocessor<int64_t>::get_feature_type()
{
return F_LONG;
}
template <>
inline EFeatureType CStringPreprocessor<uint32_t>::get_feature_type()
{
return F_UINT;
}
template <>
inline EFeatureType CStringPreprocessor<int32_t>::get_feature_type()
{
return F_INT;
}
template <>
inline EFeatureType CStringPreprocessor<uint16_t>::get_feature_type()
{
return F_WORD;
}
template <>
inline EFeatureType CStringPreprocessor<int16_t>::get_feature_type()
{
return F_WORD;
}
template <>
inline EFeatureType CStringPreprocessor<uint8_t>::get_feature_type()
{
return F_BYTE;
}
template <>
inline EFeatureType CStringPreprocessor<int8_t>::get_feature_type()
{
return F_BYTE;
}
template <>
inline EFeatureType CStringPreprocessor<char>::get_feature_type()
{
return F_CHAR;
}
template <>
inline EFeatureType CStringPreprocessor<bool>::get_feature_type()
{
return F_BOOL;
}
template <>
inline EFeatureType CStringPreprocessor<float32_t>::get_feature_type()
{
return F_SHORTREAL;
}
template <>
inline EFeatureType CStringPreprocessor<float64_t>::get_feature_type()
{
return F_DREAL;
}
template <>
inline EFeatureType CStringPreprocessor<floatmax_t>::get_feature_type()
{
return F_LONGREAL;
}
template <class ST>
CFeatures* CStringPreprocessor<ST>::apply(CFeatures* features, bool inplace)
{
REQUIRE(
features->get_feature_class() == C_STRING,
"Provided features (%d) "
"has to be of C_STRING (%d) class!\n",
features->get_feature_class(), C_STRING);
auto string_features = features->as<CStringFeatures<ST>>();
auto string_list = string_features->get_features();
if (!inplace)
string_list = string_list.clone();
apply_to_string_list(string_list);
auto processed = new CStringFeatures<ST>(
string_list, string_features->get_alphabet());
SG_REF(processed);
return processed;
}
template <class ST>
bool CStringPreprocessor<ST>::apply_to_string_features(CFeatures* features)
{
apply(features);
return true;
}
template class CStringPreprocessor<bool>;
template class CStringPreprocessor<char>;
template class CStringPreprocessor<int8_t>;
template class CStringPreprocessor<uint8_t>;
template class CStringPreprocessor<int16_t>;
template class CStringPreprocessor<uint16_t>;
template class CStringPreprocessor<int32_t>;
template class CStringPreprocessor<uint32_t>;
template class CStringPreprocessor<int64_t>;
template class CStringPreprocessor<uint64_t>;
template class CStringPreprocessor<float32_t>;
template class CStringPreprocessor<float64_t>;
template class CStringPreprocessor<floatmax_t>;
}