?? dict.cpp
字號:
#include "Dict.h"
#include <string.h>
Dict::Dict()
{
OpenDict();
}
Dict::~Dict()
{
dictMap.clear();
}
void Dict::OpenDict()
{
FILE *fpDict;
lexicon *hit_lexicon = new lexicon;
//讀二進制詞典到內存中
if((fpDict = fopen(DICTFILENAME, "rb")) == NULL)
{
printf("Can not open the Dictionary file!");
exit(1);
}
fread(hit_lexicon,sizeof(lexicon),1,fpDict);
int id, freq;
char word[MAX_WORD_LEN];
for(int i=0; i<HEAD_LEN; ++i)
{
id = hit_lexicon->lexicon_head[i].word_id;
strcpy(word,hit_lexicon->lexicon_head[i].chinese_str);
freq = hit_lexicon->lexicon_head[i].freq;
dictMap.insert(map<string,int>::value_type(word,id));
}
fclose(fpDict);
}
bool Dict::IsWord(string& str) const
{
if(dictMap.find(str) != dictMap.end())
return true;
return false;
}
int Dict::get_id(string &str)
{
return dictMap[str];
}
/*
void Dict::AddFreq(string &str)
{
//更新詞頻
//find word_id:dictMap[str]
++word_freq[dictMap[str]];
}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -