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

📄 dictionary.h

📁 k-means源码(K均值聚类算法源码)
💻 H
字号:
#ifndef _DICTIONARY_H_#define _DICTIONARY_H_#include <map>#include <iostream>#include <string>// TODO: Add a stoplist to the Dictionary (if it is really needed)// TODO: Dictionary should save "stemmed" wordsclass Dictionary{	private:		std::map<std::string,int> words;	public:	int add_word(std::string word)	{		if (words[word] == 0)			words[word] = words.size();					return words[word];	}		int size() const	{		return words.size();	}		int operator[](std::string word)	{		if(words.find(word) == words.end())			return 0;		else			return words[word];	}		std::string operator[](int index)	{			bool found = false;				std::map<std::string, int>::const_iterator i = words.begin();		while(i != words.end() && !found) 		{			if(i->second == index)				found = true;			else				i++;		}		if(found)			return i->first;		else			return "";	}		friend std::ostream& operator << (std::ostream &os, const Dictionary& d)	{		os << d.words.size();		os << ' ';		std::map<std::string, int>::const_iterator i; 		for(i = d.words.begin(); i != d.words.end(); ++i)		{			os << i->first << ' ' << i->second << ' ';		}				return os;				}	friend std::istream& operator >> (std::istream &is, Dictionary& d) 	{		int size = 0;		std::string key; // a word		int value;		 // and the correspondent index		d.words.clear();						is >> size;				for(int i = 0; i < size; i++) 		{			is >> key;			is >> value;						d.words[key] = value;		}		return is;	}};#endif /* _DICTIONARY_H_ */

⌨️ 快捷键说明

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