-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodel.h
More file actions
47 lines (39 loc) · 1022 Bytes
/
model.h
File metadata and controls
47 lines (39 loc) · 1022 Bytes
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
#ifndef _MODEL_H_
#define _MODEL_H_
#include "prob.h"
#include <stdio.h>
#include <vector>
#include <utility>
using namespace std;
class Model{
public:
vector< pair< int, prob > > para;
#define Word first
#define Prob second
bool loaded;
Model(){ loaded = false; }
Model( const char* filename ){
loaded = load( filename );
}
inline bool isLoad(){ return loaded; }
inline bool load( const char* filename ){
FILE* fin = fopen( filename , "r" );
if( !fin ) return loaded = false;
para.clear();
int _hsh;
double _vl;
while( fscanf( fin , "%d%lf" , &_hsh , &_vl ) == 2 )
para.push_back( make_pair( _hsh , prob( _vl ) ) );
fclose( fin );
return loaded = true;
}
inline bool write( const char* filename ){
FILE* fout = fopen( filename , "w" );
if( !fout ) return false;
for( size_t i = 0 ; i < para.size() ; i ++ )
fprintf( fout , "%d %.6f\n" , para[ i ].Word , para[ i ].Prob.value() );
fclose( fout );
return true;
}
};
#endif