作为一个“边做边学”项目,我正在尝试构建一个简单的人工智能,它通过适当的功能响应关键字(如“日期”)和短语(如“明天天气”)。它对简单的关键词很有用,但似乎找不到短语
我已经试过了。去掉这个命令,但是没有找到任何东西
from basics_jarvis import *
jarvis_functions = {
"date": lambda: todays_date(), #These are functions from a different .py
"datum": lambda: todays_date(),
"weather": lambda: weather_today(),
"weather tomorrow": lambda: weather_tomorrow(),
"tomorrows weather": lambda: weather_tomorrow(),
"What do you think?": lambda: print("Im not an AI, I dont think")
}
Loop = True
while Loop:
command = input("Awaiting orders \n")
for keyword in command.split(): #.strip just breaks the code
if keyword in jarvis_functions:
print(jarvis_functions[keyword]())
我试图让程序在一个完整的句子中注册一个关键短语(例如“明天的天气”),例如“嘿,明天的天气怎么样?”如果可能的话,还可以比较关键词和短语,并给短语优先级,因为一个合适的短语比一个关键词更准确
这是我第一次在这里发帖,所以我为我犯的任何错误道歉!我愿意接受任何形式的批评!提前谢谢
我在您当前的代码中添加了一些打印语句来说明这个问题:
结果输出为:
如您所见,该命令被拆开,
tomorrows
和weather
不再在一起相反,我建议迭代这些关键字,看看它们是否出现在命令中。也许是这样:
产出将是:
我希望这能让你找到正确的解决办法
这将计算最佳匹配密钥:
相关问题 更多 >
编程相关推荐