示例#1
0
int main()
{
	Segment segment;
	segment.init();
	if(!segment.loadSegDict("../dicts/segdict.gbk.v3.0"))
	{
		cerr<<"1"<<endl;
		return 1;
	}
	//segment.init("dicts/jieba.dict.utf8");
	//ifstream ifile("testtitle.gbk");
	ifstream ifile("badcase");
	vector<string> res;
	string line;
	while(getline(ifile, line))
	{
		res.clear();
		segment.cutDAG(line, res);
		PRINT_VECTOR(res);
		getchar();
	}

	segment.dispose();
	return 0;
}
示例#2
0
void testKeyWordExt2(const char * dictPath, const char * filePath)
{
	Segment seg;
	seg.init();
	KeyWordExt ext;
	ext.init();

	if(!seg.loadSegDict(dictPath))
	{
		cerr<<__FILE__<<__LINE__<<endl;
		return ;
	}

	if(!ext.loadSegDict(dictPath));
	{
		cerr<<__FILE__<<__LINE__<<endl;
		return ;
	}

	ifstream ifile(filePath);
	vector<string> words;
	vector<KeyWordInfo> res;
	string line;
	while(getline(ifile, line))
	{
		if(!line.empty())
		{
			seg.cutDAG(line, words);
			ext.extract(words, res, 20);
			cout<<line<<"\n"<<joinWordInfos(res)<<endl;
		}

	}
	seg.dispose();
	ext.dispose();
}