wvstring U8sToWcs(const vstring &src){ wvstring ret; const int nConvLen = ::MultiByteToWideChar(CP_UTF8, 0, src.c_str(), src.size(), nullptr, 0); if(nConvLen > 0){ ret.resize(nConvLen); ret.resize(::MultiByteToWideChar(CP_UTF8, 0, src.c_str(), src.size(), &ret[0], nConvLen)); } return std::move(ret); }
/*! * @if jp * @brief 与えられた文字列リストからCSVを生成 * @else * @brief Create CSV file from the given string list * @endif */ std::string flatten(vstring sv) { if (sv.size() == 0) return ""; std::string str; for (size_t i(0), len(sv.size() - 1); i < len; ++i) { str += sv[i] + ", "; } return str + sv.back(); }
void tokenize(const std::string str, vstring &v) { std::string buffer; for (int i = 0; i < str.length(); ++i) { if (!isPunc(str[i]) && !isspace(str[i]) && str[i] != '.') { buffer += str[i]; } else if (!buffer.empty()) { v.push_back(buffer); buffer.erase(); } } if ((v.empty() && !buffer.empty()) || !buffer.empty()) { v.push_back(buffer); } }
void loadannots() { ifstream annots; annots.open(scangen_args.phenotype_arg); if (annots.fail()){ cerr << "Cannot open phenotype file: " << strerror(errno) << endl; exit(EXIT_FAILURE); } back_insert_iterator<vstring> dest(phenos); copy(iisstring(annots),iisstring(),dest); annots.close(); ifstream glist; if (species=="droso"){ cout << "Reading droso genes list..." << endl; glist.open( (scangen_datapath+"/droso/annot/genelist.dat").c_str() ); } else if (species=="eutherian"){ cout << "Reading eutherian genes list..." << endl; glist.open( (scangen_datapath+"/eutherian/annot/genelist.dat").c_str() ); } if (glist.fail()){ cerr << "Cannot open gene list file: " << strerror(errno) << endl; exit(EXIT_FAILURE); } back_insert_iterator<vstring> destg(gbacks); copy(iisstring(glist),iisstring(),destg); glist.close(); for (ivstring ivs=phenos.begin();ivs!=phenos.end();ivs++){ for (ivstring ivs2=gbacks.begin();ivs2!=gbacks.end();ivs2++){ if (*ivs2==*ivs){ gbacks.erase(ivs2); break; } } } // for (ivstring ivs=phenos.begin();ivs!=phenos.end();ivs++){ // cout << *ivs << endl; // } }
int rfind(vstring v, std::string str) { int start = v.size() - 1; for(int i = start; i >= 0; --i) { if(v[i] == str) { return start - i; } } return -1; }
int find(vstring v, std::string str) { int iLim = v.size(); for(int i = 0; i < iLim; ++i) { if(v[i] == str) { return i; } } return -1; }
void Tokenizer::tokenize( vstring &v ) { if(buffer.length() == 0) { return; } resetPosition(); for( ; firstToken() != ""; v.push_back(thisToken)) ; resetPosition(); }
/*! * @if jp * @brief 文字列リスト中にある文字列が含まれるかどうかを判断する * @else * @brief Include if a string is included in string list * @endif */ bool includes(const vstring& list, std::string value, bool ignore_case) { if (ignore_case) { toLower(value); } for (int i(0), len(static_cast<int>(list.size())); i < len; ++i) { std::string str(list[i]); if (ignore_case) { toLower(str); } if (str == value) return true; } return false; }
// copy the content of a string array to a vector void copy(char *array[], vstring &v, size_t array_size) { for(int i = 0; i < array_size; ++i) { if(array[i] != NULL) { v.push_back(array[i]); } else { break; } } }
void comppheno() { // attribute phenotype to CRMs for (unsigned int i=0;i<nbchrom;i++){ for (ivginst ivg=groupedinst[i].begin();ivg!=groupedinst[i].end();ivg++){ (*ivg).isdiscarded(); if (!(*ivg).discarded){ for (ivstring ivs=phenos.begin();ivs!=phenos.end();ivs++){ if ((*ivg).besttss.gene==*ivs){ (*ivg).goodpheno=1; break; } else { (*ivg).goodpheno=0; } } } else { (*ivg).goodpheno=0; } } } return; }
// handle the context of the conversation // (the previous replies of the chatterbot) void Eliza::verify_context(vstring vContext) { m_bGoodContext = 0; size_t nNum = vContext.size(); if(nNum == 0) { m_bGoodContext = 1; return; } for(int i = 0; i < nNum; ++i) { if(is_template(vContext[i])) { findSymbol(vContext[i]); replace(vContext[i], m_sSymbol, m_sSuffix); } if(m_sPrevResponse == vContext[i]) { m_bGoodContext = 1; break; } } }
void copy(char *array[], vstring &v) { for(int i = 0; i < MAX_RESP; ++i) { v.push_back(array[i]); } }
/*! * @if jp * @brief 与えられた文字列リストから重複を削除 * @else * @brief Eliminate duplication from the given string list * @endif */ vstring unique_sv(vstring sv) { return std::for_each(sv.begin(), sv.end(), unique_strvec()).str; }
void Eliza::saveTopic(const vstring vList, const std::string sSymbol) { int listSize = vList.size(); for(int i = 0; i < listSize; ++i) { scriptfile << sSymbol << vList[i] << std::endl; } }
void Eliza::add_response(vstring v) { int size = v.size(); for(int i = 0; i < size; ++i) { response_list.push_back(v[i]); } }