-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol.cpp
87 lines (81 loc) · 2.56 KB
/
symbol.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
#include "symbol.h"
namespace seg{
Symbol::Symbol(){}
Symbol::~Symbol(){}
void Symbol::Init(const char* path){
std::string namepath = std::string(path) + "name";
std::string connectpath = std::string(path) + "connet";
LoadName(namepath.c_str());
LoadConnet(connectpath.c_str());
LoadNameFre (path);
}
bool Symbol::LoadNameFre (const char * namedir) {
if (NULL == namedir){
commom::LOG_INFO("load namefre error");
return false;
}
std::string pathfirst = std::string(namedir) + "Chinese.name";
std::string pathsecond = std::string(namedir) + "Chinese.secondname";
FILE *pf = fopen(pathfirst.c_str(),"r");
if (pf == NULL){
commom::LOG_INFO("load namefre error");
return false;
}
char buffer[SHORT_LENTH];
memset( buffer,0,SHORT_LENTH );
std::vector<std::string> temp;
while ( commom::ReadLine(buffer,SHORT_LENTH,pf)!=NULL) {
std::string str = commom::GetLine(buffer);
commom::Split(" ", str, temp);
if (temp.size() <= 2) {
namefre.insert(std::pair<std::string,unsigned int>(temp[0],atoi(temp[1].c_str())));
}
}
fclose(pf);
memset( buffer,0,SHORT_LENTH );
pf = fopen(pathsecond.c_str(),"r");
if (pf == NULL){
commom::LOG_INFO("load namefre error");
return false;
}
while ( commom::ReadLine(buffer,SHORT_LENTH,pf)!=NULL) {
std::string str = commom::GetLine(buffer);
commom::Split(" ", str, temp);
if (temp.size() <= 2) {
secondnamefir.insert(std::pair<std::string,unsigned int>(temp[0],atoi(temp[1].c_str())));
}
}
return true;
}
bool Symbol::LoadConnet(const char * connetpath){
FILE *pf = fopen(connetpath,"r");
char buffer[MAX_LENTH];
memset( buffer,0,MAX_LENTH );
std::string chinaname="";
while ( commom::ReadLine(buffer,MAX_LENTH,pf)!=NULL) {
chinaname = commom::GetLine(buffer); break;
}
return commom::StrToVec(chinaname.c_str(), m_connet);
}
/*检查是否为连接符*/
bool Symbol::CheckConnet(uint16_t x){
std::vector<uint16_t>::iterator it = find(m_connet.begin(),m_connet.end(),x);
return ( it != m_connet.end());
}
/*加载姓氏*/
bool Symbol::LoadName(const char * namepath){
FILE *pf = fopen(namepath,"r");
char buffer[MAX_LENTH];
memset( buffer,0,MAX_LENTH );
std::string chinaname="";
while ( commom::ReadLine(buffer,MAX_LENTH,pf)!=NULL) {
chinaname = commom::GetLine(buffer); break;
}
return commom::StrToVec(chinaname.c_str(), m_name);
}
/*检查是否为姓氏*/
bool Symbol::CheckName(uint16_t x){
intvector::iterator nameresult = find( m_name.begin(),m_name.end(),x);
return (nameresult !=m_name.end());
}
}