forked from HIT-SCIR/ltp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.h
92 lines (76 loc) · 1.91 KB
/
model.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef __MODEL_H__
#define __MODEL_H__
#include "featurespace.h"
#include "parameters.h"
#include "options.h"
namespace ltp {
namespace parser {
class Model {
public:
Model() :
_dim(-1),
_num_deprels(-1),
_num_postags(-1),
_num_features(-1) {}
~Model() {}
/*
* get the number of dependency relation types
*
* @return int the number of dependency relation type
*/
int num_deprels();
/*
* get the number of postag types
*
* @return int the number of postag type
*/
int num_postags();
/*
* get the number of features
*
* @return int the number of features
*/
int num_features();
/*
* get the number of dimension
*
* @return int the number of dimension
*/
int dim();
private:
int _num_deprels;
int _num_postags;
int _num_features;
int _dim;
public:
FeatureSpace space;
Parameters param;
IndexableSmartMap postags;
IndexableSmartMap deprels;
/*
* save the model to the output stream.
*
* @param out the output stream
*/
void save(ostream & out);
/*
* load the model from the input stream, return true on
* success, otherwise false
*
* @param in the input stream
* @return bool true on success, otherwise false
*/
bool load(istream & in);
private:
void write_uint(ostream & out, unsigned int val) {
out.write(reinterpret_cast<const char *>(&val), sizeof(unsigned int));
}
unsigned int read_uint(istream & in) {
char p[4];
in.read(reinterpret_cast<char*>(p), sizeof(unsigned int));
return *reinterpret_cast<const unsigned int*>(p);
}
}; // end for class model
} // end for namespace parser
} // end for namespace ltp
#endif // end for __MODEL_H__