<s> """<STR_LIT>""" <EOL> from operator import itemgetter <EOL> from heapq import nlargest <EOL> from lxml . html import parse , HTMLParser <EOL> from statscounter import StatsCounter <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> SELECT_PARENTS = '<STR_LIT>' <EOL> TOP_FIVE = <NUM_LIT:5> <EOL> def parse_html ( fileobj , encoding ) : <EOL> """<STR_LIT>""" <EOL> parser = HTMLParser ( encoding = encoding , remove_blank_text = True ) <EOL> return parse ( fileobj , parser ) <EOL> def pipeline ( data , funcs ) : <EOL> """<STR_LIT>""" <EOL> for func in funcs : <EOL> data = func ( data ) <EOL> return data <EOL> def select ( etree , query = SELECT_PARENTS ) : <EOL> return etree . xpath ( query ) <EOL> def measure ( nodes ) : <EOL> return [ ( node , StatsCounter ( [ child . tag for child in node ] ) ) <EOL> for node in nodes ] <EOL> def rank ( pairs , key = lambda x : x [ <NUM_LIT:1> ] . most_common ( <NUM_LIT:1> ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <EOL> count = TOP_FIVE ) : <EOL> return nlargest ( count , pairs , key = key ) <EOL> def finalise ( ranked ) : <EOL> for node , metric in ranked : <EOL> yield node </s>
