Esempio n. 1
0
void testKeyWordExt(const char * dictPath, const char * filePath)
{
	KeyWordExt ext;
	ext.init();

	if(!ext.loadSegDict(dictPath))
	{
		cerr<<__FILE__<<__LINE__<<endl;
		return ;
	}
	if(!ext.loadStopWords("../dicts/stopwords.gbk.v1.0"))
	{
		cerr<<__FILE__<<__LINE__<<endl;
		return ;
	}
	ifstream ifile(filePath);
	vector<KeyWordInfo> res;
	string line;
	while(getline(ifile, line))
	{
		res.clear();
		if(!line.empty())
		{
			ext.extract(line, res, 20);
			cout<<line<<'\n'<<joinWordInfos(res)<<endl;
		}

	}
	ext.dispose();
}
Esempio n. 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();
}