<s> import sys <EOL> from pattern . en import wordnet , parse , tag <EOL> def hypernym_search ( text , search_word ) : <EOL> output = [ ] <EOL> synset = wordnet . synsets ( search_word ) [ <NUM_LIT:0> ] <EOL> pos = synset . pos <EOL> possible_words = re_search ( text , pos ) <EOL> for match in possible_words : <EOL> word = match [ <NUM_LIT:0> ] . string <EOL> synsets = wordnet . synsets ( word ) <EOL> if len ( synsets ) > <NUM_LIT:0> : <EOL> hypernyms = synsets [ <NUM_LIT:0> ] . hypernyms ( recursive = True ) <EOL> if any ( search_word == h . senses [ <NUM_LIT:0> ] for h in hypernyms ) : <EOL> output . append ( word ) <EOL> return set ( output ) <EOL> text = sys . stdin . read ( ) <EOL> hypernyms = { } <EOL> for word , pos in tag ( text ) : <EOL> synsets = wordnet . synsets ( word ) <EOL> if len ( synsets ) > <NUM_LIT:0> : <EOL> try : <EOL> hypernym = synsets [ <NUM_LIT:0> ] . hypernyms ( ) [ <NUM_LIT:0> ] . senses [ <NUM_LIT:0> ] <EOL> if hypernym in hypernyms : <EOL> hypernyms [ hypernym ] += <NUM_LIT:1> <EOL> else : <EOL> hypernyms [ hypernym ] = <NUM_LIT:1> <EOL> except : <EOL> next <EOL> for hypernym in sorted ( hypernyms , key = hypernyms . get , reverse = True ) : <EOL> count = hypernyms [ hypernym ] <EOL> print hypernym + "<STR_LIT>" + str ( count ) </s>
