by sebataz

In my custom chat I wanted to implement a chatbot, since it's always empty. However any solution that I found uses a complex AIML brain and a more complex implementation of the interpreter.

Since I wanted to implement my own interpreter from scratch I had to come up with a fairly simple idea. Searching the web for an implementation I came across an idea for an incredibly simple solution.

This implementation uses an array of array of replies for the brain, instead of the complex AIML; the index of the main array is a regex which will match the user's query. The interpreter cycles through the array matching the user's query against the regex of the array and then randomly chooses a reply.

In order to use this solution you need a basic knowledge of regular expression, the use of the PHP function preg_replace() and the use of references.

Here is my own implementation of the brain and the interpreter:

// the index of the array is a regular expression
// the content of the array is an array of replies
// a reply can reference matched content from user's query
$brain['\b(hello|hi|hey)\b'] = array('Hello!', 'Hi!');
$brain['how are you.*\?'] = array('I\'m fine, thx!', 'Couldn\'t be better.', 'Very well.');
$brain['are you (.*)\?'] = array('What if I am $1.', 'What does it matter what I am.', 'Would you prefer it if I was $1.', 'I may be $1, what do you think?');

// cycles through the brain array associating the index of the array to the variable $regex and the list of replies to the variable $replies
foreach ($brain as $regex => $replies) {

    // checks if the regex matches the user's query
    if (preg_match('/' . $regex . '/i',  $input)) {

        // replaces the whole user's query with a reply
        $output = preg_replace(
            '/^.*' . $regex . '.*$/i',              // expands the brain regex to match the whole query
            $replies[rand(0, count($replies)-1)],   // chooses a random reply from the list
            $input                                  // the query to replace
        // echoes the chatbot reply
        echo $output;
        // breaks the cycle after having matched a query and returned a reply

The fun starts when you have to program and test the brain for your chatbot.

by sebataz

I cünta sü che ia trovaa di toomb, probabilment da la preistoria.

In dal 1202 Gordün faseva part da la Castalderia da Claro e gha pagava ammò un censo anüal fin al 1405. In dal 1374 Gordün faseva part, con Gnosca, da una circoscrizion aministrativa sota da un Podestà milanes.

In dal 1198 sa cüntava sü da un castel, dì anca da San Carpoforo, che l'è pö stai ricostrui in dal 1402.

Al sitt gh'era già da vesig in dal medioevo, ma la prima volta che i na parla l'è in dal 1538 (comünicazion dal patriziaa). Anca chi come in altri sitt dal canton, i gent i stava prima in colina, in doa gh'era costruit i prim cà, per pö na gio in pian. Per Gordün e Gnosca al sitt in colina, che l'è pö in munt, sa ciamava Sassa, che l'è stai abandonaa in dal 1570.

I patrizi da Gordün: Andreetta, Battaglioni, Borella, Bregnoni, Brusaferri, Della Cassina, Del Don, Ghidoni, Gregori, Mancini, Meraldi, Pedrazzi, Pedrioli, Rigoni, Robbiani, Turchetti.

Swiss folk heroes

21 April 2016
by sebataz

Switzerland has seen some tough and harsh history as well, in which battles and rebellions where fought to grant the freedom of the Swiss folk.

In the midst of battle, where the bravery of one self is tested to the limit, some of our countrymen gave it all sacrificing even their own life for a single purpose.

  • Wilhelm Tell: the tale tells that he became the leader of the rebellion against the tyranny of the Austrians. He was condemned by Gessler, the Vogt of Altdorf, to shoot an apple on the head of is son because he refused to bow in front of hat. However, Wilhelm was an excellent marksman with the crossbow and split the apple with a single bolt. And so he made an example for all of his countrymen to resist and fight against the Habsburg invaders.(on wikipedia)

  • Arnold von Winkelried: during the battle of Sempach against the Habsburg, Arnold von Winkelried sacrificed himself by throwing himself upon the Austrian pikes. By doing so he opened a passage allowing the Swiss to win the battle. The last cry of Arnold went to his family: "I will open a passage into the line; protect, dear countrymen and confederates, my wife and children..." (on wikipedia)

  • Ueli Rotach: while fighting the Austrian besides his brothers in arms it is said that he was cornered into a barn. He fought with bravery to the end, even when the Austrian set fire to the barn.