Example #1
0
		void p_length() {
			init();

			int n = atoi(inbox_search.get_string().c_str());
			if(n < 0) {
				textlist->push_back(new Text(Point(10, text_y), "(nil)"));
				attach((*textlist)[0]);
				Fl::redraw();
				return;
			}

			string s = "word == ";
			unordered_map<string, int> list;
			if(inbox_search.get_string() == "max") s += to_string(length(words, list, -1));
			else if(inbox_search.get_string() == "min") s += to_string(length(words, list, -2));
			else s += to_string(length(words, list, n));
			textlist->push_back(new Text(Point(10, text_y), s));

			int count = 1;
			if(list.size() == 0) textlist->push_back(new Text(Point(10, text_y + 20), "(nil)"));
			for(unordered_map<string, int>::const_iterator it = list.begin(); it != list.end(); ++it) {
				textlist->push_back(new Text(Point(10, text_y + 20 * count), it->first + ": " + to_string(it->second)));
				++count;
			}

			for(int i = 0; i < textlist->size(); ++i)
				attach((*textlist)[i]);
			Fl::redraw();	// 再描画
		}
Example #2
0
		void p_freq() {
			init();

			int n = atoi(inbox_search.get_string().c_str());
			if(n < 0) {
				textlist->push_back(new Text(Point(10, text_y), "(nil)"));
				attach((*textlist)[0]);
				Fl::redraw();
				return;
			}

			string s = "frequency == ";
			vector<string> list;
			if(inbox_search.get_string() == "max") s += to_string(frequency(words, list, -1));
			else if(inbox_search.get_string() == "min") s += to_string(frequency(words, list, -2));
			else s += to_string(frequency(words, list, n));
			textlist->push_back(new Text(Point(10, text_y), s));

			int count = 1;
			if(list.size() == 0) textlist->push_back(new Text(Point(10, text_y + 20), "(nil)"));
			for(vector<string>::const_iterator it = list.begin(); it != list.end(); ++it) {
				textlist->push_back(new Text(Point(10, text_y + 20 * count), *it));
				++count;
			}

			for(int i = 0; i < textlist->size(); ++i)
				attach((*textlist)[i]);
			Fl::redraw();	// 再描画
		}
Example #3
0
		void p_count() {
			init();

			string s = "Count == " + to_string(wordcount(words, inbox_search.get_string()));
			textlist->push_back(new Text(Point(10, text_y), s));

			attach((*textlist)[0]);
			Fl::redraw();	// 再描画
		}
double get_double(In_box& ib)
{
    string s;
    s = ib.get_string();
    if (s == "") error("No value in ",ib.label);
    istringstream iss(s);
    double d;
    iss >> d;
    if (!iss) error("Invalid value in ",ib.label);
    return d;
}
Example #5
0
		// 初期化
		void init() {
			words.clear();
			string tmp;
			ifstream ifs(inbox_file.get_string().c_str());
			while(ifs >> tmp) ++words[tmp];

			list_v.clear();
			if(textlist != nullptr) {
				for(int i = 0; i < textlist->size(); ++i)
					detach((*textlist)[i]);
				delete textlist;
			}
			textlist = new Vector_ref<Text>;
		}
Example #6
0
		void p_find() {
			init();

			unordered_map<string, int> list;

			f_search(words, list, inbox_search.get_string());
			textlist->push_back(new Text(Point(10, text_y), "find == " + to_string(list.size())));

			int count = 1;
			if(list.size() == 0) textlist->push_back(new Text(Point(10, text_y + 20), "(nil)"));
			for(unordered_map<string, int>::const_iterator it = list.begin(); it != list.end(); ++it) {
				textlist->push_back(new Text(Point(10, text_y + 20 * count), it->first + ": " + to_string(it->second)));
				++count;
			}

			for(int i = 0; i < textlist->size(); ++i)
				attach((*textlist)[i]);
			Fl::redraw();	// 再描画
		}