def sentiment_comparison(statement, other_statement):
 from nltk.sentiment.vader import SentimentIntensityAnalyzer
 sentiment_analyzer = SentimentIntensityAnalyzer()
 statement_polarity = sentiment_analyzer.polarity_scores(statement.text.lower())
 statement2_polarity = sentiment_analyzer.polarity_scores(other_statement.text.lower())
 statement_greatest_polarity = 'neu'
 statement_greatest_score = (-1)
 for polarity in sorted(statement_polarity):
  if (statement_polarity[polarity] > statement_greatest_score):
   statement_greatest_polarity = polarity
   statement_greatest_score = statement_polarity[polarity]
 statement2_greatest_polarity = 'neu'
 statement2_greatest_score = (-1)
 for polarity in sorted(statement2_polarity):
  if (statement2_polarity[polarity] > statement2_greatest_score):
   statement2_greatest_polarity = polarity
   statement2_greatest_score = statement2_polarity[polarity]
 if (statement_greatest_polarity != statement2_greatest_polarity):
  return 0
 values = [statement_greatest_score, statement2_greatest_score]
 difference = (max(values) - min(values))
 return (1.0 - difference)

def sentiment_comparison ( statement , other_statement ) : from nltk . sentiment . vader import SentimentIntensityAnalyzer sentiment_analyzer = SentimentIntensityAnalyzer ( ) statement_polarity = sentiment_analyzer . polarity_scores ( statement . text . lower ( ) ) statement2_polarity = sentiment_analyzer . polarity_scores ( other_statement . text . lower ( ) ) statement_greatest_polarity = 'neu' statement_greatest_score = ( - 1 ) for polarity in sorted ( statement_polarity ) : if ( statement_polarity [ polarity ] > statement_greatest_score ) : statement_greatest_polarity = polarity statement_greatest_score = statement_polarity [ polarity ] statement2_greatest_polarity = 'neu' statement2_greatest_score = ( - 1 ) for polarity in sorted ( statement2_polarity ) : if ( statement2_polarity [ polarity ] > statement2_greatest_score ) : statement2_greatest_polarity = polarity statement2_greatest_score = statement2_polarity [ polarity ] if ( statement_greatest_polarity != statement2_greatest_polarity ) : return 0 values = [ statement_greatest_score , statement2_greatest_score ] difference = ( max ( values ) - min ( values ) ) return ( 1.0 - difference )
calculate the similarity of two statements based on the closeness of the sentiment value calculated for each statement .