#include using namespace std; #define KEY_EXISTS_DICT(KEY, DICT) ( (DICT.find(KEY) == DICT.end()) ? (false) : (true)) string INPUT_FILE_NAME = "Data.CS.SFSU.txt"; string POS[] = {"noun", "pronoun", "adjective", "verb", "adverb", "preposition", "conjunction", "interjection"}; string make_lower(string data) { transform(data.begin(), data.end(), data.begin(), ::tolower); return data; } bool check_pos(string pos) { for (int i = 0; i < 8; i++) { if (POS[i] == make_lower(pos)) return true; } return false; } void print(vector &v) { for (size_t n = 0; n < v.size(); n++) cout << "\"" << v[n] << "\"\n"; cout << endl; } class Dictionary { private: string key_name; map > value; public: Dictionary() { key_name = ""; for (int i = 0; i < 8; i++) { value[POS[i]] = vector(); } } void add_key_name(string key) { key_name = key; } string get_key_name() { return key_name; } void print_meanings(string pos, bool print=false) { if ( print && value[make_lower(pos)].size()==0) cout<<"\t\t"< >::iterator it; for (it = value.begin(); it != value.end(); ++it) { print_meanings(it->first); } } void print_value(string pos=""){ if (pos=="") print_all_value(); else print_meanings(pos); } }; vector split(string stringToBeSplitted, string delimeter) { vector splittedString; int startIndex = 0; int endIndex = 0; while( (endIndex = stringToBeSplitted.find(delimeter, startIndex)) < stringToBeSplitted.size() ) { string val = stringToBeSplitted.substr(startIndex, endIndex - startIndex); splittedString.push_back(val); startIndex = endIndex + delimeter.size(); } if(startIndex < stringToBeSplitted.size()) { string val = stringToBeSplitted.substr(startIndex); splittedString.push_back(val); } return splittedString; } //class Dictionary parse_line(string line){ Dictionary dictionary; vector key_value; key_value = split(line, "|"); dictionary.add_key_name(key_value[0]); for (size_t n = 1; n < key_value.size(); n++){ vector pos_meaning_pair; pos_meaning_pair = split(key_value[n], " => "); dictionary.add_value(pos_meaning_pair[0], pos_meaning_pair[1]); } return dictionary; } int main() { map dictionary; cout<<"! Opening data file... ./"< search_data; search_data = split(line, " "); if (search_data.size()>2 || search_data.size()==0) cout<<"\t\t"<"<"<