def label_from_string(text): text = text.strip() prio = persist.get_classifier('prio').classify(ngen(text)) text = ' ' + text + ' ' out, text, date = parse_date(text) ttype = { Task.PRIORITY_HIGH: 'Important task due', Task.PRIORITY_MEDIUM: 'Assignment due', Task.PRIORITY_LOW: 'Task for', Task.PRIORITY_ADMIN: 'Appointment on', }[prio] return (" %s %s" % (ttype, out)), text.strip(), date, prio
def prio_changed(self, renderer, path, iter): if self.concurrent_modification: return miter = self.model.iter_nth_child(None, int(path)) task = self.model.get_value(miter, 0) task.prio = task.prio_match(self.prio_store.get_value(iter, 0)) self.remove(miter) self.add(task) self.persist.sync() mc = persist.get_classifier('prio') mc.update(task.prio, ngen(task.text), task.text) mc.save()
def report(self): print "num labels", len(self.weights) print "dimensions", map(len, self.weights.values()) if __name__ == '__main__': classifier = MiraClassifier() total, ok = 0.0, 0.0 while True: print print "Enter a training line:", try: line = raw_input() except EOFError: break ngrams = ngen(line) label = classifier.classify(ngrams) print "---> the right label [guessed %s]:" % label, line = raw_input() if line: classifier.update(line, ngrams) else: ok += 1 total += 1 classifier.report() print "cumulative accuracy:", ok/total for k, weights in classifier.weights.items(): if k is None: continue print print k, '-', '.'.join(map(