modify some function name and structs's contruct fucntion

This commit is contained in:
gwdwyy 2013-09-08 22:20:18 +08:00
parent 5f48e7b437
commit 789ea7c1da
2 changed files with 23 additions and 30 deletions

View File

@ -23,14 +23,13 @@ bool init(const char * const dictPath, const char * const modelPath)
return true;
}
void run(const char * const filePath)
void cut(const char * const filePath)
{
ifstream ifile(filePath);
vector<string> res;
string line;
while(getline(ifile, line))
{
res.clear();
if(!line.empty())
{
seg.cutDAG(line, res);
@ -39,14 +38,13 @@ void run(const char * const filePath)
}
}
void hmmrun(const char * const filePath)
void cutHMM(const char * const filePath)
{
ifstream ifile(filePath);
vector<string> res;
string line;
while(getline(ifile, line))
{
res.clear();
if(!line.empty())
{
hmmseg.cut(line, res);
@ -55,6 +53,17 @@ void hmmrun(const char * const filePath)
}
}
void cutAll(const char* const filePath)
{
ifstream ifs(filePath);
vector<TrieNodeInfo> res;
string line;
while(getline(ifs, line))
{
seg.cutDAG(line, res);
}
}
bool dispose()
{
if(!seg.dispose())
@ -120,11 +129,11 @@ int main(int argc, char ** argv)
}
if("cutHMM" == algorithm)
{
hmmrun(arg[1].c_str());
cutHMM(arg[1].c_str());
}
else
{
run(arg[1].c_str());
cut(arg[1].c_str());
}
dispose();
return 0;

View File

@ -15,28 +15,23 @@ namespace CppJieba
size_t freq;
string tag;
double logFreq; //logFreq = log(freq/sum(freq));
TrieNodeInfo()
TrieNodeInfo():wLen(0),freq(0),logFreq(0.0)
{
wLen = 0;
freq = 0;
logFreq = 0.0;
}
TrieNodeInfo(const string& _word)
TrieNodeInfo(const TrieNodeInfo& nodeInfo):word(nodeInfo.word), wLen(nodeInfo.wLen), freq(nodeInfo.freq), tag(nodeInfo.tag), logFreq(nodeInfo.logFreq)
{
}
TrieNodeInfo(const string& _word):word(_word),freq(0),logFreq(MIN_DOUBLE)
{
word = _word;
wLen = TransCode::getWordLength(_word);
freq = 0;
logFreq = MIN_DOUBLE;
}
};
struct SegmentContext//: public TrieNodeInfo
{
vector<uint16_t> uintVec;
vector< vector<pair<uint, const TrieNodeInfo*> > > dag;
vector< pair<const TrieNodeInfo*, double> > dp;
//vector<string> words;
};
/*
@ -50,25 +45,14 @@ namespace CppJieba
{
double idf;
double weight;// log(wLen+1)*logFreq;
KeyWordInfo()
KeyWordInfo():idf(0.0),weight(0.0)
{
idf = 0.0;
weight = 0.0;
}
KeyWordInfo(const string& _word):TrieNodeInfo(_word)
KeyWordInfo(const string& _word):TrieNodeInfo(_word),idf(0.0),weight(0.0)
{
idf = 0.0;
weight = 0.0;
}
KeyWordInfo(const TrieNodeInfo& trieNodeInfo)
KeyWordInfo(const TrieNodeInfo& trieNodeInfo):TrieNodeInfo(trieNodeInfo)
{
word = trieNodeInfo.word;
freq = trieNodeInfo.freq;
wLen = trieNodeInfo.wLen;
tag = trieNodeInfo.tag;
logFreq = trieNodeInfo.logFreq;
idf = 0.0;
weight = 0.0;
}
string toString() const
{