From cfa936b48dfb9a8bb850ff0d3600f8860345db4a Mon Sep 17 00:00:00 2001 From: mataes2007 Date: Sat, 19 Nov 2011 19:14:29 +0000 Subject: added Boltun git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@181 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- Boltun/Engine/TalkEngine.h | 112 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Boltun/Engine/TalkEngine.h (limited to 'Boltun/Engine/TalkEngine.h') diff --git a/Boltun/Engine/TalkEngine.h b/Boltun/Engine/TalkEngine.h new file mode 100644 index 0000000..364f419 --- /dev/null +++ b/Boltun/Engine/TalkEngine.h @@ -0,0 +1,112 @@ +//*********************************************************** +// Copyright © 2008 Valentin Pavlyuchenko +// +// This file is part of Boltun. +// +// Boltun is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Boltun is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Boltun. If not, see . +// +//*********************************************************** + +#ifndef TalkEngineH +#define TalkEngineH + +#include "Mind.h" +#include "ValueChooser.h" +#include "PerContactData.h" +#include "UnrecentChooser.h" + +class TalkBot +{ +public: + struct MessageInfo + { + private: + tstring Question; + MessageInfo(tstring q, tstring a) + :Question(q), Answer(a) + { + } + public: + tstring Answer; + MessageInfo(tstring q) + :Question(q) + { + } + friend class TalkBot; + }; +private: + typedef enum + { + BEST, LOOKSLIKE/*, LOOKSLIKE2*/, BAD, FAIL, NOTHING + } Level; + friend tstring LevelToStr(TalkBot::Level target); + + struct ContactData + { + ValueChooser<> initial; + //ValueChooser > question; + //ValueChooser > special; + ValueChooser<> escape; + ValueChooser<> failure; + UnRecentChooser chooser; + tstring lastMessage; + long long lastMessageTime; + int repeatCount; + inline ContactData(const Mind& mind) + :initial(mind.GetData()->initial), + //question(mind.GetData()->question), + //special(mind.GetData()->special), + escape(mind.GetData()->escape), + failure(mind.GetData()->failure), + repeatCount(0) + { + } + }; + + PerContactData* contactDatas; + const Mind mind; + bool beSilent; + bool makeLowercase; + bool understandAlways; + void UpdateStartChar(tstring& str); + typedef std::multimap::const_iterator mm_cit; + bool FindExact(ContactData* contactData, const tstring &incomingMessage, + const std::multimap& map, tstring& res); + bool FindAny(ValueChooser<> &ch, tstring& res); + void FindByKeywords(ContactData* contactData, const std::vector &keywords, tstring& res/*, tstring& ures*/, bool isQuestion); + bool FindByOthers(ContactData* contactData, const std::vector &otherwords, tstring& res, bool isQuestion); + tstring AllReplies(const tstring &incomingMessage, ContactData* contactData, Level &maxValue, std::multimap &mm); + tstring ReplaceAliases(const tstring &message); + tstring ChooseResult(ContactData* contactData, Level maxValue, const std::multimap &mm); + void RecordAnswer(ContactData *contactData, const TalkBot::MessageInfo& info); +#ifdef _DEBUG +public: +#endif + void SplitSectences(const tstring &incomingMessage, std::vector& vec); + void SplitAndSortWords(tstring sentence, std::vector& keywords, + std::vector& otherwords, bool& isQuestion); +public: + TalkBot(const Mind& goodMind); + ~TalkBot(); + const Mind& GetMind() const; + void SetSilent(const bool isSilent); + void SetLowercase(const bool isLowercase); + void SetUnderstandAlways(const bool understandAlways); + //const MindData *GetData(); + tstring GetInitMessage(void* contact); + MessageInfo* Reply(void* contact, const tstring incomingMessage, bool saveChoice); + void AnswerGiven(void* contact, const MessageInfo& info); +}; + +#endif -- cgit v1.2.3