2016-08-16 66 views
0

當我運行腳本時,我開始一個使用AIML的Python項目它給了我一個'找不到匹配'的錯誤。這是Python代碼:Python AIML錯誤

import aiml 
kernel = aiml.Kernel() 
kernel.learn("bot.aiml") 
while True: 
    print kernel.respond(raw_input("\n>>")) 

只是一個簡單的AIML內核。它有什麼問題嗎?

+0

什麼的'bot.aiml'文件中刪除了「打印」聲明? –

回答

0

我有更好的Python腳本,如果你有興趣

import aiml 
import sys <br> 

brainLoaded = False 
forceReload = False 
while not brainLoaded: 
    if forceReload or (len(sys.argv) >= 2 and sys.argv[1] == "reload"): 

     kern.bootstrap(learnFiles="Database.xml", commands="load aiml b") 
     brainLoaded = True 
     kern.saveBrain("Cache.brn") 
    else: 
     # Attempt to load the brain file. If it fails, fall back on the Reload 
     try: 
      # It is our cache file. 
      kern.bootstrap(brainFile = "Cache.brn") 
      brainLoaded = True 
     except: 
      forceReload = True 

# Enter the main input/output loop. 
print "Enter your message for the chatbot" 
while(True): 
    print kern.respond(raw_input("> ")) 

注意:您需要創建在您將您的AIML文件 一個文件夾,數據庫和文件Database.xml

0

「不匹配找到輸入「警告發生的原因是因爲」bot.aiml「的輸入確實有匹配的輸出。嘗試包括像下面這樣的默認響應:

<category> 
    <pattern>*</pattern> 
    <template> 
     Sorry. I didn't quite get that. 
    </template> 
</category> 
0

嘗試在代碼

import aiml 
kernel = aiml.Kernel() 
kernel.learn("bot.aiml") 
while True: 
    kernel.respond(raw_input("\n>>"))