dynamicphrasetable.h

来自「我们一个小组」· C头文件 代码 · 共 69 行

H
69
字号
#pragma once

#include <string>
#include <hash_map>
#include <vector>
#include <algorithm>

using std::string;
using stdext::hash_map;
using std::vector;

static const double DYNAMIC_FREQUENCY_INCREASEMENT = 0.5 ;

class ID
{
public:
	int id;
	double frequency;
	ID(int id,double frequency)
	{
		this->id = id;
		this->frequency = frequency;
	}
	
	int getid()
	{
		return id;
	}
	double getfrequency()
	{
		return frequency;
	}

	bool operator < (ID other)
	{
		return frequency > other.frequency ;
	}

	bool operator == (ID other)
	{
		return this->id == other.id;
	}
	
};

class DynamicPhraseTable
{
public:
	DynamicPhraseTable();

	bool GetVectorByPhrase(const string& strPYPhrase, vector<ID> &vecPhrase);
	
	bool InsertPhrase(const string& strPYPhrase,int nid,double frequency );

	//Get the word by py, using longest-matching strategy, return the longest matching count
	int GetPhraseByLongestMatchPy(const string& strPy, vector<ID> &vecPhraseID) ;

	bool IncreaseFrequency(const string& strPy, int id);

	bool Save(const string& strFileName) ;
	
	bool Load(const string& strFilename) ;

protected:

private:
	hash_map<string, vector<ID> > m_Phrase2VectorMap;        //插入动态表

};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?