def main(args): try: opts, args = getopt.getopt(args, "hd:p:", ["help", "database=", "pickle="]) except getopt.GetoptError as msg: usage(msg) return 1 if len(args) != 1: usage() return 1 cdbname = args[0] dbname = usedb = None for opt, arg in opts: if opt in ("-h", "--help"): usage() return 0 dbname, usedb = storage.database_type(opts) store = storage.open_storage(dbname, usedb) bayes = CdbClassifier() items = [] for word in store._wordinfokeys(): record = store._wordinfoget(word) prob = store.probability(record) items.append((word, str(prob))) cdbfile = open(cdbname, "wb") cdb.cdb_make(cdbfile, items) cdbfile.close()
def store(self): items = [(self.statekey, "%d,%d" % (self.nham, self.nspam))] for word, wi in self.wordinfo.items(): if isinstance(word, str): word = word.encode("utf-8") items.append((word, "%d,%d" % (wi.hamcount, wi.spamcount))) db = open(self.db_name, "wb") cdb.cdb_make(db, items) db.close()
def save_wordinfo(self, db_file): items = [] for word, record in self.wordinfo.items(): prob = Classifier.probability(self, record) items.append((word, str(prob))) cdb.cdb_make(db_file, items)
store = storage.open_storage(dbname, usedb) bayes = CdbClassifier() items = [] for word in store._wordinfokeys(): record = store._wordinfoget(word) prob = store.probability(record) items.append((word, str(prob))) cdbfile = open(cdbname, "wb") cdb.cdb_make(cdbfile, items) cdbfile.close() if __name__ == "__main__": sys.exit(main(sys.argv[1:])) if __name__ == "__main__": sys.exit(main(sys.argv[1:]))
def save_wordinfo(self, db_file): items = [] for word, record in self.wordinfo.iteritems(): prob = Classifier.probability(self, record) items.append((word, str(prob))) cdb.cdb_make(db_file, items)
usage(msg) return 1 if len(args) != 1: usage() return 1 cdbname = args[0] dbname = usedb = None for opt, arg in opts: if opt in ("-h", "--help"): usage() return 0 dbname, usedb = storage.database_type(opts) store = storage.open_storage(dbname, usedb) bayes = CdbClassifier() items = [] for word in store._wordinfokeys(): record = store._wordinfoget(word) prob = store.probability(record) items.append((word, str(prob))) cdbfile = open(cdbname, "wb") cdb.cdb_make(cdbfile, items) cdbfile.close() if __name__ == "__main__": sys.exit(main(sys.argv[1:]))