第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 Python Chatbot 中成對(duì)調(diào)用打印函數(shù)時(shí)出現(xiàn)值錯(cuò)誤

在 Python Chatbot 中成對(duì)調(diào)用打印函數(shù)時(shí)出現(xiàn)值錯(cuò)誤

躍然一笑 2023-02-07 11:10:45
我正在研究聊天機(jī)器人。但是在成對(duì)使用功能鏈接時(shí),出現(xiàn)了一些錯(cuò)誤。我想在列表中打印主題。在用戶可以選擇所需的主題之后。但是在打印主題時(shí),出現(xiàn)了一些我可以解決的問(wèn)題解決。from nltk.chat.util import Chat, reflectionsfrom tkinter import *import reimport numpy as npsubjectAreaList = ["subject1","subjec2","subject3"]    def listSubjectArea():    i = 1    for a in subjectAreaList:        print(i,". ",a)        i = i + 1                pairs = [    ['i want to see reports', ['In which subject area would you like to see the reports?'],listSubjectArea()],    ['subject1(.*)', ['blah blah blah']],    ['subject2(.*)', ['blah blah blah']],    ['subject3(.*)', ['blah blah blah']]]reflections = {    'i am' : 'you are',    'i was' : 'you were',    'i': 'you'}chat = Chat(pairs, reflections)print("Hi,What do you want to do ?")chat.converse(quit='by')但是我得到了這個(gè)錯(cuò)誤:Traceback (most recent call last):  File "c:/Projects/demo.py", line 71, in <module>    chat = Chat(pairs, reflections)  File "C:\Python38-32\lib\site-packages\nltk\chat\util.py", line 52, in __init__    self._pairs = [(re.compile(x, re.IGNORECASE), y) for (x, y) in pairs]  File "C:\Python38-32\lib\site-packages\nltk\chat\util.py", line 52, in <listcomp>    self._pairs = [(re.compile(x, re.IGNORECASE), y) for (x, y) in pairs]ValueError: too many values to unpack (expected 2)我找不到為什么會(huì)返回錯(cuò)誤。我檢查我的循環(huán)但沒(méi)有任何變化。
查看完整描述

2 回答

?
侃侃無(wú)極

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊

發(fā)生錯(cuò)誤是因?yàn)榕鋵?duì)列表在第一個(gè)索引中有 3 個(gè)項(xiàng)目,而[(re.compile(x, re.IGNORECASE), y) for (x, y) in pairs] 語(yǔ)句期望有 2 個(gè)項(xiàng)目。

所以你可以試試


 pairs = [

    ['i want to see reports', [['In which subject area would you like to see the reports?'],listSubjectArea()]],

    ['subject1(.*)', ['blah blah blah']],

    ['subject2(.*)', ['blah blah blah']],

    ['subject3(.*)', ['blah blah blah']]

]

或者


pairs = [

    ['i want to see reports', ['In which subject area would you like to see the reports?',listSubjectArea()]],

    ['subject1(.*)', ['blah blah blah']],

    ['subject2(.*)', ['blah blah blah']],

    ['subject3(.*)', ['blah blah blah']]

]


查看完整回答
反對(duì) 回復(fù) 2023-02-07
?
阿晨1998

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊

例如,我有一個(gè)問(wèn)題;


眾所周知,這是基本代碼(當(dāng)然是縮寫(xiě)):


from nltk.chat.util import Chat, reflections



pairs = (

    (

        r"I need (.*)",

        (

            "Why do you need %1?",

            "Would it really help you to get %1?",

            "Are you sure you need %1?",

        ),

    ),

    (

        r"Why don\'t you (.*)",

        (

            "Do you really think I don't %1?",

            "Perhaps eventually I will %1.",

            "Do you really want me to %1?",

        ),

    )

)


    

reflections = {

    "i am": "you are",

    "i was": "you were",

    "i": "you",

    "i'm": "you are"

}





def chatty():

    print("Hi, how are you?") #default message at the start

    chat = Chat(pairs, reflections)

    chat.converse()

    


if __name__ == "__main__":

    chatty()

我們想按如下方式組織代碼。當(dāng)提出我們確定的問(wèn)題時(shí),它會(huì)采取行動(dòng)。例如,在網(wǎng)站或類似網(wǎng)站上進(jìn)行搜索。


from nltk.chat.util import Chat, reflections

from googlesearch import search



gs=search(Chat)



pairs = (

    (

        r"I need (.*)",

        (

            "Why do you need %1?",

            "Would it really help you to get %1?",

            ((gs)+"%1?"),

        ),

    ),

    (

        r"Why don\'t you (.*)",

        (

            "Do you really think I don't %1?",

            "Perhaps eventually I will %1.",

            "Do you really want me to %1?",

        ),

    )

)


    

reflections = {

    "i am": "you are",

    "i was": "you were",

    "i": "you",

    "i'm": "you are"

}






def chatty():

    print("Hi, how are you?")

    chat = Chat(pairs, reflections)

    chat.converse()

    


if __name__ == "__main__":

    chatty()

我們實(shí)際上想要這個(gè)。能夠干擾 chat.converse()


查看完整回答
反對(duì) 回復(fù) 2023-02-07
  • 2 回答
  • 0 關(guān)注
  • 177 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)