Python AI中的错误
我目前正在用Python编写一个人工智能程序,其中包含一些来自ELIZA的基本代码。我将改进代码,一旦我得到它的工作。我的问题是,当我运行程序并向计算机输入查询时,没有响应。我的代码如下Python AI中的错误,python,artificial-intelligence,Python,Artificial Intelligence,我目前正在用Python编写一个人工智能程序,其中包含一些来自ELIZA的基本代码。我将改进代码,一旦我得到它的工作。我的问题是,当我运行程序并向计算机输入查询时,没有响应。我的代码如下 import string # OSWALD v1.0 switch = [ ["I need \(.*\)", [ "Why do you need %1?", "Would it REALLY help you to get %1?", "Are you sure you need
import string
# OSWALD v1.0
switch = [
["I need \(.*\)",
[ "Why do you need %1?",
"Would it REALLY help you to get %1?",
"Are you sure you need %1?"]]
#There is more code with responses.
]
gPats = {
"am" : "are",
"was" : "were",
"i" : "you",
"i'd" : "you would",
"i've" : "you have",
"i'll" : "you will",
"my" : "your",
"are" : "am",
"you've": "I have",
"you'll": "I will",
"your" : "my",
"yours" : "mine",
"you" : "me",
"me" : "you",
}
s = input
gKeys = map(lambda x:regex.compile(x[0]),gPats)
gValues = map(lambda x:x[1],gPats)
print ("Hello, mortal. My name is Oswald. What would you like to talk about?")
while s == input:
try: s = input(">")
def translate(str,dict):
words = string.split(string.lower(str))
keys = dict.keys();
for i in range(0,len(words)):
if words[i] in keys:
words[i] = dict[words[i]]
return print(switch)
def respond(str,keys,values):
for i in range(0,len(keys)):
if input == input:
respnum = whrandom.randint(0,len(values[word])-1)
resp = values[i][respnum]
pos = string.find(resp,'%')
print(string.find(resp,'%'))
while pos > -1:
num = string.atoi(resp[pos+1:pos+2])
resp = resp[:pos] + \
translate(keys[i].group(num),gReflections) + \
resp[pos+2:]
pos = string.find(resp,'%')
if resp[-2:] == '?.': resp = resp[:-2] + '.'
if resp[-2:] == '??': resp = resp[:-2] + '?'
print(string.find(resp,'%'))
如果我是你,我想知道示例中的所有代码是否都是严格必需的……好的。谢谢。很抱歉。你知道哪里有问题吗?是的,你可能想阅读这篇文章并编辑你的问题。谢谢。这是我的第一篇博文,我感谢你们的帮助。乍一看:可能不必是
input==input
,但input==input()
?