2014-12-27 25 views
1

我試圖在windows 8.1平臺上加載Pyaiml(python2.7和pyaiml 0.8.6)中的AIML文件。在pyaiml中加載AIML文件時出錯

這裏是我的代碼:

__author__ = 'MASOUD AMR' 
import aiml 
import xml 
mybot = aiml.Kernel() 
mybot.learn('D:\\Python\\chatbot\\lab.xml') 
mybot.respond("what is your name") 

而且AIML文件我使用(lab.xml)是:

<?xml version="1.0" encoding="utf-8"?> 

<aiml version="1.0.1" xmlns="http://alicebot.org/2001/AIML-1.0.1" 
     xmlns:html="http://www.w3.org/1999/xhtml" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://alicebot.org/2001/AIML-1.0.1 http://aitools.org/aiml/schema/AIML.xsd"> 

<category> 
     <pattern>*</pattern> 
    <template>Hello, I'm glad to see you</template> 
</category> 

<category> 
     <pattern>WHAT IS YOUR NAME</pattern> 
     <template>My name is <bot name="name"></bot></template> 
</category> 

</aiml> 

它不斷出現這個錯誤,我不知道爲什麼。 錯誤:

Connected to pydev debugger (build 139.487) 
Loading D:\Python\chatbot\lab.xml... 
FATAL PARSE ERROR in file D:\Python\chatbot\lab.xml: 
D:\Python\chatbot\lab.xml:2:0: XML or text declaration not at start of entity 
WARNING: No match found for input: what is your name 
+1

你可以看看這個[http://stackoverflow.com/questions/15351472/pyaiml-not-loading-startup? RQ = 1]。 –

回答

0

我在我的代碼中發現了一個錯誤。 我的XML代碼聲明沒有從文檔的開頭(第一行)開始。 只有在文檔開始時才允許XML聲明。

正如你可以看到Pycharm IDE甚至顯示錯誤:

enter image description here