summaryrefslogtreecommitdiff
path: root/tko/reason_qualifier.py
diff options
context:
space:
mode:
authorjadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4>2008-06-06 21:10:57 +0000
committerjadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4>2008-06-06 21:10:57 +0000
commit45510bde8d4a2c6d08b2331f723ec5d37b6cdbe2 (patch)
tree4e2892a8aa650003f797983621cfd86290ead6af /tko/reason_qualifier.py
parente7e5318f8309211f07a3683fb168d21718f701a7 (diff)
Convert all python code to use four-space indents instead of eight-space tabs.
Signed-off-by: John Admanski <jadmanski@google.com> git-svn-id: svn://test.kernel.org/autotest/trunk@1658 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'tko/reason_qualifier.py')
-rwxr-xr-xtko/reason_qualifier.py103
1 files changed, 50 insertions, 53 deletions
diff --git a/tko/reason_qualifier.py b/tko/reason_qualifier.py
index 29e50d75..6347a4f4 100755
--- a/tko/reason_qualifier.py
+++ b/tko/reason_qualifier.py
@@ -2,63 +2,60 @@ 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 __init__(self, wording):
+ self.wording = wording
+ self.num = 1
- def html(self):
- if self.num == 1:
- return self.wording
- else:
- return "%s (%d+)" % (self.wording, self.num)
+ 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
+ ## ? 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)
-
-
-
+ # 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)