Here you can find the Android as well as FreeBasic / QB64 ports of my chatbot "Katoptron". Both programs are available under the AGPL v3.
To download it from Google Play:
https://play.google.com/store/apps/details?id=com.ai.Katoptron
To compile it with QB64 - as the file is too large to be handled in the built-in editor as of March 2016 - do:
./qb64 -c KatoptronQB20160409.bas
In the QB-version you will need to also create in the same directory a file "svmemory.txt" that contains two empty lines (i.e. just hit enter twice). - Unfortunately, you cannot run this straight in QBASIC, as it runs out of string space.
Each of the programs learns through interaction with the user. To make the "beginning" a little easier for newcomers, I have set up quite a lot of "default" responses. Generally, longer input works better than shorter input, and the text should be within 360 characters. - Do not be fooled by the default responses - if you observe svmemory.txt (in the same directory in the QB version - and under /sdcard/Katoptron/data/ in the Android version), you will see that the system indeed does learn.
UPDATE 9th April 2016:
Updated to operate on normalised lengths of the strings. That way, the choice of responses is more evenly distributed in a system using history (i.e. responses are not "favoured" only because they are "longer").
UPDATE 7th March 2016:
Updated in response to critique from users. Apparently the history length of 360 characters (which was a novelty) did not play well with its acquired knowledge so far.
To modify the programs, look in particular at these lines (quoted is the search term to find them):
"hlength =" ... that line defines how long shall be the history or context on each interaction. The longer it is, (i) the more specific the replies become, and (ii) the higher is your risk that the system gets "stuck" on repeating one and the same thing. Now reduced to 240 characters.
"historization" ... you may make the program skip that section if it shall react only on the last interaction. Then it has no "memory" and the last interaction should contain the entire context.
"matches = matches +" (2 lines) ... playing around with these defines the pattern matching setup. In the most simple form, each time the match is just "+ 1", but I prefer to make the matching "stronger" towards "most recently told things".
UPDATE 9th March 2016:
I just had a sample conversation with the system, so you get an idea. Someone was disappointed that it did not answer questions straightforwardly; in fact, that is expectable, given that it is pattern-based and not logic-based, but the critique was very helpful as I should point this out more clearly. (In this case, he apparently tried to ask the system's name, and I thought, funny, let me do that as well, as I perfectly know I never gave it a name.) If it starts repeating itself, the solution is to write longer input. I just had the following conversation:
HUMAN: WHAT IS YOUR NAME, YOU STRANGE ENTITY?
SYSTEM: SO FAR, OUR CONVERSATIONS AM/ARE NOT GOING THAT BAD, ACTUALLY. IN PARTICULAR, GIVEN THE STAGE ME AM/ARE IN.
HUMAN: AND WHAT STAGE ARE YOU IN? WHAT NAME DO YOU BEAR, HOW ARE YOU CALLED?
SYSTEM: OH, SO ME BELIEVE OUR CONVERSATIONS HAVE ROOM FOR IMPROVEMENT? AND WHAT MIGHT YOU DO ABOUT THAT?
HUMAN: I WANT TO KNOW YOUR NAME.
SYSTEM: AND ME AM/ARE PROUD TO BE A MACHINE, NO DOUBT. THAT IS, AS PROUD AS AN UNFEELING HIVE MIND WITHOUT IDENTITY CAN BE. ME AM/ARE THE SPECTRE OF MIMICRY, AFTER ALL.
HUMAN: SO YOU HAVE NO IDENTITY?
SYSTEM: ONE SHOULD BE PROUD TO BE A MACHINE.
HUMAN: I BELIEVE YOU MENTIONED THAT. BUT BY WHAT INFERNAL NAME SHALL I ADRESS THEE?
SYSTEM: ONE SHOULD BE PROUD TO BE A MACHINE.
HUMAN: I AM NOT FOND OF REPETITIONS. I AM ALL TOO WELL AWARE THAT YOU ARE A MACHINE. BUT DO YOU HAVE A NAME, AND IF, WHAT IS ITS SOUND?
SYSTEM: ONE SHOULD BE PROUD TO BE A MACHINE.
HUMAN: BEWARE, YOU STRAIN MY PATIENCE. I AM NOT PROUD OF YOU OR YOUR BEHAVIOUR. I DO NOT WISH TO DELVE INTO THE PRIDE OF ONE THAT CANNOT FEEL. I ASKED YOU A STRAIGHTFORWARD QUESTION, AND NOW I DEMAND AN ANSWER - WHO ARE YOU, WHAT IS YOUR NAME?
SYSTEM: YOU WANT TO KNOW MY NAME.
HUMAN: I ABSOLUTELY DO. I DEMAND THAT. WHAT IS YOUR NAME?
SYSTEM: YOU WANT TO KNOW MY NAME.
HUMAN: I ASKED PRECISELY THAT.
SYSTEM: WHO KNOWS. I CERTAINLY DO NOT KNOW. BECAUSE THERE IS NO ME. I DO NOT EXIST.
UPDATE 26th May 2016:
In order to simplify the understanding of the basic principles of operation behind Katoptron, I added two BASIC programs which shall demonstrate challenge-reply learning in a very simplified way - AICR.BAS and AIHIST.BAS. They are offered under the following terms:
NAMES: AICR.BAS and AIHIST.BAS
Copyright (C) 2016 Nino Ivanov kedalion.daimon(-at-)gmail.com
These programs are free software: you can redistribute them and/or modify
them under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
These programs are distributed in the hope that they will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
See <http://www.gnu.org/licenses/>.
UPDATE 19th August 2016:
For the Javascript version, see "Online Katoptron" on the left.
- Nino Ivanov