Example #1
0
class DialogueManager(object):
    def __init__(self):
        print("Loading resources...")

        self.chatbot = ChatBot()

    def generate_answer(self, question):
        question = utils.text_prepare(question)
        response = self.chatbot.get_response(question)

        return response
Example #2
0
def main():

    eliza = ChatBot(["dialogue/overheard.json", "dialogue/responses.json"],
                    "categories")

    print("Enter 'quit' to quit")
    input_string = input("[User input]: ")

    while input_string != QUIT:
        if input_string == RELOAD:
            eliza = ChatBot("responses.json")
            print("Bot reloaded.")
        else:
            response = eliza.get_response(input_string)
            print(response)

        input_string = input("[User input]: ")
from os import sys, path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))

from chatbot import ChatBot

bot = ChatBot(
    "Math & Time Bot",
    logic_adapters=[
        "chatbot.adapters.logic.EvaluateMathematically",
        "chatbot.adapters.logic.TimeLogicAdapter"
    ],
    io_adapter="chatbot.adapters.io.NoOutputAdapter",
)

# Print an example of getting one math based response
response = bot.get_response("What is 4 + 9?")
print(response)

# Print an example of getting one time based response
response = bot.get_response("What time is it?")
print(response)

# Print an example of getting one time based response
response = bot.get_response("do you know the time")
print(response)

# Print an example of getting one time based response
response = bot.get_response("i had a great time")
print(response)

# Print an example of getting one time based response
'''
In this example we use a while loop combined with a try-except statement.
This allows us to have a conversation with the chat bot until we press
ctrl-c or ctrl-d on the keyboard.
'''

while True:
    try:
        '''
        ChatBot's get_input method uses io adapter to get new input for
        the bot to respond to. In this example, the TerminalAdapter gets the
        input from the user's terminal. Other io adapters might retrieve input
        differently, such as from various web APIs.
        '''
        user_input = chatbot.get_input()

        '''
        The get_response method also uses the io adapter to determine how
        the bot's output should be returned. In the case of the TerminalAdapter,
        the output is printed to the user's terminal.
        '''

        #bot_input = chatbot.get_response(user_input)
        user_location = "latitude:42.1386410 longitude:-71.2474770"   #Walpole
        #user_location = "latitude:17.3850 longitude:78.4867"         #Hyderabad
        bot_input = chatbot.get_response(user_input, user_location)

    except (KeyboardInterrupt, EOFError, SystemExit):
        break

# To make this Python 2.x compatible, replace the print() with print "enter print text here"
print(user_input)

'''
In this example we use a while loop combined with a try-except statement.
This allows us to have a conversation with the chat bot until we press
ctrl-c or ctrl-d on the keyboard.
'''

while True:
    try:
        '''
        chatbot's get_input method uses io adapter to get new input for
        the bot to respond to. In this example, the NoOutputAdapter gets the
        input from the user's terminal. Other io adapters might retrieve input
        differently, such as from various web APIs.
        '''
        user_input = bot.get_input()

        '''
        The get_response method also uses the io adapter to determine how
        the bot's output should be returned. In the case of the NoOutputAdapter,
        the output is not printed to the terminal.
        '''
        bot_input = bot.get_response(user_input)

        print(bot_input)

    except (KeyboardInterrupt, EOFError, SystemExit):
        break
chatbot = ChatBot("HiBot", read_only=False,
    #storage_adapter="chatbot.adapters.storage.JsonDatabaseAdapter",
    storage_adapter="chatbot.adapters.storage.MongoDatabaseAdapter",
    logic_adapters=[
        "chatbot.adapters.logic.AttributeLogicAdapter",
        "chatbot.adapters.logic.EvaluateMathematically",
        "chatbot.adapters.logic.WeatherLogicAdapter",
        "chatbot.adapters.logic.TimeLogicAdapter",
        "chatbot.adapters.logic.ClosestMatchAdapter"
    ],
    pyowm_api_key="cf798079c1e5c638a93cc16cff6d7171",
    database="chatterbot-database")
'''

## This is needed to create database if does not already exists
response = chatbot.get_response("")

#question = "WHO AM I"
#question = "do you like cats"
question = "Hello"
print("[User]: " + question)
chatbot.get_response(question)

'''
question = "Learn my name is Mike"
print("[User]: " + question)
chatbot.get_response(question)

question = "Learn my age is 25"
print("[User]: " + question)
chatbot.get_response(question)
from os import sys, path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))

from chatbot import ChatBot

chatbot = ChatBot("HiBot", read_only = True,
    storage_adapter="chatbot.adapters.storage.JsonDatabaseAdapter",
    logic_adapters=[
        "chatbot.adapters.logic.EvaluateMathematically",
        "chatbot.adapters.logic.TimeLogicAdapter",
        "chatbot.adapters.logic.ClosestMatchAdapter"
    ])

# Train based on the english corpus
#chatbot.train("chatbot.corpus.english")
chatbot.train("chatbot.corpus.english.greetings")
#chatbot.train("chatbot.corpus.english.conversations")
#chatbot.train("chatbot.corpus.english.trivia")

# Get a response to an input statement
chatbot.get_response("Hello I am a robot....@Qe3")


#chatbot.get_response("What time is it")
from chatbot import ChatBot

bot = ChatBot("Movie Bot", read_only=False,
        logic_adapters=[
            "chatbot.adapters.logic.AttributeLogicAdapter",
            "chatbot.adapters.logic.TimeLogicAdapter",
            "chatbot.adapters.logic.MovieLogicAdapter",
            "chatbot.adapters.logic.ClosestMatchAdapter"
        ],

        io_adapter="chatbot.adapters.io.NoOutputAdapter",
        database="database_movie.db"
)

response = bot.get_response("")


question = "what movies are playing in Dallas"
print("\n[User]: " + question)
response = bot.get_response(question)
print(response)

question = "recommend a movie for me"
print("[User]: " + question)
response = bot.get_response(question)
print(response)


question = "learn my gender is female"
print("\n[User]: " + question)
from chatbot import ChatBot

bot = ChatBot("Math & Time Bot", read_only=False,
        logic_adapters=[
            "chatbot.adapters.logic.TimeLogicAdapter",
            "chatbot.adapters.logic.WeatherLogicAdapter",
            "chatbot.adapters.logic.ClosestMatchAdapter"
        ],

        io_adapter="chatbot.adapters.io.NoOutputAdapter",
        pyowm_api_key="cf798079c1e5c638a93cc16cff6d7171",
        database="database_weather.db"
)

response = bot.get_response("")

#response = bot.get_response("whats the weather")
#print("\n"+response)

#response = bot.get_response("what time is it")
#print("\n"+response)

response = bot.get_response("whats the weather in Boston today")
print("\n"+response)

response = bot.get_response("whats the extended weather in Dallas today")
print("\n"+response)

'''
response = bot.get_response("whats my forecast")