예제 #1
0
class ChitChat(object):
    def __init__(self):
        self.BOT_PREDICATES = {
            "name": "KanoBot",
            "birthday": "January 1st 1969",
            "location": "London",
            "master": "Judoka",
            "website": "https://github.com/brandonjackson/make-chatterbot",
            "gender": "",
            "age": "",
            "size": "",
            "religion": "",
            "party": ""
        }

        self.DEVNULL = open(os.devnull, 'wb')

        self.k = MyKernel()

        # Load the AIML files on first load, and then save as "brain" for speedier startup
        if os.path.isfile("cache/standard.brn") is False:
            self.k.learn("aiml/standard/std-startup.xml")
            self.k.respond("load aiml b")
            self.k.saveBrain("cache/standard.brn")
        else:
            self.k.loadBrain("cache/standard.brn")

        # Give the bot a name and lots of other properties
        for key, val in self.BOT_PREDICATES.items():
            self.k.setBotPredicate(key, val)

# Start Infinite Loop

    def chat(self, sentence):
        # Prompt user for input
        #     input = raw_input("> ")
        input = sentence
        # Send input to bot and print chatbot's response
        matchedPattern = self.k.matchedPattern(
            input)  # note: this has to come before the
        # call to respond as to reflect
        # the correct history
        response = self.k.respond(input)
        return response
예제 #2
0
파일: cronus.py 프로젝트: herrkami/cronus
while True:
    # Prompt user for input
    setEyes(0)
    #input = raw_input("> ")
    with sr.Microphone(device_index=2) as source:
        audio_input = recognizer.listen(source)
    try:
        input = recognizer.recognize(audio_input)
    except LookupError:
        input = 'Kauderwelsch'
    print( input )
    setEyes(1)
    setHead(int(np.random.uniform(-25, 25)))

    # Send input to bot and print chatbot's response
    matchedPattern = k.matchedPattern(input) # note: this has to come before the 
                                             # call to respond as to reflect
                                             # the correct history
    response = k.respond(input)
    if SHOW_MATCHES:
        print "Matched Pattern: "
        print k.formatMatchedPattern(matchedPattern[0])
        print "Response: "
    if not PRESENTATION_MODE:
        print response

    # Output response as speech using espeak
    if TTS_ENABLED is False:
        pass
    elif TTS_ENGINE == "espeak":
        subprocess.call(["espeak", "-s", str(TTS_SPEED), "-v", TTS_VOICE,
예제 #3
0
                elif (part_speech == 'VERB'):
                    word = wn.morphy(i[0], wn.VERB)
                elif (part_speech == 'ADV'):
                    word = wn.morphy(i[0], wn.ADV)
                elif (part_speech == 'ADJ'):
                    word = wn.morphy(i[0], wn.ADJ)
                word1 = wn.synsets(word)[0].lemmas()[0].name()
                if i[0] in grade_codes:
                    word1 = i[0]
            except:
                word1 = i[0]
            new_sentence = new_sentence + " " + word1.lower()
            new_sentence = remove_aiml_char(new_sentence)

        if DEBUG:
            matchedPattern = k.matchedPattern(myinput)
            response = k.respond(myinput)
            try:
                if SHOW_MATCHES:
                    print "Matched Pattern: "
                    print k.formatMatchedPattern(matchedPattern[0])
                    pattern = k.getPredicate("topic", '_global')
                    print "TOPIC:", pattern
                else:
                    print "-------------------------"
            except:
                print "No match found"
            print "Normal Response: ", response
            print "--------------------------------"
            print "new_sentence :", new_sentence
            matchedPattern = k.matchedPattern(new_sentence)
예제 #4
0
    k.respond("load aiml b")
    k.saveBrain("cache/standard.brn")
else:
    k.loadBrain("cache/standard.brn")

# Give the bot a name and lots of other properties
for key, val in BOT_PREDICATES.items():
    k.setBotPredicate(key, val)

# Start Infinite Loop
while True:
    # Prompt user for input
    input = raw_input("> ")

    # Send input to bot and print chatbot's response
    matchedPattern = k.matchedPattern(
        input)  # note: this has to come before the
    # call to respond as to reflect
    # the correct history
    response = k.respond(input)
    if SHOW_MATCHES:
        print "Matched Pattern: "
        print k.formatMatchedPattern(matchedPattern[0])
        print "Response: "
    print response

    # Output response as speech using espeak
    if TTS_ENABLED is False:
        pass
    elif TTS_ENGINE == "espeak":
        subprocess.call([
            "espeak", "-s",