r/programminghelp • u/pngpngpng • Aug 24 '16
PROLOG CHATBOT
Hello, I'm planning to make a chatbot using prolog. I know a bit about prolog, but I have a hard time coding on a chatter. Do you have any sample? Anything is a big help. Thanks in advance.
4
Upvotes
1
u/zmonx Aug 24 '16
I have one tip: You can regard a chatbot as a sequence of state transitions:
In a case of a chat bot, the state can for example describe which questions and answers have already taken place, i.e., the state is simply the history of the interaction.
So, in this concrete case, you can for example represent a single such state as a list of elements of the form:
question(Q)answer(A)So you have for example:
Now the point: You should focus on describing the relation between two successive states of such an interaction. Begin with a Prolog predicate that is called for example:
This is a relation between:
the current state
State0an
Actionthat needs to be performed nextthe resulting new state
State.For example, one of the clauses may be:
This describes what the chatbot will do if no history at all is currently present, i.e., the list that represents the history of states is empty.
Next, we make the rules depend on what occurred in the immediately preceding state. For example, if it was a question by the chatbot, then the next action must be to query the user. There are many ways to do this, for example:
If the previous state was a user answer, then we need to formulate a new question:
Now the point: Once you have such a declarative description of state transitions, you can define the actual interaction simply as a sequence of such transitions:
Where you start with
?- interaction([]).. I hope this gets you started. Good luck with your project!