int main() { int n = 4; std::vector<int> men1 = {2,1,0,3}; std::vector<int> men2 = {1,3,0,2}; std::vector<int> men3 = {2,0,3,1}; std::vector<int> men4 = {0,1,2,3}; std::vector<int> women1 = { 0,2,1,3 }; std::vector<int> women2 = { 2,3,1,0 }; std::vector<int> women3 = { 1,2,3,0 }; std::vector<int> women4 = { 3,1,0,2 }; std::vector<std::vector<int>> men(n, std::vector<int>(n)); men = { {men1},{men2},{men3},{men4}}; std::vector<std::vector<int>> women(n, std::vector<int>(n)); women = { { women1 },{ women2 },{ women3 },{ women4 }}; couples(men, women, n); return 0; }
//****************************************对抽取的语料库按类别进行分类**************************************** void corpus_category(string filename_path, string path_read, string path_write) //参数1:文件名列表路径 参数2:读取文件的目录 参数3:写入文件的目录 { string file_name; //存储读取的各个文件的名字 ifstream read_filename(filename_path); //从LIST.TXT读取文件名 ofstream sports(path_write+"sports.txt");//属于sport类的存放在sport.txt文件中 ofstream house(path_write+"house.txt"); ofstream it(path_write+"it.txt"); ofstream test_2008(path_write+"2008.txt"); ofstream news(path_write+"news.txt"); ofstream yule(path_write+"yule.txt"); ofstream business(path_write+"business.txt"); ofstream travel(path_write+"travel.txt"); ofstream mil_news(path_write+"mil.news.txt"); ofstream women(path_write+"women.txt"); ofstream health(path_write+"health.txt"); ofstream test_auto(path_write+"auto.txt"); ofstream cul(path_write+"cul.txt"); ofstream learning(path_write+"learning.txt"); ofstream test_else(path_write+"else.txt"); string path_in, str_line,cut_str;//path_in:存放读文件路径 str_line:读取的一行文件 cut_str:存放截取的字符串 string::size_type pos1, pos2; int number = 0; while (getline(read_filename, file_name)) { number++; cout << number << endl; path_in = path_read + file_name; ifstream infile(path_in); while (getline(infile, str_line)) //读取各个文件的每一行字符串 { pos1 = 0; pos2 = str_line.find("####"); cut_str = str_line.substr(pos1, pos2 - pos1); if (string(cut_str) == string("sports")) //字符串匹配 是否为sports类 { sports << str_line << endl; //如果是sports类就把该行输出到sports.txt文件 } else if (cut_str == "house") { house << str_line << endl; } else if (cut_str == "it") { it << str_line << endl; } else if (cut_str == "2008") { test_2008 << str_line << endl; } else if (cut_str == "news") { news << str_line << endl; } else if (cut_str == "yule") { yule << str_line << endl; } else if (cut_str == "business") { business << str_line << endl; } else if (cut_str == "travel") { travel << str_line << endl; } else if (cut_str == "mil.news") { mil_news << str_line << endl; } else if (cut_str == "women") { women << str_line << endl; } else if (cut_str == "health") { health << str_line << endl; } else if (cut_str == "auto") { test_auto << str_line << endl; } else if (cut_str == "cul") { cul << str_line << endl; } else if (cut_str == "learning") { learning << str_line << endl; } else { test_else << str_line << endl; } } infile.close(); //每次结束都得关闭文件. } }