2016-08-16 2 views
0

스크립트를 실행할 때 AIML을 사용하는 Python 프로젝트를 시작합니다. '일치하지 않습니다.'오류가 발생합니다.Python AIML 오류

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

그냥 간단한 AIML 커널 : 이것은 파이썬 코드입니다. 그게 뭔가 잘못 됐니? 당신이

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("> ")) 

주 관심이 있다면

+0

에서 '인쇄'문을 제거하십시오 : 다음과 같은 기본 응답을 포함하려고? –

답변

0

내가 더 나은 파이썬 스크립트가 : 당신은 당신이 당신의 AIML 파일 을 배치 폴더 데이터베이스 및 파일 Database.xml

0

을 만들 필요 "일치하는 항목이 없습니다 입력에 대해 발견 됨 "경고가 발생합니다. 왜냐하면"bot.aiml "에 입력에 대해 일치하는 출력이 있기 때문입니다.

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

는`bot.aiml` 파일의 내용 코드

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