The ChatBot creates a dialogue where users can ask questions about some aspects of memory management in C++. After the knowledge base of the chatbot has been loaded from a text file, a knowledge graph representation is created in computer memory, where chatbot answers represent the graph nodes and user queries represent the graph edges. After a user query has been sent to the chatbot, the Levenshtein distance is used to identify the most probable answer. This project uses raw pointers to represent the knowledge graph and interconnections between objects.
- Clone this repo.
- Make a build directory in the top level directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./membot
.
src -
| `chatgui.h` / `chatgui.cpp`
| `chatlogic.h` / `chatlogic.cpp`
| `chatbot.h` / `chatbot.cpp`
| `graphnodes.h` / `graphnodes.cpp`
| `graphedges.h` / `graphedges.cpp`
-
chatgui.h
/chatgui.cpp
: In filechatgui.h
/chatgui.cpp
, this makes_chatLogic
an exclusive resource to classChatbotPanelDialog
using a smart pointer. -
chatbot.h
/chatbot.cpp
:ChatBot
complies with the Rule of Five such as Chatbot constructor methods which allocate / deallocate memory resources on the heap and also copy member data. When sending a query to the ChatBot, it prints a string of the type e.g. "ChatBot Copy Constructor" to the console. Rule of five mehtods are as follows:- ChatBot Constructor/Destructor
- ChatBot Move Constructor
- ChatBot Move Assignment Operator
- ChatBot Copy Constructor
- ChatBot Copy Assignment Operator
-
chatlogic.h
/chatlogic.cpp
:- adapt the vector
_nodes
in a way that the instances ofGraphNodes
to which the vector elements refer are exclusively owned by the classChatLogic
. - create a local
ChatBot
instance on the stack at the bottom of functionLoadAnswerGraphFromFile
. - pass the
ChatBot
instance into the root node by using move semantics. ChatLogic
has no ownership relation to theChatBot
instance and thus is no longer responsible for memory allocation and deallocation- the
ChatBot
instance (_chatBot
) is used as a communication handle between GUI andChatBot
instance. - When passing the
GraphNode
instances to functions, contains the changes to classChatLogic
.
- adapt the vector
-
graphnodes.h
/graphnodes.cpp
- each instance of
GraphNode
exclusively owns the outgoingGraphEdges
and holds non-owning references to incomingGraphEdges
with smart pointers. - When transferring ownership from class
ChatLogic
, where all instances ofGraphEdge
are created, into instances ofGraphNode
, use move semantics.
- each instance of
start | end |
---|---|
- cmake >= 3.11
- make >= 4.1
- gcc/g++ >= 5.4
- wxWidgets >= 3.0, wxWidgets Binary