mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
modify load_test
This commit is contained in:
parent
cac77cdedf
commit
bbaa8b684d
@ -10,17 +10,17 @@
|
||||
namespace Limonp
|
||||
{
|
||||
using namespace std;
|
||||
inline string loadFile2Str(const char * const filepath)
|
||||
inline bool loadFile2Str(const char * const filepath, string& res)
|
||||
{
|
||||
ifstream in(filepath);
|
||||
if(!in)
|
||||
{
|
||||
return "";
|
||||
return false;
|
||||
}
|
||||
istreambuf_iterator<char> beg(in), end;
|
||||
string str(beg, end);
|
||||
res.assign(beg, end);
|
||||
in.close();
|
||||
return str;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void loadStr2File(const char * const filename, ios_base::openmode mode, const string& str)
|
||||
|
@ -1,5 +1,5 @@
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test)
|
||||
|
||||
ADD_EXECUTABLE(segment.demo segment.cpp)
|
||||
ADD_EXECUTABLE(test_performance test_performance.cpp)
|
||||
ADD_EXECUTABLE(load_test load_test.cpp)
|
||||
ADD_SUBDIRECTORY(unittest)
|
||||
|
51
test/load_test.cpp
Normal file
51
test/load_test.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "../src/Limonp/ArgvContext.hpp"
|
||||
#include "../src/MPSegment.hpp"
|
||||
#include "../src/HMMSegment.hpp"
|
||||
#include "../src/MixSegment.hpp"
|
||||
|
||||
using namespace CppJieba;
|
||||
|
||||
void cut(const ISegment * seg, const char * const filePath, size_t times = 10)
|
||||
{
|
||||
ifstream ifile(filePath);
|
||||
if(!ifile)
|
||||
{
|
||||
LogFatal("open file[%s] failed.", filePath);
|
||||
return;
|
||||
}
|
||||
LogInfo("open file[%s].", filePath);
|
||||
vector<string> res;
|
||||
string doc;
|
||||
loadFile2Str(filePath, doc);
|
||||
for(uint i = 0; i < times; i ++)
|
||||
{
|
||||
LogInfo("times[%u]", i);
|
||||
//ifile.seekg(0);
|
||||
//while(getline(ifile, line))
|
||||
//{
|
||||
// if(!line.empty())
|
||||
// {
|
||||
res.clear();
|
||||
seg->cut(doc, res);
|
||||
//print(res);
|
||||
//cout<<join(res.begin(), res.end(),"/")<<endl;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
{
|
||||
MixSegment seg("../dicts/jieba.dict.utf8", "../dicts/hmm_model.utf8");
|
||||
if(!seg)
|
||||
{
|
||||
cout<<"seg init failed."<<endl;
|
||||
return false;
|
||||
}
|
||||
cut(&seg, "../test/testdata/weicheng.utf8");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "../src/Limonp/ArgvContext.hpp"
|
||||
#include "../src/MPSegment.hpp"
|
||||
#include "../src/HMMSegment.hpp"
|
||||
#include "../src/MixSegment.hpp"
|
||||
|
||||
using namespace CppJieba;
|
||||
|
||||
void cut(const ISegment * seg, const char * const filePath)
|
||||
{
|
||||
ifstream ifile(filePath);
|
||||
vector<string> res;
|
||||
string line;
|
||||
while(getline(ifile, line))
|
||||
{
|
||||
if(!line.empty())
|
||||
{
|
||||
res.clear();
|
||||
seg->cut(line, res);
|
||||
//cout<<join(res.begin(), res.end(),"/")<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
{
|
||||
MixSegment seg("../dicts/jieba.dict.utf8", "../dicts/hmm_model.utf8");
|
||||
if(!seg)
|
||||
{
|
||||
cout<<"seg init failed."<<endl;
|
||||
return false;
|
||||
}
|
||||
cut(&seg, argv[1]);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user