How to make Artificial Intelligence chatbot in linux

Thanks God for the python.
Make simple chat boot in linux with AI is very simple.
You need python2.6 and PyAmil(PyAIML is an interpreter for AIML, the Artificial Intelligence Markup)

import aiml
import commands
import sys
import time 
import commands
from os import system
import marshal # sesje 
import os.path

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    BLACK = '\033[36m'
    RED =  '\033[31m'
    GREEN =  '\033[32m'
    BLUE =  '\033[34m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'

    def disable(self):
        self.HEADER = ''
        self.OKBLUE = ''
        self.OKGREEN = ''
        self.WARNING = ''
        self.FAIL = ''
        self.ENDC = ''

k = aiml.Kernel()

# read dictionary and create brain in file czerep.brp

if os.path.isfile(czerep):
    k.bootstrap(brainFile = czerep)
    #Change to the directory whe	re the AIML files are located
    os.chdir('./dic') # going to dictionary
    for item in list: #load dictionary one by one 
    #Change back to homedir to save the brain for subsequent loads
    k.saveBrain(czerep) # save new brain
# name of bot
k.setBotPredicate('name', "Hal 9000")
os.system('fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1)')# welcome cowsay is not importan you can del this
while True:
    input = raw_input("[YOU		]" )
# close bot if you use onely spell quit
    if input == "quit":
# end of new code
    response = k.respond(input)
    # print out on the shell
    print bcolors.BLACK+"[   		]"+bcolors.WARNING+response+bcolors.ENDC

And you need Knowledge base
fieles amil you unzi or untar to directory ./dic . And start the chat 😀
Nex article try show how make knowledge base 🙂 in amilxml 🙂


2 Comments Add yours

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s