2 回答

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']]
]

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()
添加回答
舉報(bào)