程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了无法从用于聊天机器人的字典中获得接近匹配大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决无法从用于聊天机器人的字典中获得接近匹配?

开发过程中遇到无法从用于聊天机器人的字典中获得接近匹配的问题如何解决?下面主要结合日常开发的经验,给出你关于无法从用于聊天机器人的字典中获得接近匹配的解决方法建议,希望对你解决无法从用于聊天机器人的字典中获得接近匹配有所启发或帮助;

我正在尝试借助存储在变量“Brain”中的示例字典来开发聊天机器人应用程序,但是当我尝试输入 1 作为我的“消息”时,聊天机器人无法识别键值对.因此它会抛出“在我的知识库中找不到它”。 我附上了下面的代码,我是 Python 的新手,所以任何有关这方面的帮助将不胜感激。

from difflib import get_close_matches
from tkinter import Tk,Label,Entry,button,Text,Scrollbar,Frame
from tkinter import *


def chatbot(window):
    global message_Entry,Brain,message_position,message_session
    window.title('Elsa')
    window.geometry('375x400')
    window.resizable(0,0)
    message_session = Text(window,bd=3,relIEf="flat",Font=("Helvetica",10),undo=True,wrap="word")
    
    message_session.config(wIDth=48,height=16,bg="white",fg="black",state='Disabled')
    link9 = Label(root1,text = "Hi,I am Elsa!\n  Press '1' for VIAW \n  Press '2' for Support \n  Press '3' for Others",wIDth= 42,fg = "black",cursor = "hand2",bg = "white",justify = left,anchor="w").grID(sticky = W,column=1,row=0)
    
    overscroll = Scrollbar(window,command=message_session.yvIEw)
    overscroll.config(wIDth=20)
    message_session["yscrollcommand"] = overscroll.set
    message_position = 1.0
    send_button = button(window,text='Send',fg='white',bg='blue',wIDth=8,Font=('Arial',14),relIEf ='flat',command = reply_to_you)
    message_Entry = Entry(window,wIDth=200,Font=('Helvetica',10))
    message_Entry.bind('<Return>',reply_to_you)
    message_session.insert(END,message_Entry)
    message_session.place(x=0,y=70)
    overscroll.place(x=350,y=10)
    send_button.place(x=3,y=350)
    message_Entry.place(x=120,y=350,wIDth=245,height=35)
    Brain = {'One': 'www.Google.com','Two': 'www.two.com','Three':'www.three.com'}
    print(Brain)

def add_chat(messagE):
    global message_Entry,message_session
    message_position+=1.5
    print(message_position)
    message_Entry.delete(0,'end')
    message_session.config(state='normal')
    message_session.insert(message_position,messagE)
    message_session.see('end')
    message_session.config(state='Disabled')

    
def reply_to_you(event=NonE):
    global message_Entry,message_session,message_position
    message = message_Entry.get().lower()
    message = 'you: '+ message+'\n'
    close_match = get_close_matches(message,Brain.keys())
    print(close_match)
    if close_match:   
        reply = 'Elsa: '+ Brain[close_match[0]][0] + '\n'
    else:
        reply = 'Elsa: ' + 'Can\'t find it it in my kNowledge base\n'
    add_chat(messagE)
    add_chat(reply)

root1 = Tk()
chatbot(root1)
root1.mainloop()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的无法从用于聊天机器人的字典中获得接近匹配全部内容,希望文章能够帮你解决无法从用于聊天机器人的字典中获得接近匹配所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: