int main (void) { string text_dirpath = string("/Users/KimKR/Desktop/NEXT_LAB/keyword/test"); string relscore_path = string("/Users/KimKR/Desktop/NEXT_LAB/keyword/rel_score/test/bm25_3_3"); vector<string> textfiles = vector<string>(); getdir(text_dirpath, textfiles); int winsize = 2; int cutoff_list[] = {3}; int cutoff_size = 1; double lambda_list[1]; int lambda_size = 1; Converter cv; Print print; // for(int i = 0; i < 21; ++i) { // lambda_list[i] = i * 0.05; // } lambda_list[0] = 0.85; clock_t all_begin = clock(); for(int fidx = textfiles.size() - 1; fidx >= 0; --fidx) { string filename = textfiles[fidx]; vector<string> sentences = TextRead(text_dirpath + "/" + filename); clock_t begin = clock(); for(int k = K_STR; k < K_STEP; ++k) { double k1 = k * 0.1; for(int b1 = 0; b1 < 1; ++b1) { double b = 0.05 * b1; string relfile_path = relscore_path + "_" + cv.to_string(k1, 2) + "_" + cv.to_string(b, 3) + "/" + filename; map<string, double> relscore; if(RelscoreRead(relfile_path, &relscore) == 0) continue; BuildGraph bg(filename, sentences, &relscore, winsize, k1, b, lambda_list, lambda_size, cutoff_list, cutoff_size); Graph G; G.null_ = true; bg.run(true, false, false, false); print.Vector("top_score_candidates", bg.top_score_candidates_.at(3).at(0.85)); SaveGraph(bg.top_score_candidates_, bg.filename_, bg.k1_, bg.b_, bg.winsize_); } } clock_t end = clock(); double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; cout << filename << " : " << elapsed_secs << endl; } clock_t end = clock(); double elapsed_secs = double(end - all_begin) / CLOCKS_PER_SEC; cout << "all finished" << " : " << elapsed_secs << endl; getchar(); }
void SaveGraph(const map<int, map<double, vector<string> > >& candidates, const string& filename, double k1_input, double b_input, int winsize_input) { Converter cv; string winsize = to_string(winsize_input); string k1 = cv.to_string(k1_input, 2); string b = cv.to_string(b_input, 3); string dirpath = "../graph/" + k1 + "_" + b; string filepath = dirpath + "/" + filename + ".csv"; string header = "winsize,cutoff,lambda,keywords_candidates\n"; // CreateDirectory(dirpath); if(!FileExists(filepath)) FileWrite(filepath, header); ofstream out(filepath, ios_base::app | ios_base::out); for(auto itr = candidates.begin(); itr != candidates.end(); ++itr) { int cutoff = itr->first; map<double, vector<string> > lamb_candidate = itr->second; for (auto j = lamb_candidate.begin(); j != lamb_candidate.end(); ++j) { double lambda = j->first; cout << candidates.at(cutoff).at(lambda)[0] << endl; string keywords_candidates = Join(candidates.at(cutoff).at(lambda), ';'); out << winsize + "," + to_string(cutoff) + "," + cv.to_string(lambda, 3) + "," + keywords_candidates + "\n"; } } };