From 4a6b3a2acf91421a958b9946e15a149cac29e7b5 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 17 Aug 2015 19:39:01 +0000 Subject: warning fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@14980 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Boltun/src/Engine/Mind.cpp | 188 ++++++++++++--------------- plugins/Boltun/src/Engine/TalkEngine.cpp | 212 +++++++++++++------------------ 2 files changed, 167 insertions(+), 233 deletions(-) (limited to 'plugins/Boltun/src/Engine') diff --git a/plugins/Boltun/src/Engine/Mind.cpp b/plugins/Boltun/src/Engine/Mind.cpp index 5158a459e6..11e636cd81 100644 --- a/plugins/Boltun/src/Engine/Mind.cpp +++ b/plugins/Boltun/src/Engine/Mind.cpp @@ -80,8 +80,7 @@ vector Mind::Parse(tstring s) return res; s.resize(len); int it = 0; - while (it != len) - { + while (it != len) { while (it != len && _istspace(s[it])) it++; if (it == len) @@ -110,19 +109,15 @@ void Mind::Load(tstring filename) bool start = true; - try - { - while (file.good()) - { + try { + while (file.good()) { getline(file, st); if (st.empty()) break; line++; - if (start) - { - if (st[0] == 65279) - { + if (start) { + if (st[0] == 65279) { st.erase(0, 1); fileTypeMark = true; } @@ -136,16 +131,13 @@ void Mind::Load(tstring filename) c = co = new TCHAR[count + 1]; mir_tstrcpy(c, st.c_str()); size_t pos = 0; - while (pos < count && _istspace(*c)) - { + while (pos < count && _istspace(*c)) { ++pos; ++c; } count -= pos; - if (count > 2) - { - switch (*c) - { + if (count > 2) { + switch (*c) { case '(': if (c[count - 1] != ')') abort(); @@ -160,13 +152,15 @@ void Mind::Load(tstring filename) toLowerStr(c); { WordsList l(c); - if (!l.IsEmpty()) + if (!l.IsEmpty()) { if (l.IsQuestion()) data->qkeywords.insert(make_pair(l, s1)); else data->keywords.insert(make_pair(l, s1)); + } } break; + case '{': if (c[count - 1] != '}') abort(); @@ -188,6 +182,7 @@ void Mind::Load(tstring filename) data->specialEscapes.insert(make_pair(l, s1)); } break; + case '[': if (c[count - 1] != ']') throw error; @@ -202,6 +197,7 @@ void Mind::Load(tstring filename) toLowerStr(c); data->widelyUsed.insert(make_pair(c, s1)); break; + case '<': if (c[count - 1] != '>') throw error; @@ -213,62 +209,56 @@ void Mind::Load(tstring filename) ++c; count -= 2; c[count] = '\0'; - if (mir_tstrcmp(c, _T("QUESTION")) == 0) - { + if (mir_tstrcmp(c, _T("QUESTION")) == 0) { toLowerStr(c); data->question.insert(s1); } - else - if (mir_tstrcmp(c, _T("IGNORED")) == 0) - { - toLowerStr(c); - data->special.insert(s1); - } - else - if (mir_tstrcmp(c, _T("ESCAPE")) == 0) - { - data->escape.push_back(s1); - } - else - if (mir_tstrcmp(c, _T("FAILURE")) == 0) - { - data->failure.push_back(s1); - } - else - if (mir_tstrcmp(c, _T("REPEAT")) == 0) - { - data->repeats.push_back(s1); - } - else - { - if (mir_tstrcmp(c, _T("INITIAL")) != 0) - throw error; - data->initial.push_back(s1); - } + else if (mir_tstrcmp(c, _T("IGNORED")) == 0) { + toLowerStr(c); + data->special.insert(s1); + } + else if (mir_tstrcmp(c, _T("ESCAPE")) == 0) { + data->escape.push_back(s1); + } + else if (mir_tstrcmp(c, _T("FAILURE")) == 0) { + data->failure.push_back(s1); + } + else if (mir_tstrcmp(c, _T("REPEAT")) == 0) { + data->repeats.push_back(s1); + } + else { + if (mir_tstrcmp(c, _T("INITIAL")) != 0) + throw error; + data->initial.push_back(s1); + } break; + case '@': - { if (file.eof()) throw error; + getline(file, s1); line++; format(s1); ++c; count -= 1; toLowerStr(c); - tstring sc(c); - int count1 = (int)s1.length(); - TCHAR *c = new TCHAR[count1 + 1]; - mir_tstrcpy(c, s1.c_str()); - CharLower(c); - s1 = c; - delete c; - vector strs = Parse(s1); - data->raliases.insert(make_pair(sc, strs)); - for (vector::const_iterator it = strs.begin(); it != strs.end(); ++it) - data->aliases.insert(make_pair(*it, sc)); - } - break; + { + std::transform(s1.begin(), s1.end(), s1.begin(), ::tolower); + int count1 = (int)s1.length(); + TCHAR *c = new TCHAR[count1 + 1]; + mir_tstrcpy(c, s1.c_str()); + CharLower(c); + s1 = c; + delete c; + vector strs = Parse(s1); + tstring sc(c); + data->raliases.insert(make_pair(sc, strs)); + for (vector::const_iterator it = strs.begin(); it != strs.end(); ++it) + data->aliases.insert(make_pair(*it, sc)); + } + break; + default: if (file.eof()) throw error; @@ -279,25 +269,21 @@ void Mind::Load(tstring filename) data->study.insert(make_pair(c, s1)); } } - else - if (count) - { - if (file.eof()) - throw error; - getline(file, s1); - line++; - format(s1); - data->study.insert(make_pair(c, s1)); - } + else if (count) { + if (file.eof()) + throw error; + getline(file, s1); + line++; + format(s1); + data->study.insert(make_pair(c, s1)); + } } if (!file.eof()) - { throw error; - } + delete co; } - catch (...) - { + catch (...) { throw CorruptedMind(line); delete co; } @@ -315,80 +301,64 @@ void Mind::Save(tstring filename) const if (fileTypeMark) file << TCHAR(65279); - for (string_mmap::iterator it = data->study.begin(); it != data->study.end(); ++it) - { + for (string_mmap::iterator it = data->study.begin(); it != data->study.end(); ++it) { file << (*it).first << _T('\r') << endl; file << (*it).second << _T('\r') << endl; } - for (multimap::iterator it = data->keywords.begin(); it != data->keywords.end(); ++it) - { + for (multimap::iterator it = data->keywords.begin(); it != data->keywords.end(); ++it) { file << _T(" (") << (tstring)(*it).first << _T(")") << _T('\r') << endl; file << (*it).second << _T('\r') << endl; } - for (multimap::iterator it = data->qkeywords.begin(); it != data->qkeywords.end(); ++it) - { + for (multimap::iterator it = data->qkeywords.begin(); it != data->qkeywords.end(); ++it) { file << _T(" (") << (tstring)(*it).first << _T(")") << _T('\r') << endl; file << (*it).second << _T('\r') << endl; } - for (multimap::iterator it = data->specialEscapes.begin(); it != data->specialEscapes.end(); ++it) - { + for (multimap::iterator it = data->specialEscapes.begin(); it != data->specialEscapes.end(); ++it) { file << _T(" {") << (tstring)(*it).first << _T("}") << _T('\r') << endl; file << (*it).second << _T('\r') << endl; } - for (multimap::iterator it = data->qspecialEscapes.begin(); it != data->qspecialEscapes.end(); ++it) - { + for (multimap::iterator it = data->qspecialEscapes.begin(); it != data->qspecialEscapes.end(); ++it) { file << _T(" {") << (tstring)(*it).first << _T("}") << _T('\r') << endl; file << (*it).second << _T('\r') << endl; } - for (string_mmap::iterator it = data->widelyUsed.begin(); it != data->widelyUsed.end(); ++it) - { + for (string_mmap::iterator it = data->widelyUsed.begin(); it != data->widelyUsed.end(); ++it) { file << _T(" [") << (*it).first << _T("]") << _T('\r') << endl; file << (*it).second << _T('\r') << endl; } - for (set::iterator it = data->question.begin(); it != data->question.end(); ++it) - { + for (set::iterator it = data->question.begin(); it != data->question.end(); ++it) { file << _T(" ") << _T('\r') << endl; file << (*it) << _T('\r') << endl; } - for (set::iterator it = data->special.begin(); it != data->special.end(); ++it) - { + for (set::iterator it = data->special.begin(); it != data->special.end(); ++it) { file << _T(" ") << _T('\r') << endl; file << (*it) << _T('\r') << endl; } - for (string_vec::iterator it = data->escape.begin(); it != data->escape.end(); ++it) - { + for (string_vec::iterator it = data->escape.begin(); it != data->escape.end(); ++it) { file << _T(" ") << _T('\r') << endl; file << (*it) << _T('\r') << endl; } - for (string_vec::iterator it = data->initial.begin(); it != data->initial.end(); ++it) - { + for (string_vec::iterator it = data->initial.begin(); it != data->initial.end(); ++it) { file << _T(" ") << _T('\r') << endl; file << (*it) << _T('\r') << endl; } - for (string_vec::iterator it = data->failure.begin(); it != data->failure.end(); ++it) - { + for (string_vec::iterator it = data->failure.begin(); it != data->failure.end(); ++it) { file << _T(" ") << _T('\r') << endl; file << (*it) << _T('\r') << endl; } - for (string_vec::iterator it = data->repeats.begin(); it != data->repeats.end(); ++it) - { + for (string_vec::iterator it = data->repeats.begin(); it != data->repeats.end(); ++it) { file << _T(" ") << _T('\r') << endl; file << (*it) << _T('\r') << endl; } - for (map>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it) - { + for (map>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it) { tstring s; const vector& v = (*it).second; bool first = true; - for (vector::const_iterator it1 = v.begin(); it1 != v.end(); ++it1) - { - if (first) - { + for (vector::const_iterator it1 = v.begin(); it1 != v.end(); ++it1) { + if (first) { first = false; s = *it1; } - else - { + else { s += _T(" ") + *it1; } } @@ -404,8 +374,7 @@ void Mind::LoadSmiles(tstring filename) data->smiles.clear(); tstring s; unsigned int l = 0; - while (!file.eof()) - { + while (!file.eof()) { getline(file, s); if (s.length() > l) l = (int)s.length(); @@ -420,8 +389,7 @@ void Mind::LoadSmiles(void *smiles, size_t size) TCHAR* buf = (TCHAR*)smiles; unsigned l = 0; TCHAR* end = buf + size; - while (buf != end) - { + while (buf != end) { TCHAR *lend = buf; while (lend != end && *lend != _T('\r')) lend++; diff --git a/plugins/Boltun/src/Engine/TalkEngine.cpp b/plugins/Boltun/src/Engine/TalkEngine.cpp index 1c4465402b..ffee42b7c7 100644 --- a/plugins/Boltun/src/Engine/TalkEngine.cpp +++ b/plugins/Boltun/src/Engine/TalkEngine.cpp @@ -43,28 +43,23 @@ void TalkBot::UpdateStartChar(tstring& str) if (!makeLowercase) return; size_t l = str.length(); - if (l) - { + if (l) { //Answers starting with ' ' must remain unchanged. - if (str[0] == _T(' ')) - { + if (str[0] == _T(' ')) { str = str.substr(1); return; } - for (size_t i = 0; i < l; i++) - { + for (size_t i = 0; i < l; i++) { TCHAR cl = (TCHAR)CharLower((LPTSTR)(void*)(long)str[i]); TCHAR cu = (TCHAR)CharUpper((LPTSTR)(void*)(long)str[i]); - if (i != l - 1) - { + if (i != l - 1) { //Do not react to BLONDE ANSWERS TCHAR ncl = (TCHAR)CharLower((LPTSTR)(void*)(long)str[i + 1]); TCHAR ncu = (TCHAR)CharUpper((LPTSTR)(void*)(long)str[i + 1]); if (ncl != ncu && str[i + 1] == ncu) break; } - if (cl != cu) - { + if (cl != cu) { str[i] = cl; break; } @@ -99,16 +94,13 @@ tstring TalkBot::ReplaceAliases(const tstring &message) tstring result; map sm; //Find smiles - for (size_t i = 0; i < sentence.length() - 1; i++) - { + for (size_t i = 0; i < sentence.length() - 1; i++) { unsigned max = (int)(sentence.length() - i); if (max > mind.GetData()->maxSmileLen) max = mind.GetData()->maxSmileLen; - for (unsigned j = max; j > 0; j--) - { + for (unsigned j = max; j > 0; j--) { tstring item = sentence.substr(i, j); - if (mind.GetData()->smiles.find(item) != mind.GetData()->smiles.end()) - { + if (mind.GetData()->smiles.find(item) != mind.GetData()->smiles.end()) { sm[i] = item; sentence.replace(i, j, _T("\1")); break; @@ -118,15 +110,12 @@ tstring TalkBot::ReplaceAliases(const tstring &message) int len = (int)sentence.length(); bool hadQuestionSigns = false; int it = 0; - while (it != len) - { - while (it != len && _tcschr(dividers, sentence[it])) - { + while (it != len) { + while (it != len && _tcschr(dividers, sentence[it])) { if (sentence[it] == _T('?')) hadQuestionSigns = true; map::iterator smit; - if (sentence[it] == '\1') - { + if (sentence[it] == '\1') { smit = sm.find(it); result.append((*smit).second); } @@ -137,8 +126,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message) if (it == len) break; int start = it; - while (true) - { + while (true) { while (it != len && !_tcschr(dividers, sentence[it])) it++; if (it == len || sentence[it] != _T('-')) @@ -169,38 +157,37 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact //Part 2 if (FindExact(contactData, incomingMessage, mind.GetData()->study, res)) //study { -#ifdef DEBUG_PREFIXES - mm.insert(make_pair(LOOKSLIKE, _T("(study_all) ")+res)); -#else + #ifdef DEBUG_PREFIXES + mm.insert(make_pair(LOOKSLIKE, _T("(study_all) ") + res)); + #else mm.insert(make_pair(LOOKSLIKE, res)); -#endif + #endif maxValue = LOOKSLIKE; } //Part 3 vector sentences; SplitSectences(incomingMessage, sentences); ValueChooser<> ch(sentences, true); //Using random order of sentences. - while ((res = ch.GetString()) != _T("")) - { + while ((res = ch.GetString()) != _T("")) { //Part 4 if (FindExact(contactData, res, mind.GetData()->widelyUsed, res)) //widelyUsed { -#ifdef DEBUG_PREFIXES - mm.insert(make_pair(BEST, _T("(widelyused_sent) ")+res)); -#else + #ifdef DEBUG_PREFIXES + mm.insert(make_pair(BEST, _T("(widelyused_sent) ") + res)); + #else mm.insert(make_pair(BEST, res)); -#endif + #endif if (maxValue > BEST) maxValue = BEST; } //Part 5 if (FindExact(contactData, res, mind.GetData()->study, res)) //study { -#ifdef DEBUG_PREFIXES - mm.insert(make_pair(LOOKSLIKE, _T("(study_sent) ")+res)); -#else + #ifdef DEBUG_PREFIXES + mm.insert(make_pair(LOOKSLIKE, _T("(study_sent) ") + res)); + #else mm.insert(make_pair(LOOKSLIKE, res)); -#endif + #endif if (maxValue > LOOKSLIKE) maxValue = LOOKSLIKE; } @@ -211,13 +198,12 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact //Part 7, 8 res = _T(""); FindByKeywords(contactData, keywords, res/*, ures*/, isQuestion); //keywords - if (res != _T("")) - { -#ifdef DEBUG_PREFIXES - mm.insert(make_pair(LOOKSLIKE, _T("(keywords) ")+res)); -#else + if (res != _T("")) { + #ifdef DEBUG_PREFIXES + mm.insert(make_pair(LOOKSLIKE, _T("(keywords) ") + res)); + #else mm.insert(make_pair(LOOKSLIKE, res)); -#endif + #endif if (maxValue > LOOKSLIKE) maxValue = LOOKSLIKE; } @@ -231,39 +217,38 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact if (maxValue > LOOKSLIKE2) maxValue = LOOKSLIKE2; }*/ - //Part 9 + //Part 9 if (FindByOthers(contactData, otherwords, res, isQuestion)) //specialEscapes { -#ifdef DEBUG_PREFIXES - mm.insert(make_pair(BAD, _T("(otherwords) ")+res)); -#else + #ifdef DEBUG_PREFIXES + mm.insert(make_pair(BAD, _T("(otherwords) ") + res)); + #else mm.insert(make_pair(BAD, res)); -#endif + #endif if (maxValue > BAD) maxValue = BAD; } } - if (!beSilent) - { + if (!beSilent) { //Part 10 if (FindAny(contactData->escape, res)) //escape { -#ifdef DEBUG_PREFIXES + #ifdef DEBUG_PREFIXES mm.insert(make_pair(FAIL, _T("(escape) ") + res)); -#else + #else mm.insert(make_pair(FAIL, res)); -#endif + #endif if (maxValue > FAIL) maxValue = FAIL; } //Part 11 if (!understandAlways && FindAny(contactData->failure, res)) //failure { -#ifdef DEBUG_PREFIXES + #ifdef DEBUG_PREFIXES mm.insert(make_pair(FAIL, _T("(failure) ") + res)); -#else + #else mm.insert(make_pair(FAIL, res)); -#endif + #endif if (maxValue > FAIL) maxValue = FAIL; } @@ -280,26 +265,24 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage, delete[] str; ContactData *contactData = contactDatas->GetData(contact); - if (incomingMessage == contactData->lastMessage && GetTickCount() < contactData->lastMessageTime + 30 * 60 * 1000) - { + if (incomingMessage == contactData->lastMessage && GetTickCount() < contactData->lastMessageTime + 30 * 60 * 1000) { MessageInfo *info; //only 2-3 repeats - if (contactData->repeatCount < 2 || contactData->repeatCount == 2 && (rand() % 2)) - { + if (contactData->repeatCount < 2 || contactData->repeatCount == 2 && (rand() % 2)) { const vector& v = mind.GetData()->repeats; tstring res = v[rand() % v.size()]; -#ifdef DEBUG_PREFIXES + #ifdef DEBUG_PREFIXES info = new MessageInfo(incomingMessage, _T("(repeat_norm) ") + res); -#else + #else info = new MessageInfo(incomingMessage, res); -#endif + #endif } else -#ifdef DEBUG_PREFIXES + #ifdef DEBUG_PREFIXES info = new MessageInfo(incomingMessage, _T("(repeat_silence)")); -#else + #else info = new MessageInfo(incomingMessage, _T("")); -#endif + #endif if (saveChoice) RecordAnswer(contactData, *info); contactDatas->PutData(contact); @@ -310,14 +293,13 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage, Level maxValue = NOTHING; tstring res = AllReplies(incomingMessage, contactData, maxValue, mm); - if (!res.empty()) - { + if (!res.empty()) { UpdateStartChar(res); -#ifdef DEBUG_PREFIXES + #ifdef DEBUG_PREFIXES MessageInfo *info = new MessageInfo(incomingMessage, _T("(widelyused_all) ") + res); -#else + #else MessageInfo *info = new MessageInfo(incomingMessage, res); -#endif + #endif if (saveChoice) RecordAnswer(contactData, *info); contactDatas->PutData(contact); @@ -327,14 +309,13 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage, incomingMessage = ReplaceAliases(incomingMessage); res = AllReplies(incomingMessage, contactData, maxValue, mm); - if (!res.empty()) - { + if (!res.empty()) { UpdateStartChar(res); -#ifdef DEBUG_PREFIXES + #ifdef DEBUG_PREFIXES MessageInfo *info = new MessageInfo(incomingMessage, _T("(widelyused_all) ") + res); -#else + #else MessageInfo *info = new MessageInfo(incomingMessage, res); -#endif + #endif if (saveChoice) RecordAnswer(contactData, *info); contactDatas->PutData(contact); @@ -355,8 +336,7 @@ bool TalkBot::FindExact(ContactData *contactData, const tstring &incomingMessage const multimap& map, tstring& res) { int max = (int)map.count(incomingMessage); - if (!max) - { + if (!max) { TCHAR c = incomingMessage[incomingMessage.length() - 1]; if (c != _T('?') && c != _T('.') && c != _T('!')) return FindExact(contactData, incomingMessage + _T('.'), map, res); @@ -400,15 +380,12 @@ void TalkBot::SplitSectences(const tstring &incomingMessage, vector& ve //FIXME: (THINK ABOUT IT:-))these chars not always mark the end of sentence. const TCHAR symbols[] = _T(".?!"); int it = 0, len = (int)incomingMessage.length(); - while (it != len) - { + while (it != len) { while (it != len && _istspace(incomingMessage[it])) it++; int start = it; - while (it != len) - { - if (_tcschr(symbols, incomingMessage[it++])) - { + while (it != len) { + if (_tcschr(symbols, incomingMessage[it++])) { //Test for a :-! smile if (it > 2 && incomingMessage[it - 1] == _T('!') && incomingMessage[it - 2] == _T('-') @@ -427,8 +404,7 @@ void TalkBot::SplitSectences(const tstring &incomingMessage, vector& ve tstring LevelToStr(TalkBot::Level target) { tstring lev; - switch (target) - { + switch (target) { case TalkBot::BEST: lev = _T("BEST(0)"); break; case TalkBot::LOOKSLIKE: lev = _T("LOOKSLIKE(1)"); break; case TalkBot::BAD: lev = _T("BAD(2)"); break; @@ -441,12 +417,12 @@ tstring LevelToStr(TalkBot::Level target) tstring TalkBot::ChooseResult(ContactData *contactData, Level maxValue, const multimap &mm) { -#ifdef DEBUG_SHOW_VARIANTS + #ifdef DEBUG_SHOW_VARIANTS AddBotMessage(_T(">>Availabe:")); for (multimap::iterator it = mm.begin(); it != mm.end(); it++) AddBotMessage(LevelToStr((*it).first) + _T(": ") + (*it).second); AddBotMessage(_T(">>Result:")); -#endif + #endif if (maxValue == NOTHING) return _T(""); Level target = maxValue; @@ -454,30 +430,29 @@ tstring TalkBot::ChooseResult(ContactData *contactData, Level maxValue, const mu pair range = mm.equal_range(target); for (lt_cit it = range.first; it != range.second; ++it) contactData->chooser.AddChoice((*it).second); -#ifdef DEBUG_SHOW_LEVEL + #ifdef DEBUG_SHOW_LEVEL tstring lev = LevelToStr(target); return lev + _T(": ") + contactData->chooser.Choose(); -#else + #else return contactData->chooser.Choose(); -#endif + #endif } -void TalkBot::FindByKeywords(ContactData *contactData, const vector &keywords, tstring& res/*, tstring& ures*/, +void TalkBot::FindByKeywords(ContactData *contactData, const vector &keywords, tstring& res/*, tstring& ures*/, bool isQuestion) { if (keywords.size() == 0) return; const multimap &keys = isQuestion ? mind.GetData()->qkeywords : mind.GetData()->keywords; - for (multimap::const_iterator it = keys.begin(); it != keys.end(); ++it) - { + for (multimap::const_iterator it = keys.begin(); it != keys.end(); ++it) { float prio; if ((*it).first.MatchesAll(keywords/*, strict*/, prio)) -#ifdef DEBUG_SHOW_SOLUTION_REASON + #ifdef DEBUG_SHOW_SOLUTION_REASON contactData->chooser.AddChoice((tstring)(*it).first + _T(": - ") + (*it).second, prio); -#else + #else contactData->chooser.AddChoice((*it).second, prio); -#endif + #endif } res = contactData->chooser.Choose(); } @@ -488,14 +463,13 @@ bool TalkBot::FindByOthers(ContactData *contactData, const vector &othe const multimap &specs = isQuestion ? mind.GetData()->qspecialEscapes : mind.GetData()->specialEscapes; for (multimap::const_iterator it = specs.begin(); - it != specs.end(); ++it) - if ((*it).first.MatchesAny(otherwords)) - { -#ifdef DEBUG_SHOW_SOLUTION_REASON + it != specs.end(); ++it) + if ((*it).first.MatchesAny(otherwords)) { + #ifdef DEBUG_SHOW_SOLUTION_REASON contactData->chooser.AddChoice((tstring)(*it).first + _T(": - ") + (*it).second); -#else + #else contactData->chooser.AddChoice((*it).second); -#endif + #endif } res = contactData->chooser.Choose(); if (res.empty()) @@ -516,17 +490,14 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector& keywords, vector words; map sm; //Find smiles - for (size_t i = 0; i < sentence.length() - 1; i++) - { + for (size_t i = 0; i < sentence.length() - 1; i++) { unsigned max = (int)(sentence.length() - i); if (max > mind.GetData()->maxSmileLen) max = mind.GetData()->maxSmileLen; - for (unsigned j = max; j > 0; j--) - { + for (unsigned j = max; j > 0; j--) { tstring item = sentence.substr(i, j); if (mind.GetData()->smiles.find(item) - != mind.GetData()->smiles.end()) - { + != mind.GetData()->smiles.end()) { sm[i] = item; sentence.replace(i, j, _T(" ")); break; @@ -536,10 +507,8 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector& keywords, len = (int)sentence.length(); bool hadQuestionSigns = false; int it = 0; - while (it != len) - { - while (it != len && _tcschr(dividers, sentence[it])) - { + while (it != len) { + while (it != len && _tcschr(dividers, sentence[it])) { if (sentence[it] == _T('?')) hadQuestionSigns = true; map::iterator smit; @@ -551,8 +520,7 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector& keywords, break; hadQuestionSigns = false; int start = it; - while (true) - { + while (true) { while (it != len && !_tcschr(dividers, sentence[it])) it++; if (it == len || sentence[it] != _T('-')) @@ -566,18 +534,16 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector& keywords, words.push_back(str); } isQuestion = hadQuestionSigns; - for (vector::iterator it = words.begin(); it != words.end(); ++it) - { - if (!isQuestion) - { + for (vector::iterator it = words.begin(); it != words.end(); ++it) { + if (!isQuestion) { if (mind.GetData()->question.find(*it) != mind.GetData()->question.end()) isQuestion = true; } if (mind.GetData()->special.find(*it) != mind.GetData()->special.end()) otherwords.push_back(*it); -#ifdef EXCLUDE_SPECIAL_WORDS + #ifdef EXCLUDE_SPECIAL_WORDS else -#endif + #endif keywords.push_back(*it); } } @@ -595,4 +561,4 @@ void TalkBot::SetLowercase(const bool isLowercase) void TalkBot::SetUnderstandAlways(const bool understandAlways) { this->understandAlways = understandAlways; -} \ No newline at end of file +} -- cgit v1.2.3