Hello and welcome, Syed!
Program O uses several algorithms to accomplish the task of selecting the correct AIML category to process. First, the script “casts a wide net”, gathering all potential matches from the database, based on the current topic, what the chatbot’s most recent response was, and the user’s input is. What gets returned is a rather large array of potential matches (most of the time). This array is then passed to several functions designed to reject irrelevant entries and to assign point values to each element of the array, based on a series of ever more stringent “rules”. The remaining array is then sorted by these point values, with the element having the highest “score” becoming the selected AIML category. In the case of ties, the “winning” category is selected at random from among the remaining highest scoring entries.
All of this takes place in the file chatbot/core/aiml/find_aiml.php. In fact, that’s the entire purpose of find_aiml.php