⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynamicphrasetable.h

📁 我们一个小组
💻 H
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -