def rank_entities(reader, sentiment=None, topn=None, reverse_bool=False):
 items = []
 for item in reader:
  json_item = json.loads(item)
  sent = json_item.get('sentiment')
  entity_item = (sent, json_item)
  if sentiment:
   if ((sentiment == 'pos') and (sent > 0)):
    items.append(entity_item)
   elif ((sentiment == 'neg') and (sent < 0)):
    items.append(entity_item)
  else:
   items.append(entity_item)
 items.sort(reverse=reverse_bool)
 items = [json.dumps(item[1]) for item in items]
 print '\n'.join(items[:topn])

def rank_entities ( reader , sentiment = None , topn = None , reverse_bool = False ) : items = [ ] for item in reader : json_item = json . loads ( item ) sent = json_item . get ( 'sentiment' ) entity_item = ( sent , json_item ) if sentiment : if ( ( sentiment == 'pos' ) and ( sent > 0 ) ) : items . append ( entity_item ) elif ( ( sentiment == 'neg' ) and ( sent < 0 ) ) : items . append ( entity_item ) else : items . append ( entity_item ) items . sort ( reverse = reverse_bool ) items = [ json . dumps ( item [ 1 ] ) for item in items ] print '\n' . join ( items [ : topn ] )
rank the entities based on their sentiment assigned from the movie .