string GetTranslate(string Key) { dict_t::iterator it=Lang.find(Key); if(it==Lang.end()) return string(" Unknown_word "); else return it->second; }
//------------------------------------------------------------------------------ void getTablesListAndOccurence(std::vector<connectionLine>& connectionArray, dict_t& tablesDictionary) { bool t1EQt2; for( size_t idx = 0; idx < connectionArray.size(); ++idx ) { connectionLine& CL = connectionArray[idx]; t1EQt2 = (CL.table1 == CL.table2); if(tablesDictionary.find(CL.table1) == tablesDictionary.end() ) tablesDictionary[CL.table1] = 0; if(tablesDictionary.find(CL.table2) == tablesDictionary.end() ) tablesDictionary[CL.table2] = 0; if (!t1EQt2) { tablesDictionary[CL.table1]++; tablesDictionary[CL.table2]++; } } }
int main(int argc, char* argv[]) { std::mt19937 eng(time(NULL)); string_t line; string_t search(argv[1] ? argv[1] : "好好学习"); const int WORD_SIZE = 12; if (argc < 2 || search.size() < WORD_SIZE) { std::cout << "Usage: ./idiom 好好学习" << std::endl; return 1; } m_file.open("dict.txt"); while (m_file >> line) { if (line.size() < WORD_SIZE) continue; string_t lineFirstStr = line.substr(0, 3); if (m_dict.find(lineFirstStr) != m_dict.end()) { m_dict[lineFirstStr].push_back(line); } else { array_t words; words.push_back(line); m_dict[lineFirstStr] = words; } } m_file.close(); string_t searchStr = search.substr(9, 12); std::cout << searchStr << std::endl; if (m_dict.find(searchStr) != m_dict.end()) { std::uniform_int_distribution<int> uniform_int_index(0, m_dict[searchStr].size() - 1); std::cout << m_dict[searchStr][uniform_int_index(eng)] << std::endl; } return 0; }
//------------------------------------------------------------------------------ // getFirstTableName is used to take the first Source std::string getFirstTableName(dict_t& dictionary) { std::string firstTable = (*dictionary.begin()).first; int minValue = (*dictionary.begin()).second; for(dict_t::iterator idx = dictionary.begin(); idx != dictionary.end(); ++idx ) { if ((*idx).second < minValue) { minValue = (*idx).second; firstTable = (*idx).first; } } return firstTable; }
iterator end() const { return iterator(dict.end()); }