2 回答

TA贡献2051条经验 获得超10个赞
发生错误是因为配对列表在第一个索引中有 3 个项目,而[(re.compile(x, re.IGNORECASE), y) for (x, y) in pairs] 语句期望有 2 个项目。
所以你可以试试
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贡献2037条经验 获得超6个赞
例如,我有一个问题;
众所周知,这是基本代码(当然是缩写):
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()
我们想按如下方式组织代码。当提出我们确定的问题时,它会采取行动。例如,在网站或类似网站上进行搜索。
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()
我们实际上想要这个。能够干扰 chat.converse()
添加回答
举报