#include <iostream> #include <iterator> #include <vector> #include <cstddef> #include <string> #include <sstream> #include <fstream> #include <algorithm> #include <cmath> #include <set> #include <limits> #include <functional> #include <numeric> void ReadDataFromCsv(const std::string &filename, std::vector<std::vector<std::string> > &lines_feat) { std::ifstream vm_info(filename.c_str()); std::string lines, var; std::vector<std::string> row; lines_feat.clear(); while(!vm_info.eof()) { getline(vm_info, lines); if(lines.empty()) break; std::istringstream stringin(lines); row.clear(); while(std::getline(stringin, var, ',')) { row.push_back(var); } lines_feat.push_back(row); } } template <class DataType> void ReadMatFromFile(std::string &filename, std::vector<std::vector<DataType> > &lines_feat) { std::ifstream vm_info(filename.c_str()); std::string lines; DataType var; std::vector<DataType> row; lines_feat.clear(); while(!vm_info.eof()) { getline(vm_info, lines); if(lines.empty()) break; std::replace(lines.begin(), lines.end(), ',', ' '); std::stringstream stringin(lines); row.clear(); while(stringin >> var) { row.push_back(var); } lines_feat.push_back(row); } } void ReadStringFromFile(std::string &filename, std::vector<std::string> &in_string) { std::ifstream vm_info(filename.c_str()); std::string lines, var; while(!vm_info.eof()) { getline(vm_info, lines); if(lines.empty()) break; std::stringstream stringin(lines); while(stringin >> var) { in_string.push_back(var); } } } void ReadDataFromFile(std::string &filename, std::vector<std::string> &lines_feat) { std::ifstream vm_info(filename.c_str()); std::string lines; lines_feat.clear(); while(!vm_info.eof()) { getline(vm_info, lines); if(lines.empty()) break; lines_feat.push_back(lines); } } void ReadSetFromFile(std::string &filename, std::set<std::string> &lines_feat) { std::ifstream vm_info(filename.c_str()); std::string lines; lines_feat.clear(); while(!vm_info.eof()) { getline(vm_info, lines); if(lines.empty()) break; lines_feat.insert(lines); } } void ProcessSet(std::set<std::string> &s1, std::set<std::string> &s2) { std::set<std::string>::const_iterator it=s1.begin(), find_it; for(; it!=s1.end(); ++it) { find_it=s2.find(*it); if(find_it == s2.end()) { std::cout<<*it<<", not found. "; } } } std::string lowerCase(const std::string& s) { std::string lower(s); for(size_t i=0;i<s.length();++i) { lower[i]=tolower(lower[i]); } return lower; } std::string letters(const std::string& s) { std::string letter; for(size_t i=0;i<s.length();++i) { char ch=s.at(i); bool flag=false; if((ch>=65 && ch<=90)) { ch=ch+32; flag=true; } else if((ch>=97 && ch<=122) || (ch>=48 && ch<=57)) { flag=true; } else { ; } if(flag) { letter.push_back(ch); } } letter.push_back('