diff options
author | jadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-06-06 15:54:34 +0000 |
---|---|---|
committer | jadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-06-06 15:54:34 +0000 |
commit | 205a7638155ba94f94a89813cfd4b05c96f0760b (patch) | |
tree | dbed7b52ba8ae5e70f7d881373a371e08b34303b /tko/reason_qualifier.py | |
parent | 8d83a10e6d18be4496e3b2106452dd63d10076bd (diff) |
Add a file that was missed from a previous patch.
git-svn-id: svn://test.kernel.org/autotest/trunk@1640 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'tko/reason_qualifier.py')
-rwxr-xr-x | tko/reason_qualifier.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tko/reason_qualifier.py b/tko/reason_qualifier.py new file mode 100755 index 00000000..29e50d75 --- /dev/null +++ b/tko/reason_qualifier.py @@ -0,0 +1,64 @@ +import re,string + + +class reason_counter: + def __init__(self, wording): + self.wording = wording + self.num = 1 + + def update(self, new_wording): + self.num += 1 + self.wording = new_wording + + def html(self): + if self.num == 1: + return self.wording + else: + return "%s (%d+)" % (self.wording, self.num) + + +def numbers_are_irrelevant(txt): + ## ? when do we replace numbers with NN ? + ## By default is always, but + ## if/when some categories of reasons choose to keep their numbers, + ## then the function shall return False for such categories + return True + + +def aggregate_reason_fields(reasons_list): + # each reason in the list may be a combination + # of | - separated reasons. + # expand into list + reasons_txt = '|'.join(reasons_list) + reasons = reasons_txt.split('|') + reason_htable = {} + for reason in reasons: + reason_reduced = reason.strip() + ## reduce whitespaces + reason_reduced = re.sub(r"\s+"," ", reason_reduced) + + if reason_reduced == '': + continue # ignore empty reasons + + if numbers_are_irrelevant(reason_reduced): + # reduce numbers included into reason descriptor + # by replacing them with generic NN + reason_reduced = re.sub(r"\d+","NN", reason_reduced) + + if not reason_reduced in reason_htable: + reason_htable[reason_reduced] = reason_counter(reason) + else: + ## reason_counter keeps original ( non reduced ) + ## reason if it occured once + ## if reason occured more then once, reason_counter + ## will keep it in reduced/generalized form + reason_htable[reason_reduced].update(reason_reduced) + + generic_reasons = reason_htable.keys() + generic_reasons.sort(key = (lambda k: reason_htable[k].num), + reverse = True) + return map(lambda generic_reason: reason_htable[generic_reason].html(), + generic_reasons) + + + |