コード例 #1
0
ファイル: pretzel.py プロジェクト: iskander/meaningcmp
 def __init__(self):
     self.pretzel_keys = []
     self.prompt = '> '
     self.completekey = None
     self.cmdqueue = []
     self.stop = False
     self.stdout = stdout
     self.minsim = 0.34
     print "Loading data... ",
     stdout.flush()
     try:
         if len(argv)==2:
             self.datafile = argv[1]
         else:
             self.datafile = "pretzel.dat"
         f = open(self.datafile)
         str = f.readline()
         while str and len(str) is not 0:
             if str[-1]=='\n':
                 str = str[:-1]
             self.pretzel_keys.append([str[:str.find(':')],str[str.find(':')+1:]])
             str = f.readline()
         print "[done]"
     except:
         self.pretzel_keys.append(['hello','hi'])
         self.pretzel_keys.append(['how are you','fine, thanks'])
         self.pretzel_keys.append(['exit','exit'])
         self.pretzel_keys.append(['quit','quit'])
         print "[failed] (new database will be created in pretzel.dat after a clean exit (type exit to do that))"
     print "Initializing mncmp()... ",
     stdout.flush()
     mncmp("doors","walls") # need to pass anything through it once so that the wordnet dictionnaries get loaded etc.
     print "[done]"
コード例 #2
0
ファイル: pretzel.py プロジェクト: iskander/meaningcmp
    def default(self, user):
        success = False
        for item in self.pretzel_keys:
            args = mncmp(user,item[0],self.minsim)
            itemtmp = item[1]
            if args is not False:
                if args is not True:
                    # means we have some arguments
                    for x in range(0,len(args)):
                        try:
                            itemtmp = itemtmp.replace('arg'+repr(x+1),args[x])
                        except:
                            pass
                success = True
                self.execute(itemtmp)
                break
        if not success:
            cmd = self.panic()
            if cmd!="":
                self.pretzel_keys.append([user,cmd])
            else:
                print "Received empty input; not adding to database."

        self.flushdb()