modify load_test

This commit is contained in:
wyy 2013-12-21 20:08:40 -08:00
parent cac77cdedf
commit bbaa8b684d
4 changed files with 56 additions and 43 deletions

View File

@ -10,17 +10,17 @@
namespace Limonp namespace Limonp
{ {
using namespace std; using namespace std;
inline string loadFile2Str(const char * const filepath) inline bool loadFile2Str(const char * const filepath, string& res)
{ {
ifstream in(filepath); ifstream in(filepath);
if(!in) if(!in)
{ {
return ""; return false;
} }
istreambuf_iterator<char> beg(in), end; istreambuf_iterator<char> beg(in), end;
string str(beg, end); res.assign(beg, end);
in.close(); in.close();
return str; return true;
} }
inline void loadStr2File(const char * const filename, ios_base::openmode mode, const string& str) inline void loadStr2File(const char * const filename, ios_base::openmode mode, const string& str)

View File

@ -1,5 +1,5 @@
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test)
ADD_EXECUTABLE(segment.demo segment.cpp) ADD_EXECUTABLE(segment.demo segment.cpp)
ADD_EXECUTABLE(test_performance test_performance.cpp) ADD_EXECUTABLE(load_test load_test.cpp)
ADD_SUBDIRECTORY(unittest) ADD_SUBDIRECTORY(unittest)

51
test/load_test.cpp Normal file
View 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;
}

View File

@ -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;
}