def learn(self, filename): """Load and learn the contents of the specified AIML file. If filename includes wildcard characters, all matching files will be loaded and learned. """ for f in glob.glob(filename): if self._verboseMode: print "Loading %s..." % f, start = time.clock() # Load and parse the AIML file. parser = AimlParser.create_parser() handler = parser.getContentHandler() handler.setEncoding(self._textEncoding) try: parser.parse(f) except xml.sax.SAXParseException, msg: err = "\nFATAL PARSE ERROR in file %s:\n%s\n" % (f, msg) sys.stderr.write(err) continue # store the pattern/template pairs in the PatternMgr. for key, tem in handler.categories.items(): self._brain.add(key, tem) # Parsing was successful. if self._verboseMode: print "done (%.2f seconds)" % (time.clock() - start)
def learn(self, filename): """Load and learn the contents of the specified AIML file. If filename includes wildcard characters, all matching files will be loaded and learned. """ # learn something given by test # (u'HOW ARE YOU', u'*', u'*') ['template', {}, ['text', {'xml:space': 'default'}, u'\nFINE THANK YOU!\n']] # self._brain.add((u'HOW ARE YOU', u'*', u'*'), ['template', {}, ['text', {'xml:space': 'default'}, u'\nFINE THANK YOU!\n']]) for f in glob.glob(filename): if self._verboseMode: print "Loading %s..." % f, start = time.clock() # Load and parse the AIML file. parser = AimlParser.create_parser() handler = parser.getContentHandler() handler.setEncoding(self._textEncoding) try: parser.parse(f) except xml.sax.SAXParseException, msg: err = "\nFATAL PARSE ERROR in file %s:\n%s\n" % (f, msg) sys.stderr.write(err) continue # store the pattern/template pairs in the PatternMgr. for key, tem in handler.categories.items(): self._brain.add(key, tem) # print 'key & tem',key,' ',tem # Parsing was successful. if self._verboseMode: print "done (%.2f seconds)" % (time.clock() - start)
def learn(self, filename): """Load and learn the contents of the specified AIML file. If filename includes wildcard characters, all matching files will be loaded and learned. """ for f in glob.glob(filename): if self._verboseMode: print "Loading %s..." % f, start = time.clock() # Load and parse the AIML file. parser = AimlParser.create_parser() handler = parser.getContentHandler() handler.setEncoding(self._textEncoding) try: parser.parse(f) except xml.sax.SAXParseException, msg: err = "\nFATAL PARSE ERROR in file %s:\n%s\n" % (f,msg) sys.stderr.write(err) continue # store the pattern/template pairs in the PatternMgr. for key,tem in handler.categories.items(): self._brain.add(key,tem) # Parsing was successful. if self._verboseMode: print "done (%.2f seconds)" % (time.clock() - start)
def learnfp(self, filep): parser = AimlParser.create_parser() handler = parser.getContentHandler() handler.setEncoding(self._textEncoding) parser.parse(filep) # store the pattern/template pairs in the PatternMgr. for key,tem in handler.categories.items(): self._brain.add(key,tem)