0

我正在开发名为 Chatterbot 的 Python 库。当我收到回复时,如何以编程方式增加对它的信心,以便在再次向其发布相同类型的问题时它会回答相同的答案。简而言之,我应该如何告诉聊天机器人这是正确的答案,而这不是正确的答案,否则它将假设错误答案是正确的答案并增加对它的信心。供您参考,我能够获得回复的信心,但信心的增加不起作用,因为它每次都表现出相同的信心。我的代码如下 -

while True:
    request = str(input(username+": "))
    list_of_words = request.split(' ')
    for i in list_of_words:
        if i in happy_list:
            happy_count += 1
        elif i in sad_list:
            sad_count += 1
    if request.strip() != 'bye' and request.strip() != 'Bye' and request.strip() != 'ok bye' and request.strip() != 'see you' and request.strip() != 'see ya':
        response = bot.get_response(request)
        print("Joe: ",response)
        print(response.confidence)
        response.confidence = response.confidence + 0.1
        if happy_count >= 4 or sad_count >= 4:
            if happy_count >= 4:
                print("Joe: You seems to be very happy today",username)
                happy_count = 0
            elif sad_count >=4:
                print("Joe: What happened? Are you upset",username,"?")
                sad_count = 0
    else:
        print("Joe: Ya taddah")
        break
4

1 回答 1

0

我认为这有效-->

class mdy:
def __init__(self, msg, rep):
    self.msg = msg
    self.rep = rep

def match(self):
    lowMsg = self.msg.lower()
    lowRep = self.rep.lower()
    lenMsg = len(self.msg.split(' '))
    lenRep = len(self.rep.split(' '))
    count = 0

    # Count
    for i in lowMsg.split(' '):
        if i in lowRep.split(' '):
            count = count + 1
    # Math
    percent = int(count/lenRep*100)
    if percent >= 60:
        return True
    else:
        return False

但不要使用回复,而是使用问题:-)

于 2018-10-02T17:27:32.550 回答