Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

python - I am not getting where exactly the error is there in my code

I ran a simple code involving a .xml extension file and python file. I got the error as shown. i didn't get the main reason behind it and cant figure out how to rectify it. error shown is:

Loading brain from startup.xml...Error restoring PatternMgr from file startup.xml:
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    kernel.bootstrap(brainFile="startup.xml")
  File "C:UsersadithAppDataLocalProgramsPythonPython37libsite-packagesaimlKernel.py", line 134, in bootstrap 
    self.loadBrain(brainFile)
  File "C:UsersadithAppDataLocalProgramsPythonPython37libsite-packagesaimlKernel.py", line 194, in loadBrain 
    self._brain.restore(filename)
  File "C:UsersadithAppDataLocalProgramsPythonPython37libsite-packagesaimlPatternMgr.py", line 67, in restore
    self._templateCount = marshal.load(inFile)
ValueError: bad marshal data (unknown type code)

File a.xml:

<aiml version="1.0.1" encoding="UTF=8">
    <category>
        <patern>HELLO THERE</pattern>
        <template>
            i am hitler!!!!!!!
        </template>
    <category>
</aiml>

File b.xml:

<aiml version="1.0.1" encoding="UTF=8">
    <category>
        <patterrn> I am *</pattern>
        <template>
            thats interesting that your dog name is<set name="dog"><star/></set>
        </template>
    </category>
    <category>
        <pattern> WHAT IS MY DOGS NAME </pattern>
        <template> 
            your name is : <get name="dog"/>
        </template>
    </category>
</aiml>

File c.xml:

<aiml version="1.0.1" encoding="UTF=8">
    <category>
        <pattern>LETS DISCUSS MOVIES</pattern>
        <template>yes<set name="topic">movies</set></template>
    </category>
    <category>
        <pattern>LETS DISCUSS GAMES</pattern>
        <template>yes<set name="topic">games</set></template>
    </category>
    <topic name ="MOVIES">
        <category> 
            <pattern>SUGGEST</pattern>
            <template> Batman</template>
        </category>
    </topic>
    <topic name ="GAMES">
        <category> 
            <pattern>SUGGEST</pattern>
            <template> Pacman</template>
        </category>
    </topic>
</aiml>

File startup.aiml:

<aiml version="1.0.1" encoding="UTF=8">
    <!--std-startup.xml -->
    <!-- Category is an atomic AIML unit -->
    <category>
        <pattern> LOAD *</pattern>
        <template>
            <learn> <star>.xml</learn>
        </template>
    <category>
</aiml>

File test.py:

import aiml
import os
kernel=aiml.Kernel()
if os.path.isfile("bot_brain.brm"):
    kernel.bootstrap(brainFile="bot_brain.brn")
else:
    kernel.bootstrap(brainFile="startup.xml")
I=input(">>>>>")
while I!="exit()":
    print(kernel.respond(I))
    I=input(">>>>>")
kernel.saveBrain("bot_brain.brn")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...