mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
modify some function name and structs's contruct fucntion
This commit is contained in:
parent
5f48e7b437
commit
789ea7c1da
@ -23,14 +23,13 @@ bool init(const char * const dictPath, const char * const modelPath)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(const char * const filePath)
|
void cut(const char * const filePath)
|
||||||
{
|
{
|
||||||
ifstream ifile(filePath);
|
ifstream ifile(filePath);
|
||||||
vector<string> res;
|
vector<string> res;
|
||||||
string line;
|
string line;
|
||||||
while(getline(ifile, line))
|
while(getline(ifile, line))
|
||||||
{
|
{
|
||||||
res.clear();
|
|
||||||
if(!line.empty())
|
if(!line.empty())
|
||||||
{
|
{
|
||||||
seg.cutDAG(line, res);
|
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);
|
ifstream ifile(filePath);
|
||||||
vector<string> res;
|
vector<string> res;
|
||||||
string line;
|
string line;
|
||||||
while(getline(ifile, line))
|
while(getline(ifile, line))
|
||||||
{
|
{
|
||||||
res.clear();
|
|
||||||
if(!line.empty())
|
if(!line.empty())
|
||||||
{
|
{
|
||||||
hmmseg.cut(line, res);
|
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()
|
bool dispose()
|
||||||
{
|
{
|
||||||
if(!seg.dispose())
|
if(!seg.dispose())
|
||||||
@ -120,11 +129,11 @@ int main(int argc, char ** argv)
|
|||||||
}
|
}
|
||||||
if("cutHMM" == algorithm)
|
if("cutHMM" == algorithm)
|
||||||
{
|
{
|
||||||
hmmrun(arg[1].c_str());
|
cutHMM(arg[1].c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
run(arg[1].c_str());
|
cut(arg[1].c_str());
|
||||||
}
|
}
|
||||||
dispose();
|
dispose();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -15,28 +15,23 @@ namespace CppJieba
|
|||||||
size_t freq;
|
size_t freq;
|
||||||
string tag;
|
string tag;
|
||||||
double logFreq; //logFreq = log(freq/sum(freq));
|
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);
|
wLen = TransCode::getWordLength(_word);
|
||||||
freq = 0;
|
|
||||||
logFreq = MIN_DOUBLE;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct SegmentContext//: public TrieNodeInfo
|
struct SegmentContext//: public TrieNodeInfo
|
||||||
{
|
{
|
||||||
vector<uint16_t> uintVec;
|
vector<uint16_t> uintVec;
|
||||||
vector< vector<pair<uint, const TrieNodeInfo*> > > dag;
|
vector< vector<pair<uint, const TrieNodeInfo*> > > dag;
|
||||||
vector< pair<const TrieNodeInfo*, double> > dp;
|
vector< pair<const TrieNodeInfo*, double> > dp;
|
||||||
//vector<string> words;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -50,25 +45,14 @@ namespace CppJieba
|
|||||||
{
|
{
|
||||||
double idf;
|
double idf;
|
||||||
double weight;// log(wLen+1)*logFreq;
|
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
|
string toString() const
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user