-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
StringPreprocessor.h
76 lines (63 loc) · 2.26 KB
/
StringPreprocessor.h
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
/*
* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Authors: Soeren Sonnenburg, Soumyajit De, Yuyu Zhang, Sergey Lisitsyn
*/
#ifndef _CSTRINGPREPROC__H__
#define _CSTRINGPREPROC__H__
#include <shogun/lib/config.h>
#include <shogun/features/Features.h>
#include <shogun/features/StringFeatures.h>
#include <shogun/lib/SGStringList.h>
#include <shogun/lib/common.h>
#include <shogun/preprocessor/Preprocessor.h>
namespace shogun
{
template <class ST> class CStringFeatures;
/** @brief Template class StringPreprocessor, base class for preprocessors (cf.
* CPreprocessor) that apply to CStringFeatures (i.e. strings of variable length).
*
* Two new functions apply_to_string() and apply_to_string_features()
* are defined in this interface that need to be implemented in each particular
* preprocessor operating on CStringFeatures.
*/
template <class ST> class CStringPreprocessor : public CPreprocessor
{
public:
/** constructor
*/
CStringPreprocessor() : CPreprocessor() {}
/** generic interface for applying the preprocessor. used as a wrapper
* for apply_to_string_features() method
*
* @param features the string input features
* @return the result feature object after applying the preprocessor
*/
virtual CFeatures* apply(CFeatures* features, bool inplace = true);
/// apply preproc on feature matrix
/// result in feature matrix
/// return pointer to feature_matrix, i.e. f->get_feature_matrix();
#ifndef SWIG
[[deprecated]]
#endif
virtual bool
apply_to_string_features(CFeatures* f);
/// apply preproc on single feature vector
virtual ST* apply_to_string(ST* f, int32_t &len)=0;
/// return that we are string features (just fixed size matrices)
virtual EFeatureClass get_feature_class() { return C_STRING; }
/// return feature type
virtual EFeatureType get_feature_type();
/// return the name of the preprocessor
virtual const char* get_name() const { return "UNKNOWN"; }
/// return a type of preprocessor
virtual EPreprocessorType get_type() const { return P_UNKNOWN; }
protected:
/** apply the preprocessor to string list in place.
*
* @param string_list the string list to be preprocessed
*/
virtual void apply_to_string_list(SGStringList<ST> string_list) = 0;
};
}
#endif