コード例 #1
0
    string recognize(string text)
    {
        text = preprocess(text);
        //cout << "text = " << text << endl;

        FuzzyMatcher matcher;
        vector<MatchGroup> mg = matcher.match(regex, text);

        int maxScore = 0;
        MatchGroup ans;
        //cout <<"mg.size() = "<< mg.size() << endl;
        int k;
        for(int i = 0; i < mg.size(); ++i)
        {
            int score = mg[i].score();
            if(score > maxScore)
            {
                ans = mg[i];
                maxScore = score;
                k = i;
            }
        }
        /*vector<MState> vms = ans.states;
        vector<MState>::iterator iter = vms.begin();
        while(iter != vms.end())
        {
        	cout << iter->name << "\t" << iter->mString << "\t" << iter->matched << "\t" << iter->offset << endl;
        	++iter;
        }
*/
        if(maxScore > 1)
            return ans.convertString();

       	return "";
    }
コード例 #2
0
ファイル: filter.cpp プロジェクト: Freaky/qgrep
static void processMatchHighlightCommandT(FuzzyMatcher& matcher, bool ranked, FilterHighlightBuffer& hlbuf, const FilterEntry& entry, const char* buffer, FilterOutput* output)
{
    const char* data = buffer + entry.offset;

	assert(matcher.size() > 0);
	hlbuf.posbuf.resize(matcher.size());

	if (ranked)
		matcher.rank(data, entry.length, &hlbuf.posbuf[0]);
	else
		matcher.match(data, entry.length, &hlbuf.posbuf[0]);

	hlbuf.ranges.resize(hlbuf.posbuf.size());
	for (size_t i = 0; i < hlbuf.posbuf.size(); ++i) hlbuf.ranges[i] = std::make_pair(hlbuf.posbuf[i], 1);

	hlbuf.result.clear();
	highlight(hlbuf.result, data, entry.length, hlbuf.ranges.empty() ? nullptr : &hlbuf.ranges[0], hlbuf.ranges.size(), kHighlightMatch);

	processMatch(hlbuf.result.c_str(), hlbuf.result.size(), output);
}