def process_movie_reviews(service, reader, sentiment_writer, entity_writer):
 collected_entities = {}
 for document in reader:
  try:
   (sentiment_total, entities) = get_sentiment_entities(service, document)
  except HttpError as e:
   logging.error('Error process_movie_reviews {}'.format(e.content))
   continue
  document.label = get_sentiment_label(sentiment_total)
  sentiment_writer.write(to_sentiment_json(document.doc_id, sentiment_total, document.label))
  sentiment_writer.write('\n')
  for ent in entities:
   (ent_sent, frequency) = collected_entities.get(ent, (0, 0))
   ent_sent += sentiment_total
   frequency += 1
   collected_entities[ent] = (ent_sent, frequency)
 for (entity, sentiment_frequency) in collected_entities.items():
  entity_writer.write(to_entity_json(entity, sentiment_frequency[0], sentiment_frequency[1]))
  entity_writer.write('\n')
 sentiment_writer.flush()
 entity_writer.flush()

def process_movie_reviews ( service , reader , sentiment_writer , entity_writer ) : collected_entities = { } for document in reader : try : ( sentiment_total , entities ) = get_sentiment_entities ( service , document ) except HttpError as e : logging . error ( 'Error process_movie_reviews {}' . format ( e . content ) ) continue document . label = get_sentiment_label ( sentiment_total ) sentiment_writer . write ( to_sentiment_json ( document . doc_id , sentiment_total , document . label ) ) sentiment_writer . write ( '\n' ) for ent in entities : ( ent_sent , frequency ) = collected_entities . get ( ent , ( 0 , 0 ) ) ent_sent += sentiment_total frequency += 1 collected_entities [ ent ] = ( ent_sent , frequency ) for ( entity , sentiment_frequency ) in collected_entities . items ( ) : entity_writer . write ( to_entity_json ( entity , sentiment_frequency [ 0 ] , sentiment_frequency [ 1 ] ) ) entity_writer . write ( '\n' ) sentiment_writer . flush ( ) entity_writer . flush ( )
perform some sentiment math and come up with movie review .