From 2c7d39169de0db6ca2f22318c97e783a1bac5b71 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 30 Aug 2012 22:50:43 -0400 Subject: [PATCH] Implement auto-assessment. --- earwigbot/tasks/wikiproject_tagger.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/earwigbot/tasks/wikiproject_tagger.py b/earwigbot/tasks/wikiproject_tagger.py index 5fbb15f..099306b 100644 --- a/earwigbot/tasks/wikiproject_tagger.py +++ b/earwigbot/tasks/wikiproject_tagger.py @@ -255,9 +255,23 @@ class WikiProjectTagger(Task): """Return banner text to add based on a *job* and a page's *code*.""" banner = "{{" + job.banner if job.autoassess: - assessment = self.assess(code) # TODO - if assessment: - banner += "|class=" + assessment + classes = {"fa": 0, "fl": 0, "ga": 0, "a": 0, "b": 0, "start": 0, + "stub": 0, "list": 0, "dab": 0, "c": 0, "redirect": 0, + "book": 0, "template": 0, "category": 0} + for template in code.ifilter_templates(recursive=True): + if template.has_param("class"): + value = str(template.get("class").value).lower() + if value in classes: + classes[value] += 1 + values = tuple(classes.values()) + best = max(values) + confidence = float(best) / sum(values) + if confidence > 0.75: + rank = tuple(classes.keys())[values.index(best)] + if rank in ("fa", "fl", "ga"): + banner += "|class=" + rank.upper() + else: + banner += "|class=" + self._upperfirst(rank) return banner + job.append + "}}" def get_banner_shell(self, code): @@ -271,6 +285,7 @@ class WikiProjectTagger(Task): def add_banner(self, code, banner): """Add *banner* to *code*, following template order conventions.""" + ins_index = 0 if has_top_temps: # TODO xxx else: