ci for insertTrie 2 or 3 column

This commit is contained in:
gwdwyy 2013-08-16 20:21:12 +08:00
parent 2e85c1c833
commit da294a04f8
4 changed files with 17 additions and 24 deletions

2
.gitignore vendored
View File

@ -6,4 +6,4 @@ tags
*.ut
log
main
cmlib.a
lib*.a

View File

@ -9,8 +9,8 @@ int main(int argc, char ** argv)
{
if(argc < 2)
{
cerr<<"usage: "<<argv[0]<<" filename"<<endl;
return 1;
cout<<"usage: "<<argv[0]<<" <filename>"<<endl;
return -1;
}
Segment seg;
if(!seg.init())

View File

@ -77,10 +77,10 @@ namespace CppJieba
return false;
}
bool res = false;
res = _buildTree(filePath);
res = _trieInsert(filePath);
if(!res)
{
LogError("_buildTree failed.");
LogError("_trieInsert failed.");
return false;
}
res = _countWeight();
@ -92,40 +92,35 @@ namespace CppJieba
return true;
}
bool Trie::_buildTree(const char * const filePath)
bool Trie::_trieInsert(const char * const filePath)
{
ifstream ifile(filePath);
string line;
vector<string> vecBuf;
TrieNodeInfo nodeInfo;
while(getline(ifile, line))
{
vecBuf.clear();
splitStr(line, vecBuf, " ");
if(3 != vecBuf.size())
if(3 < vecBuf.size())
{
LogError(string_format("line[%s] illegal.", line.c_str()));
return false;
}
string chWord = vecBuf[0];
uint count = atoi(vecBuf[1].c_str());
const string& tag = vecBuf[2];
//insert node
TrieNodeInfo nodeInfo;
nodeInfo.word = chWord;
nodeInfo.wLen = 0;
nodeInfo.count = count;
nodeInfo.tag = tag;
bool flag = insert(nodeInfo);
if(!flag)
nodeInfo.word = vecBuf[0];
nodeInfo.count = atoi(vecBuf[1].c_str());
if(3 == vecBuf.size())
{
LogError("insert node failed!");
return false;
nodeInfo.tag = vecBuf[2];
}
//insert node
if(!insert(nodeInfo))
{
LogError("insert node failed!");
}
}
return true;
}

View File

@ -35,10 +35,8 @@ namespace CppJieba
double weight;
TrieNodeInfo()
{
word = "";
wLen = 0;
count = 0;
tag = "";
weight = 0.0;
}
};
@ -101,7 +99,7 @@ namespace CppJieba
bool insert(const TrieNodeInfo& nodeInfo);
private:
bool _buildTree(const char * const filePath);
bool _trieInsert(const char * const filePath);
bool _countWeight();
bool _deleteNode(TrieNode* node);